From 7128273201d8df7c2e8a71171125032ccd1ae74c Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Tue, 15 Oct 2013 12:58:45 -0700 Subject: [PATCH] Fixed fading, and fixed files to stop when they've reached the end --- Plugins/MIDI/MIDI/MIDIDecoder.mm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Plugins/MIDI/MIDI/MIDIDecoder.mm b/Plugins/MIDI/MIDI/MIDIDecoder.mm index 167dd0c37..45a7e3e42 100755 --- a/Plugins/MIDI/MIDI/MIDIDecoder.mm +++ b/Plugins/MIDI/MIDI/MIDIDecoder.mm @@ -103,6 +103,9 @@ - (int)readAudio:(void *)buf frames:(UInt32)frames { + if ( framesRead >= totalFrames ) + return 0; + if ( !soundFontsAssigned ) { NSString * soundFontPath = [[NSUserDefaults standardUserDefaults] stringForKey:@"soundFontPath"]; if (soundFontPath == nil) @@ -123,7 +126,7 @@ float * buff = ( float * ) buf; - float fadeScale = (fadeStart - framesLength) / framesFade; + float fadeScale = (float)(framesFade - (fadeStart - framesLength)) / framesFade; float fadeStep = 1 / framesFade; for (fadePos = fadeStart; fadePos < fadeEnd; ++fadePos) { buff[ 0 ] *= fadeScale; @@ -134,7 +137,7 @@ } if (fadePos < totalFrames) - frames = (int)(fadePos - fadeStart); + frames = (int)(fadePos - framesRead); } else { frames = (int)(totalFrames - framesRead);