sdlGetAudioDeviceFormat function
Get the current audio format of a specific audio device.
For an opened device, this will report the format the device is currently using. If the device isn't yet opened, this will report the device's preferred format (or a reasonable default if this can't be determined).
You may also specify SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK or SDL_AUDIO_DEVICE_DEFAULT_RECORDING here, which is useful for getting a reasonable recommendation before opening the system-recommended default device.
You can also use this to request the current device buffer size. This is specified in sample frames and represents the amount of data SDL will feed to the physical hardware in each chunk. This can be converted to milliseconds of audio with the following equation:
ms = (int) ((((Sint64) frames) * 1000) / spec.freq);
Buffer size is only important if you need low-level control over the audio playback timing. Most apps do not need this.
\param devid the instance ID of the device to query. \param spec on return, will be filled with device details. \param sample_frames pointer to store device buffer size, in sample frames. Can be 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.
\since This function is available since SDL 3.1.3.
extern SDL_DECLSPEC bool SDLCALL SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *sample_frames)
Implementation
bool sdlGetAudioDeviceFormat(
int devid, Pointer<SdlAudioSpec> spec, Pointer<Int32> sampleFrames) {
final sdlGetAudioDeviceFormatLookupFunction = libSdl3.lookupFunction<
Uint8 Function(Uint32 devid, Pointer<SdlAudioSpec> spec,
Pointer<Int32> sampleFrames),
int Function(int devid, Pointer<SdlAudioSpec> spec,
Pointer<Int32> sampleFrames)>('SDL_GetAudioDeviceFormat');
return sdlGetAudioDeviceFormatLookupFunction(devid, spec, sampleFrames) == 1;
}