gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Audio > Mixing sounds after eachother

#29944 - bertsnks - Sat Nov 27, 2004 1:23 am

Whenever I stop a looping sound abruply and immediatly play a different sound, my mixer generates a "click" noise, does anyone know why this happens and how it can be fixed on GBA without much CPU usage?

#29949 - tepples - Sat Nov 27, 2004 3:17 am

It could be one of three things:
  • You are mixing unsigned samples and don't have the bias right.
  • You are using a sample with heavy deep bass content and cutting it off abruptly when the waveform isn't anywhere near 0.
  • You are mixing past the end of the sample.
You can verify which is the problem by recording the output in VBA and posting the output here as a zipped .wav file so that we can help you try various possibilities.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#29993 - DekuTree64 - Sat Nov 27, 2004 10:04 am

Yeah, usually that's caused by the sound being too far from 0 at the time you cut it. The 'correct' way to deal with it is to fade the volume out over a few samples so there's no abrupt change (fading over about 16 or 32 samples is usually enough).
That can be a bit tricky since you generally need the channel to play something else immediately after the fadeout, so you'd have to make sure the fading happened in the samples BEFORE the song update or the channel's vars will be overwritten, but until the song update happens, you don't know which channels to fade. Plenty of ways to deal with it, but no clear good ones.

One trick that really helps is to only fade the last sample value that was played, rather than updating the channel during it. The volume is dropping so fast anyway that you can't tell the difference, and then you can just record the output level (sample*volume) of the channel during the song update when you're cutting it, and then fade that value over the few samples AFTER the song update.
Be sure to clip it though, since that channel will be outputting new data as well as the fading level, so it could potentially overflow things.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku