mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 18:40:49 +00:00
Refactor audio stop/start
This commit is contained in:
parent
c3c0341f8c
commit
53ae4cd72c
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
49
retroarch.c
49
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user