Fixed fading, and fixed files to stop when they've reached the end
parent
c3a4189ef4
commit
7128273201
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue