[SDL] callback issue

Ryan C. Gordon icculus at icculus.org
Tue May 1 01:50:12 PDT 2007


> network; Both are not present all the time so do I need to call
> SDL_MixAudio() if both are present? Or just memcpy both if and when they
> are present?
> 
> Like this:
> 
> Got buff_A data?
>         memcpy(stream...
> Got buff_B data?
>         memcpy (stream...

If you memcpy() both in the same call, the second one will just 
overwrite the first, of course. If you need two or more things to mix 
together to be played back at the same time, you should memcpy() the 
first thing and then use SDL_MixAudio() or something similar to add each 
of the rest to the stream. Or memset() the stream and then mix all the 
sources, if you find the code is cleaner and don't mind the extra memory 
bandwidth.

But if you just have one data stream, using SDL_MixAudio is either 
wasteful (since a memcpy() will be faster when mixing against silence), 
or dangerous (if the stream we pass in ceases to be initialized for you 
in the future).

--ryan.



More information about the SDL mailing list