Bring back audio toggling on menu toggle (#16467)

This commit is contained in:
sonninnos 2024-04-25 20:10:39 +03:00 committed by GitHub
parent 70ac6d9541
commit 5e79dd4569
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 64 additions and 39 deletions

View file

@ -395,23 +395,10 @@ static bool wasapi_alive(void *wh)
return w->running;
}
static void wasapi_insert_silence(wasapi_t *w)
{
int i;
for (i = 0; i < 12; i++)
audio_driver_menu_sample();
}
static void wasapi_set_nonblock_state(void *wh, bool nonblock)
{
wasapi_t *w = (wasapi_t*)wh;
/* Since exclusive mode keeps repeating last sample while
* in paused menu, generate some silence first. */
if (!nonblock && w->exclusive)
wasapi_insert_silence(w);
w->nonblock = nonblock;
}

View file

@ -6263,7 +6263,8 @@ void menu_driver_toggle(
* struct is NULL
*/
video_driver_t *current_video = (video_driver_t*)curr_video_data;
bool pause_libretro = false;
bool menu_pause_libretro = false;
bool audio_enable_menu = false;
runloop_state_t *runloop_st = runloop_state_get_ptr();
struct menu_state *menu_st = &menu_driver_state;
bool runloop_shutdown_initiated = (runloop_st->flags &
@ -6277,10 +6278,13 @@ void menu_driver_toggle(
if (settings)
{
#ifdef HAVE_NETWORKING
pause_libretro = settings->bools.menu_pause_libretro &&
netplay_driver_ctl(RARCH_NETPLAY_CTL_ALLOW_PAUSE, NULL);
menu_pause_libretro = settings->bools.menu_pause_libretro
&& netplay_driver_ctl(RARCH_NETPLAY_CTL_ALLOW_PAUSE, NULL);
#else
pause_libretro = settings->bools.menu_pause_libretro;
menu_pause_libretro = settings->bools.menu_pause_libretro;
#endif
#ifdef HAVE_AUDIOMIXER
audio_enable_menu = settings->bools.audio_enable_menu;
#endif
#ifdef HAVE_OVERLAY
input_overlay_hide_in_menu = settings->bools.input_overlay_hide_in_menu;
@ -6346,11 +6350,10 @@ void menu_driver_toggle(
/* Stop all rumbling before entering the menu. */
command_event(CMD_EVENT_RUMBLE_STOP, NULL);
if (pause_libretro)
if (menu_pause_libretro)
{
#ifdef PS2
command_event(CMD_EVENT_AUDIO_STOP, NULL);
#endif
if (!audio_enable_menu)
command_event(CMD_EVENT_AUDIO_STOP, NULL);
#ifdef HAVE_MICROPHONE
command_event(CMD_EVENT_MICROPHONE_STOP, NULL);
#endif
@ -6379,11 +6382,10 @@ void menu_driver_toggle(
if (!runloop_shutdown_initiated)
driver_set_nonblock_state();
if (pause_libretro)
if (menu_pause_libretro)
{
#ifdef PS2
command_event(CMD_EVENT_AUDIO_START, NULL);
#endif
if (!audio_enable_menu)
command_event(CMD_EVENT_AUDIO_START, NULL);
#ifdef HAVE_MICROPHONE
command_event(CMD_EVENT_MICROPHONE_START, NULL);
#endif

View file

@ -8640,9 +8640,15 @@ static void general_write_handler(rarch_setting_t *setting)
case MENU_ENUM_LABEL_AUDIO_ENABLE_MENU:
#ifdef HAVE_AUDIOMIXER
if (settings->bools.audio_enable_menu)
{
command_event(CMD_EVENT_AUDIO_START, NULL);
audio_driver_load_system_sounds();
}
else
{
audio_driver_mixer_stop_stream(AUDIO_MIXER_SYSTEM_SLOT_BGM);
command_event(CMD_EVENT_AUDIO_STOP, NULL);
}
#endif
break;
case MENU_ENUM_LABEL_MENU_SOUND_BGM:

View file

@ -3861,23 +3861,50 @@ bool command_event(enum event_command cmd, void *data)
#endif
break;
case CMD_EVENT_AUDIO_STOP:
{
bool menu_pause_libretro = false;
bool audio_enable_menu = false;
#if defined(HAVE_AUDIOMIXER) && defined(HAVE_MENU)
if ( settings->bools.audio_enable_menu
&& menu_state_get_ptr()->flags & MENU_ST_FLAG_ALIVE)
return false;
audio_enable_menu = settings->bools.audio_enable_menu
&& menu_state_get_ptr()->flags & MENU_ST_FLAG_ALIVE;
#endif
if (!audio_driver_stop())
return false;
#ifdef HAVE_NETWORKING
menu_pause_libretro = settings->bools.menu_pause_libretro
&& netplay_driver_ctl(RARCH_NETPLAY_CTL_ALLOW_PAUSE, NULL);
#else
menu_pause_libretro = settings->bools.menu_pause_libretro;
#endif
if (audio_enable_menu || !menu_pause_libretro)
return false;
if (!audio_driver_stop())
return false;
}
break;
case CMD_EVENT_AUDIO_START:
{
bool menu_pause_libretro = false;
bool audio_enable_menu = false;
#if defined(HAVE_AUDIOMIXER) && defined(HAVE_MENU)
if ( settings->bools.audio_enable_menu
&& menu_state_get_ptr()->flags & MENU_ST_FLAG_ALIVE)
return false;
audio_enable_menu = settings->bools.audio_enable_menu
&& menu_state_get_ptr()->flags & MENU_ST_FLAG_ALIVE;
#endif
if (!audio_driver_start(runloop_st->flags &
RUNLOOP_FLAG_SHUTDOWN_INITIATED))
return false;
#ifdef HAVE_NETWORKING
menu_pause_libretro = settings->bools.menu_pause_libretro
&& netplay_driver_ctl(RARCH_NETPLAY_CTL_ALLOW_PAUSE, NULL);
#else
menu_pause_libretro = settings->bools.menu_pause_libretro;
#endif
if (audio_enable_menu && !menu_pause_libretro)
return false;
if (!audio_driver_start(runloop_st->flags & RUNLOOP_FLAG_SHUTDOWN_INITIATED))
return false;
}
break;
#ifdef HAVE_MICROPHONE
case CMD_EVENT_MICROPHONE_STOP:
@ -4664,19 +4691,22 @@ bool command_event(enum event_command cmd, void *data)
#ifdef HAVE_MENU
{
#ifdef HAVE_NETWORKING
bool menu_pause_libretro = settings->bools.menu_pause_libretro
&& netplay_driver_ctl(RARCH_NETPLAY_CTL_ALLOW_PAUSE, NULL);
bool menu_pause_libretro = settings->bools.menu_pause_libretro
&& netplay_driver_ctl(RARCH_NETPLAY_CTL_ALLOW_PAUSE, NULL);
#else
bool menu_pause_libretro = settings->bools.menu_pause_libretro;
bool menu_pause_libretro = settings->bools.menu_pause_libretro;
#endif
if (menu_pause_libretro)
{
command_event(CMD_EVENT_AUDIO_STOP, NULL);
#ifdef HAVE_MICROPHONE
command_event(CMD_EVENT_MICROPHONE_STOP, NULL);
#endif
}
else
{
command_event(CMD_EVENT_AUDIO_START, NULL);
#ifdef HAVE_MICROPHONE
command_event(CMD_EVENT_MICROPHONE_START, NULL);
#endif