r/gamedev•
NeonMan

I need a SDL_mixer programming model.

Posted Dec 24, 2014, 3:45 PM UTC

53
phao•

Did you check SDL audio related features?

https://wiki.libsdl.org/CategoryAudio

SDL mixer is to make some things more convenient, but for what I've studied, it's for less fine grained control over things. SDL has its own audio support, which is as far as I can tell good for what you want to do. It's less easier to use as far as I've heard (I've never used it), but from what I've read it suits you.

5
NeonManOP•

I'll check it out.

Thanks.

1
kimixa•

There's Mix_HookMusic() that allows you to supply a callback, that looks like it might do what you want. I believe it /replaces/ the SDL_Mixer music player though, so you can't blend music from two sources automatically.

There's a trivial example of HookMusic here

You don't need to use SDL_mixer if you always want to provide the sound samples directly - the callback field of the SDL_AudioSpec struct passed into SDL_OpenAudioDevice() does that.

I do not believe that SDL_Mixer and this callback can co-exist, however, as IIRC this is the method SDL_Mixer gets it's audio data into SDL, so again you would have to do manual mixing if you want to mix audio from different sources (e.g. sfx playing at the same time as music)

3