SDL_MixAudio

Name

SDL_MixAudio -- Mix audio data

Synopsis

#include "SDL.h"

void SDL_MixAudio(Uint8 *dst, Uint8 *src, Uint32 len, int volume);

Description

This function takes two audio buffers of len bytes each of the playing audio format and mixes them, performing addition, volume adjustment, and overflow clipping. The volume ranges from 0 to SDL_MIX_MAXVOLUME and should be set to the maximum value for full audio volume. Note this does not change hardware volume. This is provided for convenience -- you could also mix your own audio data.

void audio_callback(void *udata, Uint8 *stream, int len)
{
    SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME);
}

Although this works, for a single channel it's just as good as just writing the audiodata directly to stream, that is if you don't need the volume adjustment.

If you need to mix more channels of sample data writing your own mixer is not that difficult, for starters use a signed audio stream and just add the values and clip the result. There is an example of this in Audio_Examples.

See Also

SDL_OpenAudio Audio_Examples

SDL_MixAudio (last edited 2009-12-25 23:32:07 by 201-255-140-237)