<commit_before>
;@ ins k k k
;@ outs k k
opcode EnvADSR, 0, kkkkkkkkkkkkk
	kShape,kA,kD,kS,kR,kType,kKB,kReset,  kin,kGatei,kAMi,kEnvO,kout xin

	k1[] fillarray 1,-1, 1,-1, 2,-2
	k2[] fillarray 0, 1,-1, 0,-1, 1

	aIn zar kin
	kGate zkr kGatei

	kEnv init 0
	kEnv0 init 0
	kEnv1 init 0
	kstate init 0
	kShapeLst init 0
	kTime0 init 0
	kTime init 0
	kAM init 64

	kA /= 1000
	kD /= 1000
	kS /= 64
	kR /= 1000

	if kAMi < 2 goto NoAM
		kAM zkr kAMi
NoAM:
	if kKB!= 1 goto NoKB
		kGate += gkGate
		kGate limit kGate, -1, 1
NoKB:
	if kShape == kShapeLst goto Next
		kTime0 = kTime
		kEnv0 = kEnv
  		kShapeLst = kShape
Next:
	if kGate == 0 goto Free
		if kstate = 4 then
			if kReset == 0 goto NoRes
				kEnv = 0
				kTime = 0
				kEnv0 = 0
				kTime0 = 0
				kgoto OutRes
NoRes:
			kTime0 = 0
			kEnv0 = kEnv
			kTime = 0
		endif
OutRes:
		if kstate == 2 goto Decay
		if kstate == 3 goto ESustain

		kstate = 1 ;Attack

		if kShape == 0 then
			kEnv = kEnv0 + (1.013-kEnv0)*(1 - exp(-4*(kTime-kTime0)/(kA*kr)))
		elseif kShape == 2 then
			kEnv = kEnv0 +(1-kEnv0)*(exp((kTime-kTime0)/(kA*kr - kTime0)*1.791759)-1)/5
		else
			kEnv += 1/(kr*kA)
		endif
		kTime += 1
		kEnv limit kEnv, 0, 1

	if kEnv < 1 goto EnvOut
		kstate = 2; Decay
		kTime = 0
		kEnv0 = 1
		kTime0 = 0
Decay:
		if kShape < 3 then
			kEnv = 0.9993*kS + (kEnv0 - 0.9993*kS)*(exp(-8*(kTime-kTime0)/(kD*kr)))
		else
			kEnv -= (kEnv0 - kS)/(kr*kD-kTime0)
		endif
		kTime += 1
	if (kEnv > kS) goto EnvOut
		kstate = 3 ; Sustain
ESustain:
		kEnv = kS
		kgoto EnvOut

Free:
	if kstate == 0 goto EnvOut

	if kstate == 4 goto Release
		kstate = 4
		kEnv0 = kEnv
		kTime0 = 0
		kTime = 0

Release:
	if kShape < 3 then
			kEnv = kEnv0*(exp(-8*(kTime-kTime0)/(kR*kr)))
		else
			kEnv -= kEnv0/(kr*kR-kTime0)
	endif
		kTime += 1

	kEnv limit kEnv, 0, 1
	if kEnv != 0 goto EnvOut
		kstate = 0
		kTime = 0
		kEnv0 = 0
		kTime0 = 0
EnvOut:

	kEnv *= kAM/64
	kEnv1 = kEnv*k1[kType]+k2[kType]
	zkw kEnv1, kEnvO
	zaw kEnv1*aIn, kout
		;out a(kEnv1)*0.97 ;TEST
endop

;@ ins a k k
;@ outs k a

opcode EnvADSR, 0, kkkkkkkkkkkkk
	kShape,kA,kD,kS,kR,kType,kKB,kReset,  kin,kGatei,kAMi,kEnvO,kout xin

	k1[] fillarray 1,-1, 1,-1, 2,-2
	k2[] fillarray 0, 1,-1, 0,-1, 1

	aIn zar kin
	kGate zkr kGatei

	kEnv init 0
	kEnv0 init 0
	kEnv1 init 0
	kstate init 0
	kShapeLst init 0
	kTime0 init 0
	kTime init 0
	kAM init 64
