sdlConvertAudioSamples function

bool sdlConvertAudioSamples(
  1. Pointer<SdlAudioSpec> srcSpec,
  2. Pointer<Uint8> srcData,
  3. int srcLen,
  4. Pointer<SdlAudioSpec> dstSpec,
  5. Pointer<Pointer<Uint8>> dstData,
  6. Pointer<Int32> dstLen,
)

Convert some audio data of one format to another format.

Please note that this function is for convenience, but should not be used to resample audio in blocks, as it will introduce audio artifacts on the boundaries. You should only use this function if you are converting audio data in its entirety in one call. If you want to convert audio in smaller chunks, use an SDL_AudioStream, which is designed for this situation.

Internally, this function creates and destroys an SDL_AudioStream on each use, so it's also less efficient than using one directly, if you need to convert multiple times.

\param src_spec the format details of the input audio. \param src_data the audio data to be converted. \param src_len the len of src_data. \param dst_spec the format details of the output audio. \param dst_data will be filled with a pointer to converted audio data, which should be freed with SDL_free(). On error, it will be NULL. \param dst_len will be filled with the len of dst_data. \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_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_data, int src_len, const SDL_AudioSpec *dst_spec, Uint8 **dst_data, int *dst_len)

Implementation

bool sdlConvertAudioSamples(
    Pointer<SdlAudioSpec> srcSpec,
    Pointer<Uint8> srcData,
    int srcLen,
    Pointer<SdlAudioSpec> dstSpec,
    Pointer<Pointer<Uint8>> dstData,
    Pointer<Int32> dstLen) {
  final sdlConvertAudioSamplesLookupFunction = libSdl3.lookupFunction<
      Uint8 Function(
          Pointer<SdlAudioSpec> srcSpec,
          Pointer<Uint8> srcData,
          Int32 srcLen,
          Pointer<SdlAudioSpec> dstSpec,
          Pointer<Pointer<Uint8>> dstData,
          Pointer<Int32> dstLen),
      int Function(
          Pointer<SdlAudioSpec> srcSpec,
          Pointer<Uint8> srcData,
          int srcLen,
          Pointer<SdlAudioSpec> dstSpec,
          Pointer<Pointer<Uint8>> dstData,
          Pointer<Int32> dstLen)>('SDL_ConvertAudioSamples');
  return sdlConvertAudioSamplesLookupFunction(
          srcSpec, srcData, srcLen, dstSpec, dstData, dstLen) ==
      1;
}