From 5c136aea57d94a81176ec913fdb7209258c932c6 Mon Sep 17 00:00:00 2001 From: headshot2017 <> Date: Thu, 14 Mar 2024 22:18:14 -0400 Subject: [PATCH] AudioBackend_Tick!! --- src/Audio.c | 12 +++++++++++- src/Platform_Switch.c | 5 ----- src/Window_Switch.c | 8 -------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Audio.c b/src/Audio.c index 7c4bc9419..0bc17d23b 100644 --- a/src/Audio.c +++ b/src/Audio.c @@ -950,12 +950,14 @@ static int channelIDs; static struct AudioMemPools audioPools[64]; AudioDriver drv; bool switchAudio = false; -extern void* audrv_mutex; +void* audrv_mutex; static cc_bool AudioBackend_Init(void) { if (switchAudio) return true; switchAudio = true; + audrv_mutex = Mutex_Create(); + Mem_Set(audioPools, 0, sizeof(audioPools)); static const AudioRendererConfig arConfig = @@ -980,9 +982,17 @@ static cc_bool AudioBackend_Init(void) { return R_SUCCEEDED(res); } + +void AudioBackend_Tick(void) { + Mutex_Lock(audrv_mutex); + if (switchAudio) audrvUpdate(&drv); + Mutex_Unlock(audrv_mutex); +} + static void AudioBackend_Free(void) { if (!switchAudio) return; switchAudio = false; + Mutex_Free(audrv_mutex); audrvClose(&drv); audrenExit(); diff --git a/src/Platform_Switch.c b/src/Platform_Switch.c index 57e7f6f09..124c7aef6 100644 --- a/src/Platform_Switch.c +++ b/src/Platform_Switch.c @@ -37,8 +37,6 @@ const cc_result ReturnCode_SocketWouldBlock = EWOULDBLOCK; const cc_result ReturnCode_DirectoryExists = EEXIST; const char* Platform_AppNameSuffix = " Switch"; -void* audrv_mutex; - alignas(16) u8 __nx_exception_stack[0x1000]; u64 __nx_exception_stack_size = sizeof(__nx_exception_stack); @@ -521,12 +519,9 @@ void Platform_Init(void) { // Configure our supported input layout: a single player with standard controller styles padConfigureInput(1, HidNpadStyleSet_NpadStandard); hidInitializeTouchScreen(); - - audrv_mutex = Mutex_Create(); } void Platform_Free(void) { socketExit(); - Mutex_Free(audrv_mutex); } cc_bool Platform_DescribeError(cc_result res, cc_string* dst) { diff --git a/src/Window_Switch.c b/src/Window_Switch.c index a2b9e30e7..5a537d516 100644 --- a/src/Window_Switch.c +++ b/src/Window_Switch.c @@ -22,9 +22,6 @@ static EGLDisplay s_display; static EGLContext s_context; static EGLSurface s_surface; -extern AudioDriver drv; -extern bool switchAudio; -extern void* audrv_mutex; static cc_bool launcherMode; static Framebuffer fb; @@ -139,11 +136,6 @@ void Window_ProcessEvents(double delta) { // Scan the gamepad. This should be done once for each frame padUpdate(&pad); - Mutex_Lock(audrv_mutex); - if (switchAudio) - audrvUpdate(&drv); - Mutex_Unlock(audrv_mutex); - if (!appletMainLoop()) { Window_Main.Exists = false; Window_RequestClose();