Wiki Page Content

Differences between revisions 1 and 2
Revision 1 as of 2009-11-17 21:07:43
Size: 1027
Editor: SheenaSmith
Comment: create page, add content
Revision 2 as of 2009-11-17 21:18:38
Size: 1887
Editor: SheenaSmith
Comment: content added
Deletions are marked like this. Additions are marked like this.
Line 19: Line 19:
||'''src'''||points to the source audio to be mixed||
||'''len'''||defines the length of the audio clip||
||'''src'''||points to the source audio buffers to be mixed||
||'''len'''||defines the length of the audio buffers in bytes||
Line 29: Line 29:
This takes two audio buffers of the playing audio format and mixes them, performing addition, volume adjustment, and overflow clipping. This takes two audio buffers of '''len''' bytes each of the playing audio format and mixes them, performing addition, volume adjustment, and overflow clipping.
Line 31: Line 31:
Note this does not change hardware volume. Note that this does not change hardware volume.
Line 35: Line 35:
Do not use this function for mixing together more than two streams of sample data. The output from repeated application of this function may be distorted by clipping, because there is no accumulator with greater range than the input (not to mention this being an inefficient way of doing it). Use mixing functions from SDL_mixer, OpenAL, or write your own mixer instead.

It is a common misconception that this function is required to write audiodata to an outputstream in the audio-callback like:
{{{#!highlight cpp
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 writing the audiodata directly to stream; that is if you don't need the volume adjustment.

SDL_MixAudio

Use this function to mix audio data.

Syntax

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

Function Parameters

dst

points to the destination for the mixed audio

src

points to the source audio buffers to be mixed

len

defines the length of the audio buffers in bytes

volume

ranges from 0 - 128, and should be set to ::SDL_MIX_MAXVOLUME for full audio volume

Code Examples

You can add your code example here

Remarks

This takes two audio buffers of len bytes each of the playing audio format and mixes them, performing addition, volume adjustment, and overflow clipping.

Note that this does not change hardware volume.

This is provided for convenience -- you can mix your own audio data.

Do not use this function for mixing together more than two streams of sample data. The output from repeated application of this function may be distorted by clipping, because there is no accumulator with greater range than the input (not to mention this being an inefficient way of doing it). Use mixing functions from SDL_mixer, OpenAL, or write your own mixer instead.

It is a common misconception that this function is required to write audiodata to an outputstream in the audio-callback like:

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 writing the audiodata directly to stream; that is if you don't need the volume adjustment.

None: SDL_MixAudio (last edited 2015-01-02 21:46:19 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit