Skip to content

Commit 3f7f632

Browse files
committed
audio: Added SDL_AudioDeviceStreamPaused.
We had the other two wrapper functions to pause and resume, and forgot query.
1 parent f61860f commit 3f7f632

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

include/SDL3/SDL_audio.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,25 @@ extern SDL_DECLSPEC bool SDLCALL SDL_PauseAudioStreamDevice(SDL_AudioStream *str
15771577
*/
15781578
extern SDL_DECLSPEC bool SDLCALL SDL_ResumeAudioStreamDevice(SDL_AudioStream *stream);
15791579

1580+
/**
1581+
* Use this function to query if an audio device associated with a stream is paused.
1582+
*
1583+
* Unlike in SDL2, audio devices start in an _unpaused_ state, since an app
1584+
* has to bind a stream before any audio will flow.
1585+
*
1586+
* \param stream the audio stream associated with the audio device to query.
1587+
* \returns true if device is valid and paused, false otherwise.
1588+
*
1589+
* \threadsafety It is safe to call this function from any thread.
1590+
*
1591+
* \since This function is available since SDL 3.1.3.
1592+
*
1593+
* \sa SDL_PauseAudioStreamDevice
1594+
* \sa SDL_ResumeAudioStreamDevice
1595+
*/
1596+
extern SDL_DECLSPEC bool SDLCALL SDL_AudioStreamDevicePaused(SDL_AudioStream *stream);
1597+
1598+
15801599
/**
15811600
* Lock an audio stream for serialized access.
15821601
*

src/audio/SDL_audio.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,16 @@ bool SDL_ResumeAudioStreamDevice(SDL_AudioStream *stream)
21302130
return SDL_ResumeAudioDevice(devid);
21312131
}
21322132

2133+
bool SDL_AudioStreamDevicePaused(SDL_AudioStream *stream)
2134+
{
2135+
SDL_AudioDeviceID devid = SDL_GetAudioStreamDevice(stream);
2136+
if (!devid) {
2137+
return false;
2138+
}
2139+
2140+
return SDL_AudioDevicePaused(devid);
2141+
}
2142+
21332143
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
21342144
#define NATIVE(type) SDL_AUDIO_##type##LE
21352145
#define SWAPPED(type) SDL_AUDIO_##type##BE

src/dynapi/SDL_dynapi.sym

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,7 @@ SDL3_0.0.0 {
12301230
SDL_GetTrayMenuParentEntry;
12311231
SDL_GetTrayMenuParentTray;
12321232
SDL_GetThreadState;
1233+
SDL_AudioStreamDevicePaused;
12331234
# extra symbols go here (don't modify this line)
12341235
local: *;
12351236
};

src/dynapi/SDL_dynapi_overrides.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,3 +1255,4 @@
12551255
#define SDL_GetTrayMenuParentEntry SDL_GetTrayMenuParentEntry_REAL
12561256
#define SDL_GetTrayMenuParentTray SDL_GetTrayMenuParentTray_REAL
12571257
#define SDL_GetThreadState SDL_GetThreadState_REAL
1258+
#define SDL_AudioStreamDevicePaused SDL_AudioStreamDevicePaused_REAL

src/dynapi/SDL_dynapi_procs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,3 +1263,4 @@ SDL_DYNAPI_PROC(SDL_TrayMenu*,SDL_GetTrayEntryParent,(SDL_TrayEntry *a),(a),retu
12631263
SDL_DYNAPI_PROC(SDL_TrayEntry*,SDL_GetTrayMenuParentEntry,(SDL_TrayMenu *a),(a),return)
12641264
SDL_DYNAPI_PROC(SDL_Tray*,SDL_GetTrayMenuParentTray,(SDL_TrayMenu *a),(a),return)
12651265
SDL_DYNAPI_PROC(SDL_ThreadState,SDL_GetThreadState,(SDL_Thread *a),(a),return)
1266+
SDL_DYNAPI_PROC(bool,SDL_AudioStreamDevicePaused,(SDL_AudioStream *a),(a),return)

test/testaudiorecording.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
172172

173173
SDL_AppResult SDL_AppIterate(void *appstate)
174174
{
175-
if (!SDL_AudioDevicePaused(SDL_GetAudioStreamDevice(stream_in))) {
175+
if (!SDL_AudioStreamDevicePaused(stream_in)) {
176176
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
177177
} else {
178178
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);

0 commit comments

Comments
 (0)