diff --git a/frontend/frontend.c b/frontend/frontend.c index 68a8c94cf5..d9a5d4a68b 100644 --- a/frontend/frontend.c +++ b/frontend/frontend.c @@ -159,8 +159,7 @@ static int main_entry_iterate_menu_preinit(args_type() args) key_event = g_extern.system.key_event; g_extern.system.key_event = menu_key_event; - if (driver.audio_data) - audio_stop_func(); + rarch_main_command(RARCH_CMD_AUDIO_STOP); driver.menu->need_refresh = true; driver.menu->old_input_state |= 1ULL << RARCH_MENU_TOGGLE; @@ -183,11 +182,7 @@ static int main_entry_iterate_menu(args_type() args) g_extern.lifecycle_state &= ~(1ULL << MODE_MENU); driver_set_nonblock_state(driver.nonblock_state); - if (driver.audio_data && !g_extern.audio_data.mute && !audio_start_func()) - { - RARCH_ERR("Failed to resume audio driver. Will continue without audio.\n"); - g_extern.audio_active = false; - } + rarch_main_command(RARCH_CMD_AUDIO_START); g_extern.lifecycle_state |= (1ULL << MODE_CLEAR_INPUT); diff --git a/general.h b/general.h index 48e500d594..25b4394e61 100644 --- a/general.h +++ b/general.h @@ -102,6 +102,8 @@ enum basic_event RARCH_CMD_REINIT, RARCH_CMD_REWIND, RARCH_CMD_AUTOSAVE, + RARCH_CMD_AUDIO_STOP, + RARCH_CMD_AUDIO_START, }; enum menu_enums diff --git a/retroarch.c b/retroarch.c index 9454738fae..b6b85d364d 100644 --- a/retroarch.c +++ b/retroarch.c @@ -2301,10 +2301,12 @@ static void check_movie(void) static void check_pause(void) { - static bool old_state = false; - static bool old_focus = true; - bool focus = true; - bool new_state = input_key_pressed_func(RARCH_PAUSE_TOGGLE); + static bool old_state = false; + static bool old_focus = true; + bool focus = true; + bool has_set_audio_stop = false; + bool has_set_audio_start = false; + bool new_state = input_key_pressed_func(RARCH_PAUSE_TOGGLE); // FRAMEADVANCE will set us into pause mode. new_state |= !g_extern.is_paused && input_key_pressed_func(RARCH_FRAMEADVANCE); @@ -2319,40 +2321,32 @@ static void check_pause(void) if (g_extern.is_paused) { RARCH_LOG("Paused.\n"); - if (driver.audio_data) - audio_stop_func(); + has_set_audio_stop = true; } else { RARCH_LOG("Unpaused.\n"); - if (driver.audio_data) - { - if (!g_extern.audio_data.mute && !audio_start_func()) - { - RARCH_ERR("Failed to resume audio driver. Will continue without audio.\n"); - g_extern.audio_active = false; - } - } + has_set_audio_start = true; } } else if (focus && !old_focus) { RARCH_LOG("Unpaused.\n"); - g_extern.is_paused = false; - if (driver.audio_data && !g_extern.audio_data.mute && !audio_start_func()) - { - RARCH_ERR("Failed to resume audio driver. Will continue without audio.\n"); - g_extern.audio_active = false; - } + g_extern.is_paused = false; + has_set_audio_start = true; } else if (!focus && old_focus) { RARCH_LOG("Paused.\n"); g_extern.is_paused = true; - if (driver.audio_data) - audio_stop_func(); + has_set_audio_stop = true; } + if (has_set_audio_stop) + rarch_main_command(RARCH_CMD_AUDIO_STOP); + if (has_set_audio_start) + rarch_main_command(RARCH_CMD_AUDIO_START); + old_focus = focus; old_state = new_state; } @@ -3206,6 +3200,17 @@ void rarch_main_command(unsigned action) init_autosave(); #endif break; + case RARCH_CMD_AUDIO_STOP: + if (driver.audio_data) + audio_stop_func(); + break; + case RARCH_CMD_AUDIO_START: + if (driver.audio_data && !g_extern.audio_data.mute && !audio_start_func()) + { + RARCH_ERR("Failed to start audio driver. Will continue without audio.\n"); + g_extern.audio_active = false; + } + break; } }