From 8d4ed49501bea2a40aa8a4f936a65949c8f7a126 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 16 Jan 2022 21:52:59 +0200 Subject: [PATCH 43/44] Add pause and resume functionality to audio API See osdn #43550 Signed-off-by: Marko Lindqvist --- client/audio.c | 16 ++++++++++++++++ client/audio.h | 6 ++++++ client/audio_none.c | 18 ++++++++++++++++++ client/audio_sdl.c | 18 ++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/client/audio.c b/client/audio.c index acfe5f029e..5a50bb9cd0 100644 --- a/client/audio.c +++ b/client/audio.c @@ -582,6 +582,22 @@ void audio_play_track(const char *const tag, char *const alt_tag) real_audio_play_music(tag, alt_tag, TRUE); } +/**********************************************************************//** + Pause sound. +**************************************************************************/ +void audio_pause(void) +{ + plugins[selected_plugin].pause(); +} + +/**********************************************************************//** + Resume sound. +**************************************************************************/ +void audio_resume(void) +{ + plugins[selected_plugin].resume(); +} + /**********************************************************************//** Stop sound. Music should die down in a few seconds. **************************************************************************/ diff --git a/client/audio.h b/client/audio.h index 8588bb9b02..102f066d4e 100644 --- a/client/audio.h +++ b/client/audio.h @@ -17,6 +17,7 @@ extern "C" { #endif /* __cplusplus */ +/* utility */ #include "support.h" /* bool type */ #define MAX_AUDIO_NAME_LEN 20 @@ -37,6 +38,8 @@ struct audio_plugin { void (*set_volume) (double volume); bool (*play) (const char *const tag, const char *const path, bool repeat, audio_finished_callback cb); + void (*pause)(void); + void (*resume)(void); }; enum music_usage { MU_MENU, MU_INGAME }; @@ -57,6 +60,9 @@ void audio_stop(void); void audio_stop_usage(void); void audio_restart(const char *soundset_name, const char *musicset_name); +void audio_pause(void); +void audio_resume(void); + void audio_play_sound(const char *const tag, const char *const alt_tag); void audio_play_music(const char *const tag, char *const alt_tag, enum music_usage usage); diff --git a/client/audio_none.c b/client/audio_none.c index b8a9a4c017..30ad9740aa 100644 --- a/client/audio_none.c +++ b/client/audio_none.c @@ -17,8 +17,10 @@ #include +/* utility */ #include "support.h" +/* client */ #include "audio.h" #include "gui_main_g.h" @@ -58,6 +60,20 @@ static bool none_audio_play(const char *const tag, const char *const fullpath, return FALSE; } +/**********************************************************************//** + Pause audio +**************************************************************************/ +static void none_audio_pause(void) +{ +} + +/**********************************************************************//** + Resume audio +**************************************************************************/ +static void none_audio_resume(void) +{ +} + /**********************************************************************//** Initialize. **************************************************************************/ @@ -80,5 +96,7 @@ void audio_none_init(void) self.stop = none_audio_stop; self.wait = none_audio_wait; self.play = none_audio_play; + self.pause = none_audio_pause; + self.resume = none_audio_resume; audio_add_plugin(&self); } diff --git a/client/audio_sdl.c b/client/audio_sdl.c index 32af02c66e..47c6cc9d00 100644 --- a/client/audio_sdl.c +++ b/client/audio_sdl.c @@ -144,6 +144,22 @@ static bool sdl_audio_play(const char *const tag, const char *const fullpath, return TRUE; } +/**********************************************************************//** + Pause music +**************************************************************************/ +static void sdl_audio_pause(void) +{ + Mix_PauseMusic(); +} + +/**********************************************************************//** + Resume music +**************************************************************************/ +static void sdl_audio_resume(void) +{ + Mix_ResumeMusic(); +} + /**********************************************************************//** Stop music **************************************************************************/ @@ -264,6 +280,8 @@ void audio_sdl_init(void) self.stop = sdl_audio_stop; self.wait = sdl_audio_wait; self.play = sdl_audio_play; + self.pause = sdl_audio_pause; + self.resume = sdl_audio_resume; self.set_volume = sdl_audio_set_volume; self.get_volume = sdl_audio_get_volume; audio_add_plugin(&self); -- 2.34.1