sdlMixAudio function
Mix audio data in a specified format.
This takes an audio buffer src
of len
bytes of format
data and mixes
it into dst
, performing addition, volume adjustment, and overflow
clipping. The buffer pointed to by dst
must also be len
bytes of
format
data.
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).
It is a common misconception that this function is required to write audio data to an output stream in an audio callback. While you can do that, SDL_MixAudio() is really only needed when you're mixing a single audio stream with a volume adjustment.
\param dst the destination for the mixed audio. \param src the source audio buffer to be mixed. \param format the SDL_AudioFormat structure representing the desired audio format. \param len the length of the audio buffer in bytes. \param volume ranges from 0.0 - 1.0, and should be set to 1.0 for full audio volume. \returns true on success or false on failure; call SDL_GetError() for more information.
\threadsafety It is safe to call this function from any thread.
\since This function is available since SDL 3.1.3.
extern SDL_DECLSPEC bool SDLCALL SDL_MixAudio(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format, Uint32 len, float volume)
Implementation
bool sdlMixAudio(Pointer<Uint8> dst, Pointer<Uint8> src, int format, int len,
double volume) {
final sdlMixAudioLookupFunction = libSdl3.lookupFunction<
Uint8 Function(Pointer<Uint8> dst, Pointer<Uint8> src, Int32 format,
Uint32 len, Float volume),
int Function(Pointer<Uint8> dst, Pointer<Uint8> src, int format, int len,
double volume)>('SDL_MixAudio');
return sdlMixAudioLookupFunction(dst, src, format, len, volume) == 1;
}