From 3f7f632e143673e955215802601c29a02d6cf076 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 9 Jan 2025 01:36:57 -0500 Subject: [PATCH] audio: Added SDL_AudioDeviceStreamPaused. We had the other two wrapper functions to pause and resume, and forgot query. --- include/SDL3/SDL_audio.h | 19 +++++++++++++++++++ src/audio/SDL_audio.c | 10 ++++++++++ src/dynapi/SDL_dynapi.sym | 1 + src/dynapi/SDL_dynapi_overrides.h | 1 + src/dynapi/SDL_dynapi_procs.h | 1 + test/testaudiorecording.c | 2 +- 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/SDL3/SDL_audio.h b/include/SDL3/SDL_audio.h index 7eefaf2943..4c8fbec9bb 100644 --- a/include/SDL3/SDL_audio.h +++ b/include/SDL3/SDL_audio.h @@ -1577,6 +1577,25 @@ extern SDL_DECLSPEC bool SDLCALL SDL_PauseAudioStreamDevice(SDL_AudioStream *str */ extern SDL_DECLSPEC bool SDLCALL SDL_ResumeAudioStreamDevice(SDL_AudioStream *stream); +/** + * Use this function to query if an audio device associated with a stream is paused. + * + * Unlike in SDL2, audio devices start in an _unpaused_ state, since an app + * has to bind a stream before any audio will flow. + * + * \param stream the audio stream associated with the audio device to query. + * \returns true if device is valid and paused, false otherwise. + * + * \threadsafety It is safe to call this function from any thread. + * + * \since This function is available since SDL 3.1.3. + * + * \sa SDL_PauseAudioStreamDevice + * \sa SDL_ResumeAudioStreamDevice + */ +extern SDL_DECLSPEC bool SDLCALL SDL_AudioStreamDevicePaused(SDL_AudioStream *stream); + + /** * Lock an audio stream for serialized access. * diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 4380986d6d..bc1704b60e 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -2130,6 +2130,16 @@ bool SDL_ResumeAudioStreamDevice(SDL_AudioStream *stream) return SDL_ResumeAudioDevice(devid); } +bool SDL_AudioStreamDevicePaused(SDL_AudioStream *stream) +{ + SDL_AudioDeviceID devid = SDL_GetAudioStreamDevice(stream); + if (!devid) { + return false; + } + + return SDL_AudioDevicePaused(devid); +} + #if SDL_BYTEORDER == SDL_LIL_ENDIAN #define NATIVE(type) SDL_AUDIO_##type##LE #define SWAPPED(type) SDL_AUDIO_##type##BE diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym index 36e19c606f..db3718e694 100644 --- a/src/dynapi/SDL_dynapi.sym +++ b/src/dynapi/SDL_dynapi.sym @@ -1230,6 +1230,7 @@ SDL3_0.0.0 { SDL_GetTrayMenuParentEntry; SDL_GetTrayMenuParentTray; SDL_GetThreadState; + SDL_AudioStreamDevicePaused; # extra symbols go here (don't modify this line) local: *; }; diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index e1d7a13d70..bf42c0f7b2 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -1255,3 +1255,4 @@ #define SDL_GetTrayMenuParentEntry SDL_GetTrayMenuParentEntry_REAL #define SDL_GetTrayMenuParentTray SDL_GetTrayMenuParentTray_REAL #define SDL_GetThreadState SDL_GetThreadState_REAL +#define SDL_AudioStreamDevicePaused SDL_AudioStreamDevicePaused_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 648621d0b3..74da2a73c2 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -1263,3 +1263,4 @@ SDL_DYNAPI_PROC(SDL_TrayMenu*,SDL_GetTrayEntryParent,(SDL_TrayEntry *a),(a),retu SDL_DYNAPI_PROC(SDL_TrayEntry*,SDL_GetTrayMenuParentEntry,(SDL_TrayMenu *a),(a),return) SDL_DYNAPI_PROC(SDL_Tray*,SDL_GetTrayMenuParentTray,(SDL_TrayMenu *a),(a),return) SDL_DYNAPI_PROC(SDL_ThreadState,SDL_GetThreadState,(SDL_Thread *a),(a),return) +SDL_DYNAPI_PROC(bool,SDL_AudioStreamDevicePaused,(SDL_AudioStream *a),(a),return) diff --git a/test/testaudiorecording.c b/test/testaudiorecording.c index efc8550b8d..88cbc73d54 100644 --- a/test/testaudiorecording.c +++ b/test/testaudiorecording.c @@ -172,7 +172,7 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) SDL_AppResult SDL_AppIterate(void *appstate) { - if (!SDL_AudioDevicePaused(SDL_GetAudioStreamDevice(stream_in))) { + if (!SDL_AudioStreamDevicePaused(stream_in)) { SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); } else { SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);