Playing multiple sounds simultaneously (SDL_Mixer, BeOS)

I’ve been using SDL_Mixer 1.2 for BeOS. I’ve had some problems playing
multiple sounds simultaneously.

I’m looking for a function that will play a sound on all speakers, and not
overwrite whatever is currently playing. For example, I want explosions
to be occuring, while the player walks over a concrete surface.

I’ve been over the SDL_Mixer function set thoroughly, but cannot seem to
find the function needed to do this. All the functions I’ve tried
overwrite the previous channel, and BeOS only offers two channels. So no
sort of rotation is possible.

What have other people done? Is the BeOS implementation somehow limited?
Am I misunderstanding the concept of channels?

What have other people done? Is the BeOS implementation somehow
limited? Am I misunderstanding the concept of channels?

“Channel” in this case has nothing to do with stereo (“BeOS supports two
channels”). Channels are an abstraction in SDL_Mixer above the OS and above
SDL_audio. If you can play a stream of sound at all in SDL, then you can mix
multiple streams of sound (“channels”) through SDL_mixer.

If you start three sounds on channels 1, 2, and 3, and start some music too,
then all four of these sounds should mix into one stream of sound behind the
scenes, which makes it’s way to your sound card.

I don’t know if that clarifies anything. :slight_smile:

–ryan.

That’s what I thought it should be, but when I initialize the Mixer with
say, 8 channels, SDL_Error returns: “1 (mono) and 2 (stereo) channels
supported”.

Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, 8, chunkSize) < 0

Even though it only works for two channels, it’s otherwise behaving as
expected.

Are there any variables which affect the number of channels available?On Tue, 21 Aug 2001, Ryan C. Gordon wrote:

What have other people done? Is the BeOS implementation somehow
limited? Am I misunderstanding the concept of channels?

“Channel” in this case has nothing to do with stereo (“BeOS supports two
channels”). Channels are an abstraction in SDL_Mixer above the OS and above
SDL_audio. If you can play a stream of sound at all in SDL, then you can mix
multiple streams of sound (“channels”) through SDL_mixer.

If you start three sounds on channels 1, 2, and 3, and start some music too,
then all four of these sounds should mix into one stream of sound behind the
scenes, which makes it’s way to your sound card.

I don’t know if that clarifies anything. :slight_smile:

–ryan.

“Matt Pekar” wrote

That’s what I thought it should be, but when I initialize the Mixer with
say, 8 channels, SDL_Error returns: “1 (mono) and 2 (stereo) channels
supported”.

Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, 8, chunkSize) < 0

matt, you’re on the right trail, you are running up against an
unfortunate choice of terminology. when you initialize SDL_mixer
like this, the “channels” refers to stereo or mono. after you
initialize, you really don’t deal with stero or mono channels
anymore, from now on a channel is an individual sound stream
that can be played at anytime (and is automatically mixed with
other playing channels).

SDL_mixer defaults to 8 simultaneous channels, so you likely
don’t even need to change this, but you can with
Mix_AllocateChannels()

unless you want specific control, you can just let SDL_mixer
manage which sound goes to any available channel. call
Mix_PlayChannel() with an argument of -1 for the channel argument.

that should be all you need. i think the use of the work
"channel" for these playback streams is unfortunate, but once
you get past it it’s easy enough to keep them unconfused with
’stereo channels’ :]