Fixed MIDI fading and stopping at the end

CQTexperiment
Chris Moeller 2013-10-18 18:52:59 -07:00
parent bc9d9458b4
commit 16396ad20a
1 changed files with 7 additions and 5 deletions

View File

@ -127,17 +127,19 @@
float * buff = ( float * ) buf; float * buff = ( float * ) buf;
float fadeScale = (float)(framesFade - (fadeStart - framesLength)) / framesFade; float fadeScale = (float)(framesFade - (fadeStart - framesLength)) / framesFade;
float fadeStep = 1 / framesFade; float fadeStep = 1.0 / (float)framesFade;
for (fadePos = fadeStart; fadePos < fadeEnd; ++fadePos) { for (fadePos = fadeStart; fadePos < fadeEnd; ++fadePos) {
buff[ 0 ] *= fadeScale; buff[ 0 ] *= fadeScale;
buff[ 1 ] *= fadeScale; buff[ 1 ] *= fadeScale;
buff += 2; buff += 2;
fadeScale -= fadeStep; fadeScale -= fadeStep;
if (fadeScale < 0) break; if (fadeScale < 0) {
fadeScale = 0;
fadeStep = 0;
}
} }
if (fadePos < totalFrames) frames = (int)(fadeEnd - framesRead);
frames = (int)(fadePos - framesRead);
} }
else { else {
frames = (int)(totalFrames - framesRead); frames = (int)(totalFrames - framesRead);