[SDL] Creating audio samples via code

Ryan C. Gordon icculus at icculus.org
Tue May 22 01:56:03 PDT 2007


> Is there some reason why your algorithm cannot generate N samples at a 
> time, on demand? I'm thinking about abusing the effect API. (See 
> Mix_RegisterEffect etc.) Keep the channel alive using a dummy looping 
> sample

I was going to recommend something similar, actually, but didn't want to 
be the first to offer it because it's a Big Nasty Hack...but it'll work.

David's other solution would be way better, but would require further 
development work in SDL_mixer itself: if there was going to be an 
extension at all, it would be to have SDL_mixer fire a callback where 
you generate the audio for the channel...much like what SDL's audio 
callback does, but you can have several independent ones running at once 
that SDL_mixer mixes into a final output buffer. This way you could mix 
and match premade audio with algorithmically generated noise...that's 
basically what was described with the Effects API, but it just cleans it 
up into something formal and removes the need to have a buffer of 
looping silence with an effect.

If you're generating all your own audio, just use SDL directly and not 
SDL_mixer...obviously, SDL_mixer is most useful if you want to fire off 
some .wav files or whatnot and not worry about it too much. If you just 
want to decode some .oggs, maybe SDL_sound will do, too.

--ryan.




More information about the SDL mailing list