Clipping Audio
-
I have been asked if it is possible to cut an audio track short and this is what I came up with:
dealSound = loadaudio("Wild Forts/FX_Card_Deal_02") playingSound = false count = 0 clipTime = 0.4 loop clear() print(count) update() c = controls( 0 ) if c.a then dealCard() endif repeat function dealCard() if !playingSound then playaudio(0, dealSound, 1.0, 0.5, 1, 1) playingSound = true timer1 = setTimer(clipTime, 1, stopChannel0()) endif return void function stopChannel0() if playingSound then count += 1 stopChannel(0) playingSound = false endif return voidBasically at the same time as starting playing the audio you start a timer to trigger at a specified interval to stop it. If anyone can come up with a better/simpler solution please let me know!
-
In the Ninja Scroll game I had to fade out multiple bits of audio and layer them to get the sword slash fx sounding right. If you don't want to hard clip a sound effect, a controllable fade is very helpful.
I'm sure there is a much prettier way to do it, but I did something like:
audio = loadAudio("David Silvera/chuckle_11") chanVol = 2 fadeOut = 0.02 sfxPlaying = false sfxFade = false loop clear() c = controls(0) if c.a then playSfx() endif if sfxPlaying then fadeSfx() endif update() repeat function playSfx() if !sfxPlaying then chanVol = 2 playAudio(0, audio, chanVol, 0.5, 1, 0) sfxPlaying = true sfxFade = true endif return void function fadeSfx() chanVol -= fadeOut setVolume(0, chanVol) if chanVol <= 0 then sfxFade = false sfxPlaying = false endif return voidThis doesn't use the
setTimer()function and thefadeOutvalue can be adjusted very precisely to make the sound play for any length of time. I'm sure with a little bit of maths you could get a very nicely adjustable drop-off rate too. -
Yep, used an audio fade for my AnimeJump Game as well