How to play 2 sounds?

Hello,
what play 2 sounds (at the same time)with sdl (not use sdlmixer)?

Just add the samples together, basically. Multiply to scale the
volume. Don’t clip! (That is, you’ll have to lower the volume to make
room for more simultaneous sounds, or the output will overflow and
wrap, which sounds terrible.)

Have a look at this little toy I just hacked; “simplemixer”;

Info:
http://olofson.net/examples.html

Direct download:
http://olofson.net/download/simplemixer.tar.gz

It doesn’t get much simpler than that - but it doesn’t do much either,
and it’s not very “nice”. No pitch control, and it supports only one
output format: 44.1 kHz 16 bit stereo.

It doesn’t even check the format of the sound files loaded, so you’d
better make sure they’re 16 bit mono at 44.1 kHz. (Well, the sample
rate isn’t critical. They’ll be mixed as if they were 44.1 kHz. :slight_smile:

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Saturday 24 May 2003 22.13, SDL wrote:

Hello,
what play 2 sounds (at the same time)with sdl (not use sdlmixer)?

what play 2 sounds (at the same time)with sdl (not use sdlmixer)?

Use SDL_mixer. :slight_smile:

You can mix them yourself in your audio callback (or feed something you
premixed elsewhere to the audio device during your callback), but this is
a real pain. SDL_MixAudio() can be used to mix two samples at a given
volume, or you can do it yourself, but ultimately, you have to feed a
stream of bytes to the audio device.

There isn’t an SDL function to play one-shot sounds (or play two one-shot
sounds at the same time). This is what SDL_mixer is for, and more or less
does what I jusst described above.

–ryan.

…or loads of fun! :wink:

Either way, doing it right is far from trivial. The real hard part is
resampling without ruining the sound quality. Linear interpolation is
better than nothing, but far from good. Cubic is ok, but far from
perfect. Anything that gives really good results will also burn
plenty of CPU time, so you have to balance quality against system
requirements. Or just throw in a bunch of different resamplers, like
I did in Kobo Deluxe and Audiality.

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Sunday 25 May 2003 11.10, Ryan C. Gordon wrote:

what play 2 sounds (at the same time)with sdl (not use sdlmixer)?

Use SDL_mixer. :slight_smile:

You can mix them yourself in your audio callback (or feed something
you premixed elsewhere to the audio device during your callback),
but this is a real pain.

thanks for all.

thanks for all.

“SDL” <@zesj> escreveu na mensagem
news:baojuv$u34$1 at main.gmane.org…> Hello,

what play 2 sounds (at the same time)with sdl (not use sdlmixer)?