<commit_msg>ADSR small fix<commit_after>
;@ ins k k k
;@ outs k k
opcode EnvADSR, 0, kkkkkkkkkkkkk
	kShape,kA,kD,kS,kR,kType,kKB,kReset,  kin,kGatei,kAMi,kEnvO,kout xin

	k1[] fillarray 1,-1, 1,-1, 2,-2
	k2[] fillarray 0, 1,-1, 0,-1, 1

	aIn zar kin
	kGate zkr kGatei

	kEnv init 0
	kEnv0 init 0
	kEnv1 init 0
	kstate init 0
	kShapeLst init 0
	kTime0 init 0
	kTime init 0
	kAM init 64

	kA table kA, ENVtim
  kD table kD, ENVtim
	kR table kR, ENVtim
	kS table kS, ENVlev

	kA /= 1000
	kD /= 1000
	kS /= 64
	kR /= 1000

	if kAMi < 2 goto NoAM
		kAM zkr kAMi
NoAM:
	if kKB!= 1 goto NoKB
		kGate += gkGate
		kGate limit kGate, -1, 1
NoKB:
	if kShape == kShapeLst goto Next
		kTime0 = kTime
		kEnv0 = kEnv
  		kShapeLst = kShape
Next:
	if kGate == 0 goto Free
		if kstate = 4 then
			if kReset == 0 goto NoRes
				kEnv = 0
				kTime = 0
				kEnv0 = 0
				kTime0 = 0
				kgoto OutRes
NoRes:
			kTime0 = 0
			kEnv0 = kEnv
			kTime = 0
		endif
OutRes:
		if kstate == 2 goto Decay
		if kstate == 3 goto ESustain

		kstate = 1 ;Attack

		if kShape == 0 then
			kEnv = kEnv0 + (1.013-kEnv0)*(1 - exp(-4*(kTime-kTime0)/(kA*kr)))
		elseif kShape == 2 then
			kEnv = kEnv0 +(1-kEnv0)*(exp((kTime-kTime0)/(kA*kr - kTime0)*1.791759)-1)/5
		else
			kEnv += 1/(kr*kA)
		endif
		kTime += 1
		kEnv limit kEnv, 0, 1

	if kEnv < 1 goto EnvOut
		kstate = 2; Decay
		kTime = 0
		kEnv0 = 1
		kTime0 = 0
Decay:
		if kShape < 3 then
			kEnv = 0.9993*kS + (kEnv0 - 0.9993*kS)*(exp(-8*(kTime-kTime0)/(kD*kr)))
		else
			kEnv -= (kEnv0 - kS)/(kr*kD-kTime0)
		endif
		kTime += 1
	if (kEnv > kS) goto EnvOut
		kstate = 3 ; Sustain
ESustain:
		kEnv = kS
		kgoto EnvOut

Free:
	if kstate == 0 goto EnvOut

	if kstate == 4 goto Release
		kstate = 4
		kEnv0 = kEnv
		kTime0 = 0
		kTime = 0

Release:
	if kShape < 3 then
			kEnv = kEnv0*(exp(-8*(kTime-kTime0)/(kR*kr)))
		else
			kEnv -= kEnv0/(kr*kR-kTime0)
	endif
		kTime += 1

	kEnv limit kEnv, 0, 1
	if kEnv != 0 goto EnvOut
		kstate = 0
		kTime = 0
		kEnv0 = 0
		kTime0 = 0
EnvOut:

	kEnv *= kAM/64
	kEnv1 = kEnv*k1[kType]+k2[kType]
	zkw kEnv1, kEnvO
	zaw kEnv1*aIn, kout
		;out a(kEnv1)*0.97 ;TEST
endop

;@ ins a k k
;@ outs k a

opcode EnvADSR, 0, kkkkkkkkkkkkk
	kShape,kA,kD,kS,kR,kType,kKB,kReset,  kin,kGatei,kAMi,kEnvO,kout xin

	k1[] fillarray 1,-1, 1,-1, 2,-2
	k2[] fillarray 0, 1,-1, 0,-1, 1

	aIn zar kin
	kGate zkr kGatei

	kEnv init 0
	kEnv0 init 0
	kEnv1 init 0
	kstate init 0
	kShapeLst init 0
	kTime0 init 0
	kTime init 0
	kAM init 64

	kA table kA, ENVtim
	kD table kD, ENVtim
	kR table kR, ENVtim
	kS table kS, ENVlev

{'fraction_non_alphanumeric': 0.12006512006512006, 'fraction_numerical': 0.07244607244607244, 'mean_word_length': 2.6569940476190474, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6804260', 'n_tokens_mistral': 2808, 'n_tokens_neox': 2399, 'n_words': 702}