sdlxGetAudioStreamFormat function audio

bool sdlxGetAudioStreamFormat(
  1. Pointer<SdlAudioStream> stream,
  2. SdlxAudioSpec? srcSpec,
  3. SdlxAudioSpec? dstSpec
)

Query the current format of an audio stream.

\param stream the SDL_AudioStream to query. \param src_spec where to store the input audio format; ignored if NULL. \param dst_spec where to store the output audio format; ignored if NULL. \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.

\since This function is available since SDL 3.2.0.

\sa SDL_SetAudioStreamFormat

extern SDL_DECLSPEC bool SDLCALL SDL_GetAudioStreamFormat(SDL_AudioStream *stream, SDL_AudioSpec *src_spec, SDL_AudioSpec *dst_spec)

Implementation

bool sdlxGetAudioStreamFormat(
  Pointer<SdlAudioStream> stream,
  SdlxAudioSpec? srcSpec,
  SdlxAudioSpec? dstSpec,
) {
  Pointer<SdlAudioSpec> srcSpecPointer = nullptr;
  Pointer<SdlAudioSpec> dstSpecPointer = nullptr;
  if (srcSpec != null) {
    srcSpecPointer = srcSpec.calloc();
  }
  if (dstSpec != null) {
    dstSpecPointer = dstSpec.calloc();
  }
  final result = sdlGetAudioStreamFormat(
    stream,
    srcSpecPointer,
    dstSpecPointer,
  );
  if (result) {
    if (srcSpec != null) {
      srcSpec.loadFromPointer(srcSpecPointer);
    }
    if (dstSpec != null) {
      dstSpec.loadFromPointer(dstSpecPointer);
    }
  }
  if (srcSpecPointer != nullptr) {
    srcSpecPointer.callocFree();
  }
  if (dstSpecPointer != nullptr) {
    dstSpecPointer.callocFree();
  }
  return result;
}