Switch Between Stereo and Mono Sound

Hi,

Does anyone know if I can switch between Stereo and Mono Sound using SDL_mixer during the game (meaning, after Mix_OpenAudio() was called)?

Or should I just call Mix_CloseAudio() and then call Mix_OpenAudio() again?

Thanks,___________________________________________________________________
Speed up your surfing with Juno SpeedBand.
Now includes pop-up blocker!
Only $14.95/month -visit http://www.juno.com/surf to sign up today!

Does anyone know if I can switch between Stereo and Mono Sound
using SDL_mixer during the game (meaning, after Mix_OpenAudio() was
called)?

Or should I just call Mix_CloseAudio() and then call Mix_OpenAudio() again?

It’s “safe” to do this in that the program won’t crash, but you will
have a total stop in your sound while things reset, need to restart all
the sounds and music, and reregister all mixer effects you want to use,
so it’s not feasible to do this over and over during gameplay.

It might be better to always open the device in stereo and write a
simple posteffect to downmix to mono. Here’s a totally untested example:

// make stereo effects interpolate and play out of both speakers as
// if device was opened as mono…
void Eff_makemono16(int chan, void *stream, int len, void *udata)
{
Sint16 *ptr = (Sint16 *) stream;
for (int i = 0; i < len; i += sizeof (Sint16) * 2, ptr += 2)
ptr[0] = ptr[1] = (ptr[0] + ptr[1]) / 2;
}

// make sure the device is being fed stereo, 16-bit samples!

// Call this to change from stereo to mono on the fly…
Mix_RegisterEffect(MIX_CHANNEL_POST, Eff_makemono16, NULL, NULL);

// Call this when you want to switch back to stereo…
Mix_UnregisterEffect(MIX_CHANNEL_POST, Eff_makemono16);

…the overhead on this is probably trivial, and might be cleaner than
restarting the whole mixer.

Good luck,
–ryan.

Michael Wyrzykowski wrote:

Hi,

Does anyone know if I can switch between Stereo and Mono Sound using SDL_mixer during the game (meaning, after Mix_OpenAudio() was called)?

On the off-chance you want to do this because some of your sound effects are
mono .wav files, you should know that conversion to stereo is automatic
when you’ve opened for 2 channels.

Greg

On the off-chance you want to do this because some of your sound effects
are mono .wav files, you should know that conversion to stereo is automatic
when you’ve opened for 2 channels.

I was guessing he wanted to drop into mono output for menus or something.

Yeah, you can play a mono sound when the mixer is opened for stereo and
it’ll do the right thing.

–ryan.

On the off-chance you want to do this because some of your sound effects
are mono .wav files, you should know that conversion to stereo is
automatic
when you’ve opened for 2 channels.

I was guessing he wanted to drop into mono output for menus or something.

Yeah, you can play a mono sound when the mixer is opened for stereo and
it’ll do the right thing.

–ryan.

Switching between Stereo / Mono is just for a menu option so users can hear the difference between the two choices. I think I’ll just fade out the music, close sdl_mixer, and then re-open with the mode (stereo or mono) depending on what the user choose.

I just wasn’t sure if there was an function call that wasn’t documented on the SDL_mixer site I could make to switch between the two.

Thanks,___________________________________________________________________
Speed up your surfing with Juno SpeedBand.
Now includes pop-up blocker!
Only $14.95/month -visit http://www.juno.com/surf to sign up today!