SDL
2.0
|
#include "../SDL_internal.h"
#include "SDL.h"
#include "SDL_audio.h"
#include "SDL_audio_c.h"
#include "SDL_sysaudio.h"
#include "../thread/SDL_systhread.h"
Go to the source code of this file.
Macros | |
#define | _THIS SDL_AudioDevice *_this |
#define | FILL_STUB(x) |
#define | CHECK_FMT_STRING(x) if (SDL_strcmp(string, #x) == 0) return AUDIO_##x |
#define | NUM_FORMATS 10 |
Variables | |
static SDL_AudioDriver | current_audio |
static SDL_AudioDevice * | open_devices [16] |
static const AudioBootStrap *const | bootstrap [] |
static int | format_idx |
static int | format_idx_sub |
static SDL_AudioFormat | format_list [NUM_FORMATS][NUM_FORMATS] |
#define _THIS SDL_AudioDevice *_this |
Definition at line 31 of file SDL_audio.c.
#define CHECK_FMT_STRING | ( | x | ) | if (SDL_strcmp(string, #x) == 0) return AUDIO_##x |
Referenced by SDL_ParseAudioFormat().
#define FILL_STUB | ( | x | ) |
Referenced by finish_audio_entry_points_init().
#define NUM_FORMATS 10 |
Definition at line 1557 of file SDL_audio.c.
Referenced by SDL_FirstAudioFormat(), and SDL_NextAudioFormat().
|
static |
Definition at line 378 of file SDL_audio.c.
References SDL_AudioDriver::detectionLock, SDL_AudioDeviceItem::handle, SDL_AudioDeviceItem::name, SDL_AudioDeviceItem::next, NULL, retval, SDL_assert, SDL_INLINE, SDL_LockMutex, SDL_malloc, SDL_strlcpy, SDL_strlen, and SDL_UnlockMutex.
Referenced by add_capture_device(), and add_output_device().
|
static |
Definition at line 402 of file SDL_audio.c.
References add_audio_device(), SDL_AudioDriverImpl::HasCaptureSupport, SDL_AudioDriver::impl, SDL_AudioDriver::inputDeviceCount, SDL_AudioDriver::inputDevices, SDL_assert, and SDL_INLINE.
Referenced by SDL_AddAudioDevice().
|
static |
Definition at line 409 of file SDL_audio.c.
References add_audio_device(), SDL_AudioDriver::outputDeviceCount, and SDL_AudioDriver::outputDevices.
Referenced by SDL_AddAudioDevice().
|
static |
Definition at line 957 of file SDL_audio.c.
References SDL_AudioDeviceItem::handle, SDL_AudioDeviceItem::next, NULL, SDL_FALSE, and SDL_free.
Referenced by SDL_GetNumAudioDevices().
|
static |
Definition at line 1051 of file SDL_audio.c.
References SDL_AudioDevice::buffer_queue, SDL_AudioDriverImpl::CloseDevice, SDL_AudioDevice::enabled, SDL_AudioDevice::hidden, SDL_AudioDevice::id, SDL_AudioDriver::impl, SDL_AudioDevice::mixer_lock, NULL, SDL_assert, SDL_AtomicSet, SDL_DestroyMutex, SDL_free, SDL_FreeAudioStream, SDL_FreeDataQueue(), SDL_WaitThread, SDL_AudioDevice::shutdown, SDL_AudioDevice::stream, SDL_AudioDevice::thread, and SDL_AudioDevice::work_buffer.
Referenced by open_audio_device(), SDL_AudioQuit(), and SDL_CloseAudioDevice().
Definition at line 334 of file SDL_audio.c.
References FILL_STUB, SDL_AudioDriver::impl, SDL_AudioDriverImpl::LockDevice, NULL, SDL_AudioLockOrUnlockDeviceWithNoMixerLock(), SDL_AudioDriverImpl::SkipMixerLock, and SDL_AudioDriverImpl::UnlockDevice.
Referenced by SDL_AudioInit().
|
static |
Definition at line 415 of file SDL_audio.c.
References SDL_AudioDriverImpl::FreeDeviceHandle, SDL_AudioDeviceItem::handle, SDL_AudioDriver::impl, SDL_AudioDeviceItem::next, NULL, and SDL_free.
Referenced by SDL_AudioQuit().
|
static |
Definition at line 197 of file SDL_audio.c.
References NULL, SDL_arraysize, and SDL_SetError.
Referenced by SDL_ClearQueuedAudio(), SDL_CloseAudioDevice(), SDL_DequeueAudio(), SDL_GetAudioDeviceStatus(), SDL_GetQueuedAudioSize(), SDL_LockAudioDevice(), SDL_MixAudio(), SDL_OpenedAudioDeviceDisconnected(), SDL_PauseAudioDevice(), SDL_QueueAudio(), and SDL_UnlockAudioDevice().
|
static |
Definition at line 299 of file SDL_audio.c.
References SDL_FALSE, SDL_ThreadID, SDL_TRUE, SDL_AudioDevice::thread, and SDL_AudioDevice::threadid.
Referenced by SDL_AudioLockDevice_Default(), and SDL_AudioUnlockDevice_Default().
|
static |
Definition at line 475 of file SDL_audio.c.
References SDL_AudioDeviceItem::handle, SDL_AudioDeviceItem::next, NULL, SDL_assert, and SDL_TRUE.
Referenced by SDL_RemoveAudioDevice().
|
static |
Definition at line 1150 of file SDL_audio.c.
References SDL_AudioDriverImpl::AllowsArbitraryDeviceNames, SDL_AudioDevice::buffer_queue, SDL_AudioSpec::callback, SDL_AudioDevice::callbackspec, SDL_AudioSpec::channels, close_audio_device(), DEFAULT_INPUT_DEVNAME, DEFAULT_OUTPUT_DEVNAME, SDL_AudioDriver::detectionLock, device, SDL_AudioDevice::enabled, SDL_AudioSpec::format, SDL_AudioSpec::freq, SDL_AudioDeviceItem::handle, SDL_AudioDevice::handle, SDL_AudioDriverImpl::HasCaptureSupport, SDL_AudioDevice::hidden, i, SDL_AudioDevice::id, SDL_AudioDriver::impl, SDL_AudioDriver::inputDevices, SDL_AudioDevice::iscapture, SDL_AudioDevice::mixer_lock, SDL_AudioDeviceItem::name, SDL_AudioDeviceItem::next, NULL, SDL_AudioDriverImpl::OnlyHasDefaultCaptureDevice, SDL_AudioDriverImpl::OnlyHasDefaultOutputDevice, SDL_AudioDriverImpl::OpenDevice, SDL_AudioDriver::outputDevices, SDL_AudioDevice::paused, prepare_audiospec(), SDL_AudioDriverImpl::ProvidesOwnCallbackThread, SDL_AudioSpec::samples, SDL_arraysize, SDL_assert, SDL_AtomicSet, SDL_AUDIO_ALLOW_CHANNELS_CHANGE, SDL_AUDIO_ALLOW_FORMAT_CHANGE, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE, SDL_AUDIOBUFFERQUEUE_PACKETLEN, SDL_BufferQueueDrainCallback(), SDL_BufferQueueFillCallback(), SDL_CalculateAudioSpec(), SDL_calloc, SDL_CaptureAudio(), SDL_CreateMutex, SDL_CreateThreadInternal(), SDL_FALSE, SDL_getenv, SDL_INIT_AUDIO, SDL_LockMutex, SDL_malloc, SDL_NewAudioStream, SDL_NewDataQueue(), SDL_OutOfMemory, SDL_RunAudio(), SDL_SetError, SDL_snprintf, SDL_strcmp, SDL_TRUE, SDL_UnlockMutex, SDL_WasInit, SDL_AudioDevice::shutdown, SDL_AudioSpec::size, SDL_AudioDriverImpl::SkipMixerLock, SDL_AudioDevice::spec, SDL_AudioDevice::stream, SDL_AudioDevice::thread, SDL_AudioSpec::userdata, SDL_AudioDevice::work_buffer, and SDL_AudioDevice::work_buffer_len.
Referenced by SDL_OpenAudio(), and SDL_OpenAudioDevice().
|
static |
Definition at line 1093 of file SDL_audio.c.
References AUDIO_S16, SDL_AudioSpec::channels, SDL_AudioSpec::format, SDL_AudioSpec::freq, SDL_AudioSpec::samples, SDL_atoi, SDL_CalculateAudioSpec(), SDL_getenv, SDL_memcpy, SDL_ParseAudioFormat(), and SDL_SetError.
Referenced by open_audio_device().
Definition at line 432 of file SDL_audio.c.
References add_capture_device(), add_output_device(), SDL_AUDIODEVICEADDED, SDL_ENABLE, SDL_GetEventState, SDL_PushEvent, and SDL_zero.
Referenced by SDL_AudioDetectDevices_Default().
Definition at line 234 of file SDL_audio.c.
Definition at line 261 of file SDL_audio.c.
Definition at line 277 of file SDL_audio.c.
Definition at line 282 of file SDL_audio.c.
Definition at line 211 of file SDL_audio.c.
References DEFAULT_INPUT_DEVNAME, DEFAULT_OUTPUT_DEVNAME, SDL_AudioDriverImpl::HasCaptureSupport, SDL_AudioDriver::impl, SDL_AudioDriverImpl::OnlyHasDefaultCaptureDevice, SDL_AudioDriverImpl::OnlyHasDefaultOutputDevice, SDL_AddAudioDevice(), SDL_assert, SDL_FALSE, and SDL_TRUE.
Definition at line 267 of file SDL_audio.c.
Definition at line 287 of file SDL_audio.c.
Definition at line 255 of file SDL_audio.c.
References NULL.
|
static |
Definition at line 249 of file SDL_audio.c.
int SDL_AudioInit | ( | const char * | driver_name | ) |
Definition at line 885 of file SDL_audio.c.
References AudioBootStrap::demand_only, SDL_AudioDriver::desc, AudioBootStrap::desc, SDL_AudioDriverImpl::DetectDevices, SDL_AudioDriver::detectionLock, finish_audio_entry_points_init(), i, SDL_AudioDriver::impl, AudioBootStrap::init, SDL_AudioDriver::name, AudioBootStrap::name, NULL, SDL_AudioQuit(), SDL_CreateMutex, SDL_getenv, SDL_INIT_AUDIO, SDL_SetError, SDL_strlen, SDL_strncasecmp, SDL_WasInit, and SDL_zero.
|
static |
Definition at line 313 of file SDL_audio.c.
References is_in_audio_device_thread(), SDL_AudioDevice::mixer_lock, and SDL_LockMutex.
|
static |
Definition at line 329 of file SDL_audio.c.
Referenced by finish_audio_entry_points_init().
|
static |
Definition at line 244 of file SDL_audio.c.
Definition at line 272 of file SDL_audio.c.
Definition at line 1527 of file SDL_audio.c.
References close_audio_device(), SDL_AudioDriverImpl::Deinitialize, SDL_AudioDriver::detectionLock, free_device_list(), i, SDL_AudioDriver::impl, SDL_AudioDriver::inputDeviceCount, SDL_AudioDriver::inputDevices, SDL_AudioDriver::name, SDL_AudioDriver::outputDeviceCount, SDL_AudioDriver::outputDevices, SDL_arraysize, SDL_DestroyMutex, SDL_FreeResampleFilter(), and SDL_zero.
Referenced by SDL_AudioInit().
Definition at line 229 of file SDL_audio.c.
Definition at line 224 of file SDL_audio.c.
|
static |
Definition at line 321 of file SDL_audio.c.
References is_in_audio_device_thread(), SDL_AudioDevice::mixer_lock, and SDL_UnlockMutex.
Definition at line 239 of file SDL_audio.c.
Definition at line 520 of file SDL_audio.c.
References SDL_AudioDevice::buffer_queue, device, SDL_AudioDevice::iscapture, NULL, SDL_assert, SDL_CountDataQueue(), SDL_memset, SDL_ReadFromDataQueue(), SDLCALL, SDL_AudioSpec::silence, and SDL_AudioDevice::spec.
Referenced by open_audio_device(), SDL_GetQueuedAudioSize(), and SDL_QueueAudio().
Definition at line 541 of file SDL_audio.c.
References SDL_AudioDevice::buffer_queue, device, SDL_AudioDevice::iscapture, NULL, SDL_assert, and SDL_WriteToDataQueue().
Referenced by open_audio_device(), SDL_DequeueAudio(), and SDL_GetQueuedAudioSize().
void SDL_CalculateAudioSpec | ( | SDL_AudioSpec * | spec | ) |
Definition at line 1605 of file SDL_audio.c.
References AUDIO_U8, SDL_AudioSpec::channels, SDL_AudioSpec::format, SDL_AudioSpec::samples, SDL_AUDIO_BITSIZE, SDL_AudioSpec::silence, and SDL_AudioSpec::size.
Referenced by open_audio_device(), and prepare_audiospec().
|
static |
Definition at line 738 of file SDL_audio.c.
References SDL_AudioDriverImpl::BeginLoopIteration, callback(), SDL_AudioSpec::callback, SDL_AudioDevice::callbackspec, SDL_AudioDriverImpl::CaptureFromDevice, device, SDL_AudioDevice::enabled, SDL_AudioDriverImpl::FlushCapture, SDL_AudioSpec::freq, SDL_AudioDriver::impl, SDL_AudioDevice::iscapture, SDL_AudioDevice::mixer_lock, NULL, SDL_AudioDevice::paused, SDL_AudioSpec::samples, SDL_assert, SDL_AtomicGet, SDL_AudioStreamAvailable, SDL_AudioStreamClear, SDL_AudioStreamGet, SDL_AudioStreamPut, SDL_Delay, SDL_LockMutex, SDL_memset, SDL_OpenedAudioDeviceDisconnected(), SDL_SetThreadPriority, SDL_THREAD_PRIORITY_HIGH, SDL_ThreadID, SDL_UnlockMutex, SDL_AudioDevice::shutdown, SDL_AudioSpec::silence, SDL_AudioSpec::size, SDL_AudioDevice::spec, SDL_AudioDevice::stream, SDL_AudioDriverImpl::ThreadDeinit, SDL_AudioDevice::threadid, SDL_AudioDriverImpl::ThreadInit, SDL_AudioSpec::userdata, and SDL_AudioDevice::work_buffer.
Referenced by open_audio_device().
void SDL_ClearQueuedAudio | ( | SDL_AudioDeviceID | dev | ) |
Drop any queued audio data. For playback devices, this is any queued data still waiting to be submitted to the hardware. For capture devices, this is any data that was queued by the device that hasn't yet been dequeued by the application.
Immediately after this call, SDL_GetQueuedAudioSize() will return 0. For playback devices, the hardware will start playing silence if more audio isn't queued. Unpaused capture devices will start filling the queue again as soon as they have more data available (which, depending on the state of the hardware and the thread, could be before this function call returns!).
This will not prevent playback of queued audio that's already been sent to the hardware, as we can not undo that, so expect there to be some fraction of a second of audio that might still be heard. This can be useful if you want to, say, drop any pending music during a level change in your game.
You may not queue audio on a device that is using an application-supplied callback; calling this function on such a device is always a no-op. You have to queue audio with SDL_QueueAudio()/SDL_DequeueAudio(), or use the audio callback, but not both.
You should not call SDL_LockAudio() on the device before clearing the queue; SDL handles locking internally for this function.
This function always succeeds and thus returns void.
dev | The device ID of which to clear the audio queue. |
Definition at line 623 of file SDL_audio.c.
References SDL_AudioDevice::buffer_queue, device, get_audio_device(), SDL_AudioDriver::impl, SDL_AudioDriverImpl::LockDevice, SDL_AUDIOBUFFERQUEUE_PACKETLEN, SDL_ClearDataQueue(), SDLCALL, and SDL_AudioDriverImpl::UnlockDevice.
This function shuts down audio processing and closes the audio device.
Definition at line 1521 of file SDL_audio.c.
References SDL_CloseAudioDevice().
void SDL_CloseAudioDevice | ( | SDL_AudioDeviceID | devid | ) |
Definition at line 1515 of file SDL_audio.c.
References close_audio_device(), and get_audio_device().
Referenced by SDL_CloseAudio().
Uint32 SDL_DequeueAudio | ( | SDL_AudioDeviceID | dev, |
void * | data, | ||
Uint32 | len | ||
) |
Dequeue more audio on non-callback devices.
(If you are looking to queue audio for output on a non-callback playback device, you want SDL_QueueAudio() instead. This will always return 0 if you use it with playback devices.)
SDL offers two ways to retrieve audio from a capture device: you can either supply a callback that SDL triggers with some frequency as the device records more audio data, (push method), or you can supply no callback, and then SDL will expect you to retrieve data at regular intervals (pull method) with this function.
There are no limits on the amount of data you can queue, short of exhaustion of address space. Data from the device will keep queuing as necessary without further intervention from you. This means you will eventually run out of memory if you aren't routinely dequeueing data.
Capture devices will not queue data when paused; if you are expecting to not need captured audio for some length of time, use SDL_PauseAudioDevice() to stop the capture device from queueing more data. This can be useful during, say, level loading times. When unpaused, capture devices will start queueing data from that point, having flushed any capturable data available while paused.
This function is thread-safe, but dequeueing from the same device from two threads at once does not promise which thread will dequeued data first.
You may not dequeue audio from a device that is using an application-supplied callback; doing so returns an error. You have to use the audio callback, or dequeue audio with this function, but not both.
You should not call SDL_LockAudio() on the device before queueing; SDL handles locking internally for this function.
dev | The device ID from which we will dequeue audio. |
data | A pointer into where audio data should be copied. |
len | The number of bytes (not samples!) to which (data) points. |
Definition at line 580 of file SDL_audio.c.
References SDL_AudioDevice::buffer_queue, SDL_AudioSpec::callback, SDL_AudioDevice::callbackspec, device, get_audio_device(), SDL_AudioDriver::impl, SDL_AudioDevice::iscapture, SDL_AudioDriverImpl::LockDevice, SDL_BufferQueueFillCallback(), SDL_ReadFromDataQueue(), and SDL_AudioDriverImpl::UnlockDevice.
SDL_AudioFormat SDL_FirstAudioFormat | ( | SDL_AudioFormat | format | ) |
Definition at line 1584 of file SDL_audio.c.
References format_idx, format_idx_sub, format_list, NUM_FORMATS, and SDL_NextAudioFormat().
const char* SDL_GetAudioDeviceName | ( | int | index, |
int | iscapture | ||
) |
Get the human-readable name of a specific audio device. Must be a value between 0 and (number of audio devices-1). Only valid after a successfully initializing the audio subsystem. The values returned by this function reflect the latest call to SDL_GetNumAudioDevices(); recall that function to redetect available hardware.
The string returned by this function is UTF-8 encoded, read-only, and managed internally. You are not to free it. If you need to keep the string for any length of time, you should make your own copy of it, as it will be invalid next time any of several other SDL functions is called.
Definition at line 1011 of file SDL_audio.c.
References SDL_AudioDriver::detectionLock, SDL_AudioDriverImpl::HasCaptureSupport, i, SDL_AudioDriver::impl, SDL_AudioDriver::inputDeviceCount, SDL_AudioDriver::inputDevices, SDL_AudioDeviceItem::next, NULL, SDL_AudioDriver::outputDeviceCount, SDL_AudioDriver::outputDevices, retval, SDL_assert, SDL_INIT_AUDIO, SDL_LockMutex, SDL_SetError, SDL_UnlockMutex, and SDL_WasInit.
SDL_AudioStatus SDL_GetAudioDeviceStatus | ( | SDL_AudioDeviceID | devid | ) |
Definition at line 1443 of file SDL_audio.c.
References device, SDL_AudioDevice::enabled, get_audio_device(), SDL_AudioDevice::paused, SDL_AtomicGet, SDL_AUDIO_PAUSED, SDL_AUDIO_PLAYING, and SDL_AUDIO_STOPPED.
Referenced by SDL_GetAudioStatus().
const char* SDL_GetAudioDriver | ( | int | index | ) |
Definition at line 876 of file SDL_audio.c.
References AudioBootStrap::name, NULL, and SDL_GetNumAudioDrivers().
SDL_AudioStatus SDL_GetAudioStatus | ( | void | ) |
Definition at line 1459 of file SDL_audio.c.
References SDL_GetAudioDeviceStatus().
const char* SDL_GetCurrentAudioDriver | ( | void | ) |
This function returns the name of the current audio driver, or NULL if no driver has been initialized.
Definition at line 950 of file SDL_audio.c.
References SDL_AudioDriver::name.
int SDL_GetNumAudioDevices | ( | int | iscapture | ) |
Get the number of available devices exposed by the current driver. Only valid after a successfully initializing the audio subsystem. Returns -1 if an explicit list of devices can't be determined; this is not an error. For example, if SDL is set up to talk to a remote audio server, it can't list every one available on the Internet, but it will still allow a specific host to be specified to SDL_OpenAudioDevice().
In many common cases, when this function returns a value <= 0, it can still successfully open the default device (NULL for first argument of SDL_OpenAudioDevice()).
Definition at line 985 of file SDL_audio.c.
References SDL_AudioDriver::captureDevicesRemoved, clean_out_device_list(), SDL_AudioDriver::detectionLock, SDL_AudioDriver::inputDeviceCount, SDL_AudioDriver::inputDevices, SDL_AudioDriver::outputDeviceCount, SDL_AudioDriver::outputDevices, SDL_AudioDriver::outputDevicesRemoved, retval, SDL_FALSE, SDL_INIT_AUDIO, SDL_LockMutex, SDL_UnlockMutex, and SDL_WasInit.
int SDL_GetNumAudioDrivers | ( | void | ) |
Definition at line 870 of file SDL_audio.c.
References SDL_arraysize.
Referenced by SDL_GetAudioDriver().
Uint32 SDL_GetQueuedAudioSize | ( | SDL_AudioDeviceID | dev | ) |
Get the number of bytes of still-queued audio.
For playback device:
This is the number of bytes that have been queued for playback with SDL_QueueAudio(), but have not yet been sent to the hardware. This number may shrink at any time, so this only informs of pending data.
Once we've sent it to the hardware, this function can not decide the exact byte boundary of what has been played. It's possible that we just gave the hardware several kilobytes right before you called this function, but it hasn't played any of it yet, or maybe half of it, etc.
For capture devices:
This is the number of bytes that have been captured by the device and are waiting for you to dequeue. This number may grow at any time, so this only informs of the lower-bound of available data.
You may not queue audio on a device that is using an application-supplied callback; calling this function on such a device always returns 0. You have to queue audio with SDL_QueueAudio()/SDL_DequeueAudio(), or use the audio callback, but not both.
You should not call SDL_LockAudio() on the device before querying; SDL handles locking internally for this function.
dev | The device ID of which we will query queued audio size. |
Definition at line 599 of file SDL_audio.c.
References SDL_AudioDevice::buffer_queue, SDL_AudioSpec::callback, SDL_AudioDevice::callbackspec, device, get_audio_device(), SDL_AudioDriverImpl::GetPendingBytes, SDL_AudioDriver::impl, SDL_AudioDriverImpl::LockDevice, retval, SDL_BufferQueueDrainCallback(), SDL_BufferQueueFillCallback(), SDL_CountDataQueue(), and SDL_AudioDriverImpl::UnlockDevice.
void SDL_LockAudioDevice | ( | SDL_AudioDeviceID | devid | ) |
Definition at line 1483 of file SDL_audio.c.
References device, get_audio_device(), SDL_AudioDriver::impl, and SDL_AudioDriverImpl::LockDevice.
Referenced by SDL_LockAudio().
This takes two audio buffers of the playing audio format and mixes them, performing addition, volume adjustment, and overflow clipping. The volume ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME for full audio volume. Note this does not change hardware volume. This is provided for convenience – you can mix your own audio data.
Definition at line 1626 of file SDL_audio.c.
References SDL_AudioDevice::callbackspec, device, SDL_AudioSpec::format, get_audio_device(), NULL, and SDL_MixAudioFormat.
SDL_AudioFormat SDL_NextAudioFormat | ( | void | ) |
Definition at line 1596 of file SDL_audio.c.
References format_idx, format_idx_sub, format_list, and NUM_FORMATS.
Referenced by SDL_FirstAudioFormat().
int SDL_OpenAudio | ( | SDL_AudioSpec * | desired, |
SDL_AudioSpec * | obtained | ||
) |
This function opens the audio device with the desired parameters, and returns 0 if successful, placing the actual hardware parameters in the structure pointed to by obtained
. If obtained
is NULL, the audio data passed to the callback function will be guaranteed to be in the requested format, and will be automatically converted to the hardware audio format if necessary. This function returns -1 if it failed to open the audio device, or couldn't set up the audio thread.
When filling in the desired audio spec structure,
desired->freq
should be the desired audio frequency in samples-per- second.desired->format
should be the desired audio format.desired->samples
is the desired size of the audio buffer, in samples. This number should be a power of two, and may be adjusted by the audio driver to a value more suitable for the hardware. Good values seem to range between 512 and 8096 inclusive, depending on the application and CPU speed. Smaller values yield faster response time, but can lead to underflow if the application is doing heavy processing and cannot fill the audio buffer in time. A stereo sample consists of both right and left channels in LR ordering. Note that the number of samples is directly related to time by the following formula:desired->size
is the size in bytes of the audio buffer, and is calculated by SDL_OpenAudio().desired->silence
is the value used to set the buffer to silence, and is calculated by SDL_OpenAudio().desired->callback
should be set to a function that will be called when the audio device is ready for more data. It is passed a pointer to the audio buffer, and the length in bytes of the audio buffer. This function usually runs in a separate thread, and so you should protect data structures that it accesses by calling SDL_LockAudio() and SDL_UnlockAudio() in your code. 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).desired->userdata
is passed as the first parameter to your callback function. If you passed a NULL callback, this value is ignored.The audio device starts out playing silence when it's opened, and should be enabled for playing by calling SDL_PauseAudio(0)
when you are ready for your audio callback function to be called. Since the audio driver may modify the requested size of the audio buffer, you should allocate any local mixing buffers after you open the audio device.
Definition at line 1398 of file SDL_audio.c.
References NULL, open_audio_device(), SDL_assert, SDL_AUDIO_ALLOW_ANY_CHANGE, SDL_INIT_AUDIO, SDL_InitSubSystem, SDL_SetError, SDL_WasInit, SDL_zero, SDL_AudioSpec::silence, and SDL_AudioSpec::size.
SDL_AudioDeviceID SDL_OpenAudioDevice | ( | const char * | device, |
int | iscapture, | ||
const SDL_AudioSpec * | desired, | ||
SDL_AudioSpec * | obtained, | ||
int | allowed_changes | ||
) |
Open a specific audio device. Passing in a device name of NULL requests the most reasonable default (and is equivalent to calling SDL_OpenAudio()).
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.
SDL_OpenAudio(), unlike this function, always acts on device ID 1.
Definition at line 1434 of file SDL_audio.c.
References open_audio_device().
void SDL_OpenedAudioDeviceDisconnected | ( | SDL_AudioDevice * | device | ) |
Definition at line 449 of file SDL_audio.c.
References SDL_AudioDevice::enabled, get_audio_device(), SDL_AudioDevice::id, SDL_AudioDriver::impl, SDL_AudioDevice::iscapture, SDL_AudioDriverImpl::LockDevice, SDL_assert, SDL_AtomicGet, SDL_AtomicSet, SDL_AUDIODEVICEREMOVED, SDL_ENABLE, SDL_GetEventState, SDL_PushEvent, SDL_zero, and SDL_AudioDriverImpl::UnlockDevice.
Referenced by SDL_CaptureAudio(), and SDL_RemoveAudioDevice().
|
static |
Definition at line 844 of file SDL_audio.c.
References CHECK_FMT_STRING, and S32.
Referenced by prepare_audiospec().
void SDL_PauseAudio | ( | int | pause_on | ) |
Definition at line 1476 of file SDL_audio.c.
References SDL_PauseAudioDevice().
void SDL_PauseAudioDevice | ( | SDL_AudioDeviceID | devid, |
int | pause_on | ||
) |
Definition at line 1465 of file SDL_audio.c.
References device, get_audio_device(), SDL_AudioDriver::impl, SDL_AudioDriverImpl::LockDevice, SDL_AudioDevice::paused, SDL_AtomicSet, and SDL_AudioDriverImpl::UnlockDevice.
Referenced by SDL_PauseAudio().
int SDL_QueueAudio | ( | SDL_AudioDeviceID | dev, |
const void * | data, | ||
Uint32 | len | ||
) |
Queue more audio on non-callback devices.
(If you are looking to retrieve queued audio from a non-callback capture device, you want SDL_DequeueAudio() instead. This will return -1 to signify an error if you use it with capture devices.)
SDL offers two ways to feed audio to the device: you can either supply a callback that SDL triggers with some frequency to obtain more audio (pull method), or you can supply no callback, and then SDL will expect you to supply data at regular intervals (push method) with this function.
There are no limits on the amount of data you can queue, short of exhaustion of address space. Queued data will drain to the device as necessary without further intervention from you. If the device needs audio but there is not enough queued, it will play silence to make up the difference. This means you will have skips in your audio playback if you aren't routinely queueing sufficient data.
This function copies the supplied data, so you are safe to free it when the function returns. This function is thread-safe, but queueing to the same device from two threads at once does not promise which buffer will be queued first.
You may not queue audio on a device that is using an application-supplied callback; doing so returns an error. You have to use the audio callback or queue audio with this function, but not both.
You should not call SDL_LockAudio() on the device before queueing; SDL handles locking internally for this function.
dev | The device ID to which we will queue audio. |
data | The data to queue to the device for later playback. |
len | The number of bytes (not samples!) to which (data) points. |
Definition at line 557 of file SDL_audio.c.
References SDL_AudioDevice::buffer_queue, SDL_AudioSpec::callback, SDL_AudioDevice::callbackspec, device, get_audio_device(), SDL_AudioDriver::impl, SDL_AudioDevice::iscapture, SDL_AudioDriverImpl::LockDevice, SDL_BufferQueueDrainCallback(), SDL_SetError, SDL_WriteToDataQueue(), and SDL_AudioDriverImpl::UnlockDevice.
Definition at line 490 of file SDL_audio.c.
References SDL_AudioDriver::captureDevicesRemoved, SDL_AudioDriver::detectionLock, device, SDL_AudioDriverImpl::FreeDeviceHandle, SDL_AudioDevice::handle, SDL_AudioDriver::impl, SDL_AudioDriver::inputDevices, mark_device_removed(), NULL, SDL_AudioDriver::outputDevices, SDL_AudioDriver::outputDevicesRemoved, SDL_arraysize, SDL_LockMutex, SDL_OpenedAudioDeviceDisconnected(), SDL_UnlockMutex, and SDLCALL.
|
static |
Definition at line 643 of file SDL_audio.c.
References SDL_AudioDriverImpl::BeginLoopIteration, callback(), SDL_AudioSpec::callback, SDL_AudioDevice::callbackspec, device, SDL_AudioDevice::enabled, SDL_AudioSpec::freq, SDL_AudioDriverImpl::GetDeviceBuf, SDL_AudioDriver::impl, SDL_AudioDevice::iscapture, SDL_AudioDevice::mixer_lock, NULL, SDL_AudioDevice::paused, SDL_AudioDriverImpl::PlayDevice, SDL_AudioDriverImpl::PrepareToClose, SDL_AudioSpec::samples, SDL_assert, SDL_AtomicGet, SDL_AudioStreamAvailable, SDL_AudioStreamGet, SDL_AudioStreamPut, SDL_Delay, SDL_LockMutex, SDL_memset, SDL_SetThreadPriority, SDL_THREAD_PRIORITY_HIGH, SDL_ThreadID, SDL_UnlockMutex, SDLCALL, SDL_AudioDevice::shutdown, SDL_AudioSpec::silence, SDL_AudioSpec::size, SDL_AudioDevice::spec, SDL_AudioDevice::stream, SDL_AudioDriverImpl::ThreadDeinit, SDL_AudioDevice::threadid, SDL_AudioDriverImpl::ThreadInit, SDL_AudioSpec::userdata, SDL_AudioDriverImpl::WaitDevice, and SDL_AudioDevice::work_buffer.
Referenced by open_audio_device().
Definition at line 1509 of file SDL_audio.c.
References SDL_UnlockAudioDevice().
void SDL_UnlockAudioDevice | ( | SDL_AudioDeviceID | devid | ) |
Definition at line 1499 of file SDL_audio.c.
References device, get_audio_device(), SDL_AudioDriver::impl, and SDL_AudioDriverImpl::UnlockDevice.
Referenced by SDL_UnlockAudio().
|
static |
Definition at line 37 of file SDL_audio.c.
|
static |
Definition at line 33 of file SDL_audio.c.
|
static |
Definition at line 1558 of file SDL_audio.c.
Referenced by SDL_FirstAudioFormat(), and SDL_NextAudioFormat().
|
static |
Definition at line 1559 of file SDL_audio.c.
Referenced by SDL_FirstAudioFormat(), and SDL_NextAudioFormat().
|
static |
Definition at line 1560 of file SDL_audio.c.
Referenced by SDL_FirstAudioFormat(), and SDL_NextAudioFormat().
|
static |
Definition at line 34 of file SDL_audio.c.