Fixed fading, and fixed files to stop when they've reached the end

CQTexperiment
Chris Moeller 2013-10-15 12:58:45 -07:00
parent c3a4189ef4
commit 7128273201
1 changed files with 5 additions and 2 deletions

View File

@ -103,6 +103,9 @@
- (int)readAudio:(void *)buf frames:(UInt32)frames - (int)readAudio:(void *)buf frames:(UInt32)frames
{ {
if ( framesRead >= totalFrames )
return 0;
if ( !soundFontsAssigned ) { if ( !soundFontsAssigned ) {
NSString * soundFontPath = [[NSUserDefaults standardUserDefaults] stringForKey:@"soundFontPath"]; NSString * soundFontPath = [[NSUserDefaults standardUserDefaults] stringForKey:@"soundFontPath"];
if (soundFontPath == nil) if (soundFontPath == nil)
@ -123,7 +126,7 @@
float * buff = ( float * ) buf; float * buff = ( float * ) buf;
float fadeScale = (fadeStart - framesLength) / framesFade; float fadeScale = (float)(framesFade - (fadeStart - framesLength)) / framesFade;
float fadeStep = 1 / framesFade; float fadeStep = 1 / framesFade;
for (fadePos = fadeStart; fadePos < fadeEnd; ++fadePos) { for (fadePos = fadeStart; fadePos < fadeEnd; ++fadePos) {
buff[ 0 ] *= fadeScale; buff[ 0 ] *= fadeScale;
@ -134,7 +137,7 @@
} }
if (fadePos < totalFrames) if (fadePos < totalFrames)
frames = (int)(fadePos - fadeStart); frames = (int)(fadePos - framesRead);
} }
else { else {
frames = (int)(totalFrames - framesRead); frames = (int)(totalFrames - framesRead);