sdlSetAudioStreamOutputChannelMap function

bool sdlSetAudioStreamOutputChannelMap(
  1. Pointer<SdlAudioStream> stream,
  2. Pointer<Int32> chmap,
  3. int count
)

Set the current output channel map of an audio stream.

Channel maps are optional; most things do not need them, instead passing data in the order that SDL expects.

The output channel map reorders data that leaving a stream via SDL_GetAudioStreamData.

Each item in the array represents an input channel, and its value is the channel that it should be remapped to. To reverse a stereo signal's left and right values, you'd have an array of { 1, 0 }. It is legal to remap multiple channels to the same thing, so { 1, 1 } would duplicate the right channel to both channels of a stereo signal. An element in the channel map set to -1 instead of a valid channel will mute that channel, setting it to a silence value.

You cannot change the number of channels through a channel map, just reorder/mute them.

The output channel map can be changed at any time, as output remapping is applied during SDL_GetAudioStreamData.

Audio streams default to no remapping applied. Passing a NULL channel map is legal, and turns off remapping.

SDL will copy the channel map; the caller does not have to save this array after this call.

If count is not equal to the current number of channels in the audio stream's format, this will fail. This is a safety measure to make sure a race condition hasn't changed the format while this call is setting the channel map.

\param stream the SDL_AudioStream to change. \param chmap the new channel map, NULL to reset to default. \param count The number of channels in the map. \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, as it holds a stream-specific mutex while running. Don't change the stream's format to have a different number of channels from a a different thread at the same time, though!

\since This function is available since SDL 3.1.3.

\sa SDL_SetAudioStreamInputChannelMap

extern SDL_DECLSPEC bool SDLCALL SDL_SetAudioStreamOutputChannelMap(SDL_AudioStream *stream, const int *chmap, int count)

Implementation

bool sdlSetAudioStreamOutputChannelMap(
    Pointer<SdlAudioStream> stream, Pointer<Int32> chmap, int count) {
  final sdlSetAudioStreamOutputChannelMapLookupFunction =
      libSdl3.lookupFunction<
          Uint8 Function(Pointer<SdlAudioStream> stream, Pointer<Int32> chmap,
              Int32 count),
          int Function(Pointer<SdlAudioStream> stream, Pointer<Int32> chmap,
              int count)>('SDL_SetAudioStreamOutputChannelMap');
  return sdlSetAudioStreamOutputChannelMapLookupFunction(
          stream, chmap, count) ==
      1;
}