I am trying to get a looping sound to stop at a precise moment. However, the audio.fadeOut is allowing the sound to continue on past the “stop” point.
Things to note:
The looping .wav sound I am using is slightly less than 1000 milliseconds so the fade only takes 3ish frames.
The second audio.stop works as intended, stoping the audio at the precise moment.
Any ideas what I am doing wrong?
--soundfx are preloaded in another function but here for clarity --duration = x, is passed through the function call local soundfx = { rockButtonDown = audio.loadSound( "audio/buttonDown\_05.wav" ), rockButtonUp = audio.loadSound( "audio/buttonUp\_05.wav" ), rockSliding = audio.loadSound( "audio/rockSliding\_01.wav" ), } local clipDuration = { audio.getDuration( soundfx.rockButtonDown ), audio.getDuration( soundfx.rockButtonUp ), timeDelay = 0,--.5 timeFadeLength = .2, } timer.performWithDelay( clipDuration.timeDelay \* clipDuration[1], function() audio.play( soundfx.rockSliding, { channel = 3, loops = -1, fadein = clipDuration.timeFadeLength\*clipDuration[1], } ) end ) --THIS: timer.performWithDelay( duration - (clipDuration.timeFadeLength\*clipDuration[2]), function() audio.fadeOut( { 3, clipDuration.timeFadeLength \* clipDuration[2] } ) end ) --VS. THIS: timer.performWithDelay( duration, function() audio.stop( 3 ) end )