Skip to content

Commit

Permalink
audio: Added SDL_AudioDeviceStreamPaused.
Browse files Browse the repository at this point in the history
We had the other two wrapper functions to pause and resume, and forgot query.
  • Loading branch information
icculus committed Jan 9, 2025
1 parent f61860f commit 3f7f632
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
19 changes: 19 additions & 0 deletions include/SDL3/SDL_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
10 changes: 10 additions & 0 deletions src/audio/SDL_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi.sym
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi_overrides.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions src/dynapi/SDL_dynapi_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion test/testaudiorecording.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3f7f632

Please sign in to comment.