mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-23 15:56:00 +00:00
audio: Readded (logical) device pausing.
This commit is contained in:
@@ -603,7 +603,12 @@ SDL_bool SDL_OutputAudioThreadIterate(SDL_AudioDevice *device)
|
||||
} else {
|
||||
SDL_assert(buffer_size <= device->buffer_size); // you can ask for less, but not more.
|
||||
SDL_memset(mix_buffer, device->silence_value, buffer_size); // start with silence.
|
||||
|
||||
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev != NULL; logdev = logdev->next) {
|
||||
if (SDL_AtomicGet(&logdev->paused)) {
|
||||
continue; // paused? Skip this logical device.
|
||||
}
|
||||
|
||||
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = stream->next_binding) {
|
||||
/* this will hold a lock on `stream` while getting. We don't explicitly lock the streams
|
||||
for iterating here because the binding linked list can only change while the device lock is held.
|
||||
@@ -1165,6 +1170,41 @@ SDL_AudioDeviceID SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSp
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int SetLogicalAudioDevicePauseState(SDL_AudioDeviceID devid, int value)
|
||||
{
|
||||
SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(devid);
|
||||
if (!logdev) {
|
||||
return -1; // ObtainLogicalAudioDevice will have set an error.
|
||||
}
|
||||
SDL_AtomicSet(&logdev->paused, value);
|
||||
SDL_UnlockMutex(logdev->physical_device->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDL_PauseAudioDevice(SDL_AudioDeviceID devid)
|
||||
{
|
||||
return SetLogicalAudioDevicePauseState(devid, 1);
|
||||
}
|
||||
|
||||
int SDLCALL SDL_UnpauseAudioDevice(SDL_AudioDeviceID devid)
|
||||
{
|
||||
return SetLogicalAudioDevicePauseState(devid, 0);
|
||||
}
|
||||
|
||||
SDL_bool SDL_IsAudioDevicePaused(SDL_AudioDeviceID devid)
|
||||
{
|
||||
SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(devid);
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
if (logdev) {
|
||||
if (SDL_AtomicGet(&logdev->paused)) {
|
||||
retval = SDL_TRUE;
|
||||
}
|
||||
SDL_UnlockMutex(logdev->physical_device->lock);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int num_streams)
|
||||
{
|
||||
const SDL_bool islogical = (devid & (1<<1)) ? SDL_FALSE : SDL_TRUE;
|
||||
|
||||
@@ -885,6 +885,9 @@ SDL3_0.0.0 {
|
||||
SDL_ConvertAudioSamples;
|
||||
SDL_GetSilenceValueForFormat;
|
||||
SDL_LoadWAV;
|
||||
SDL_PauseAudioDevice;
|
||||
SDL_UnpauseAudioDevice;
|
||||
SDL_IsAudioDevicePaused;
|
||||
# extra symbols go here (don't modify this line)
|
||||
local: *;
|
||||
};
|
||||
|
||||
@@ -911,3 +911,6 @@
|
||||
#define SDL_ConvertAudioSamples SDL_ConvertAudioSamples_REAL
|
||||
#define SDL_GetSilenceValueForFormat SDL_GetSilenceValueForFormat_REAL
|
||||
#define SDL_LoadWAV SDL_LoadWAV_REAL
|
||||
#define SDL_PauseAudioDevice SDL_PauseAudioDevice_REAL
|
||||
#define SDL_UnpauseAudioDevice SDL_UnpauseAudioDevice_REAL
|
||||
#define SDL_IsAudioDevicePaused SDL_IsAudioDevicePaused_REAL
|
||||
|
||||
@@ -955,3 +955,6 @@ SDL_DYNAPI_PROC(int,SDL_MixAudioFormat,(Uint8 *a, const Uint8 *b, SDL_AudioForma
|
||||
SDL_DYNAPI_PROC(int,SDL_ConvertAudioSamples,(const SDL_AudioSpec *a, const Uint8 *b, int c, const SDL_AudioSpec *d, Uint8 **e, int *f),(a,b,c,d,e,f),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetSilenceValueForFormat,(SDL_AudioFormat a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_LoadWAV,(const char *a, SDL_AudioSpec *b, Uint8 **c, Uint32 *d),(a,b,c,d),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_PauseAudioDevice,(SDL_AudioDeviceID a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_UnpauseAudioDevice,(SDL_AudioDeviceID a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_bool,SDL_IsAudioDevicePaused,(SDL_AudioDeviceID a),(a),return)
|
||||
|
||||
Reference in New Issue
Block a user