Parcourir la source

audio: Added SDL_AudioDeviceStreamPaused.

We had the other two wrapper functions to pause and resume, and forgot query.
Ryan C. Gordon il y a 3 mois
Parent
commit
3f7f632e14

+ 19 - 0
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.
  *

+ 10 - 0
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

+ 1 - 0
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: *;
 };

+ 1 - 0
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

+ 1 - 0
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)

+ 1 - 1
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);