MichaelBenjamin ·
here is an optimized and bug fixed asm version of oddsons and infuzions 1.7 adsr from the sm wiki. cpu reduction to the code version is ~50% fixes: first is more of a workaround, since the sm env module seems to have a bug, it sometimes outputs values higher than 4 for a short time after release stage resulting in a nasty click. therefore the holdstage variable is minpsd by 4. second is that releasehop is no longer multiplied with S, since that made the enelope act wierd and hang on S with certain (especially small S)values. i also removed the stage(0) part since it would not have worked with stream data. if you only use green data you can stage(0) everything including minps xmm7,F4; after that stage1 begins. this envelope behaves like the adsr4 envelope, but restarts at the attack stage on a retrigger of the same note. to use different hops you need to change the variables cntr and incr according. step=1/hop. feed the streamboolout to a env module and the output from the env module into the holdstage input.
streamin A; streamin D; streamin S; streamin R; streamin holdStage; streamout out; streamboolout releaseOff; float stg=0; float hopA=0; float cntr=-16; float incr=16; float step=0.0625; float F1=1; float FM1=-1; float F4=4; float F0=0; float F2=2; float F3=3; mov eax,ecx; and eax,15; cmp eax,0; jnz end0;
movaps xmm0,A; movaps xmm1,xmm0; movaps hopA,xmm1; movaps xmm3,FM1; movaps xmm5,xmm3; movaps xmm4,D; movaps xmm6,R; movaps xmm7,holdStage;
mulps xmm0,step; rcpps xmm0,xmm0; addps xmm1,D; addps xmm3,S; mulps xmm4,step; rcpps xmm4,xmm4; mulps xmm3,xmm4; mulps xmm6,step; rcpps xmm6,xmm6; mulps xmm5,xmm6; minps xmm7,F4;
movaps xmm6,xmm7; movaps xmm4,cntr;
cmpps xmm7,F1,6; //extstage addps xmm4,incr; andps xmm7,xmm4;
movaps cntr,xmm7; movaps xmm4,xmm7;//backup cntr for comp
cmpps xmm7,hopA,5; andps xmm7,F1; cmpps xmm4,xmm1,5;//hopad in xmm1 andps xmm4,F1; addps xmm4,xmm7; cmpps xmm6,F4,0; andps xmm6,F4; addps xmm4,xmm6; movaps stg,xmm4; movaps xmm6,xmm4;//backup stg movaps xmm1,xmm4;//backup for next block movaps xmm2,xmm4;
//0,3,4,5, reserved movaps xmm7,cntr; cmpps xmm7,F0,6; andps xmm7,out; cmpps xmm4,F0,0; andps xmm4,xmm0; addps xmm4,xmm7; cmpps xmm6,F1,0; andps xmm6,xmm3; addps xmm4,xmm6;//out in xmm4
movaps xmm3,xmm1;//backup stage //4,5 reserved cmpps xmm1,F2,1; cmpps xmm2,F2,0; cmpps xmm3,F3,6; andps xmm1,xmm4; andps xmm2,S; addps xmm4,xmm5; andps xmm3,xmm4; addps xmm1,xmm2; addps xmm1,xmm3; minps xmm1,F1; maxps xmm1,F0; movaps out,xmm1;
movaps xmm0,stg; cmpps xmm0,F3,6; cmpps xmm1,F0,2; andps xmm0,xmm1; movaps releaseOff,xmm0; end0: