

If the application requests a feature that the hardware doesn't offer, SDL will always try to get the closest equivalent.įor example, if you ask for float32 audio format, but the sound card only supports int16, SDL will set the hardware to int16. These flags specify how SDL should behave when a device cannot offer a specific feature. If you passed a NULL callback, this value is ignored.Īllowed_changes can have the following flags OR'd together:

Alternately, you may pass a NULL pointer here, and call SDL_QueueAudio() with some frequency, to queue more audio samples to be played (or for capture devices, call SDL_DequeueAudio() with some frequency, to obtain audio samples). This function usually runs in a separate thread, and so you should protect data structures that it accesses by calling SDL_LockAudioDevice() and SDL_UnlockAudioDevice() in your code. It is passed a pointer to the audio buffer, and the length in bytes of the audio buffer. desired->callback should be set to a function that will be called when the audio device is ready for more data.desired->silence is the value used to set the buffer to silence, and is calculated by SDL_OpenAudioDevice().desired->size is the size in _bytes_ of the audio buffer, and is calculated by SDL_OpenAudioDevice().Note that the number of sample frames is directly related to time by the following formula: ms = (sampleframes*1000)/freq Smaller values reduce latency, but can lead to underflow if the application is doing heavy processing and cannot fill the audio buffer in time. Good values seem to range between 5 inclusive, depending on the application and CPU speed.
Audiodevice value driver#
This number should be a power of two, and may be adjusted by the audio driver to a value more suitable for the hardware.
Audiodevice value drivers#
The device name is a UTF-8 string reported by SDL_GetAudioDeviceName(), but some drivers allow arbitrary and driver-specific strings, such as a hostname/IP address for a remote audio server, or a filename in the diskaudio driver.Īn opened audio device starts out paused, and should be enabled for playing by calling SDL_PauseAudioDevice(devid, 0) when you are ready for your audio callback function to be called. Passing in a device name of NULL requests the most reasonable default (and is equivalent to what SDL_OpenAudio() does to choose a device). Starting with SDL 2.0.5, recording is implemented and this value can be non-zero. Please note that SDL 2.0 before 2.0.5 did not support recording as such, this function would fail if iscapture was not zero. As such, this function will never return a 1 so as not to conflict with the legacy function.

SDL_OpenAudio(), unlike this function, always acts on device ID 1. Returns a valid device ID that is > 0 on success or 0 on failure call SDL_GetError() for more information.įor compatibility with SDL 1.2, this will never return 1, since SDL reserves that ID for the legacy SDL_OpenAudio() function. Non-zero to specify a device should be opened for recording, not playbackĪn SDL_AudioSpec structure representing the desired output format see SDL_OpenAudio() for more informationĪn SDL_AudioSpec structure filled in with the actual output format see SDL_OpenAudio() for more information NULL requests the most reasonable default device. SDL_AudioDeviceID SDL_OpenAudioDevice( const char *device, int iscapture, const SDL_AudioSpec *desired, SDL_AudioSpec *obtained, int allowed_changes) Function ParametersĪ UTF-8 string reported by SDL_GetAudioDeviceName() or a driver-specific name as appropriate.
