From eddd90bbeb171efe68d7f6d39ce4f9193b521842 Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 20 Dec 2018 20:49:14 +1030 Subject: [PATCH] [Project64] Try to fix sync to audio --- Source/Project64-audio/AudioMain.cpp | 4 ++++ Source/Project64-audio/AudioSettings.cpp | 15 ++++++++++----- Source/Project64-audio/AudioSettings.h | 10 ++++++---- Source/Project64-core/Plugins/AudioPlugin.cpp | 3 ++- Source/Project64-core/Plugins/PluginClass.cpp | 5 +++++ Source/Project64-core/Settings/GameSettings.cpp | 9 +++++++-- Source/Project64-core/Settings/GameSettings.h | 2 ++ 7 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Source/Project64-audio/AudioMain.cpp b/Source/Project64-audio/AudioMain.cpp index 9d71f6ed5..47e9ce2c0 100644 --- a/Source/Project64-audio/AudioMain.cpp +++ b/Source/Project64-audio/AudioMain.cpp @@ -65,6 +65,10 @@ EXPORT void CALL PluginLoaded(void) { PluginInit(); WriteTrace(TraceAudioInterface, TraceDebug, "Called"); + if (g_settings != NULL) + { + g_settings->SetSyncViaAudioEnabled(true); + } } EXPORT void CALL AiDacrateChanged(int SystemType) diff --git a/Source/Project64-audio/AudioSettings.cpp b/Source/Project64-audio/AudioSettings.cpp index cef5a25ef..798e9d0aa 100644 --- a/Source/Project64-audio/AudioSettings.cpp +++ b/Source/Project64-audio/AudioSettings.cpp @@ -16,6 +16,7 @@ CSettings * g_settings = NULL; CSettings::CSettings() : + m_Set_SyncViaAudioEnabled(0), m_Set_EnableAudio(0), m_Set_FixedAudio(0), m_Set_SyncAudio(0), @@ -81,11 +82,7 @@ CSettings::~CSettings() void CSettings::RegisterSettings(void) { SetModuleName("default"); - short Set_SyncViaAudioEnabled = FindSystemSettingId("SyncViaAudioEnabled"); - if (Set_SyncViaAudioEnabled != 0) - { - SetSystemSetting(Set_SyncViaAudioEnabled, 1); - } + m_Set_SyncViaAudioEnabled = FindSystemSettingId("SyncViaAudioEnabled"); m_Set_EnableAudio = FindSystemSettingId("Enable Audio"); m_Set_FixedAudio = FindSystemSettingId("Fixed Audio"); m_Set_SyncAudio = FindSystemSettingId("Sync Audio"); @@ -109,6 +106,14 @@ void CSettings::RegisterSettings(void) LogLevelChanged(); } +void CSettings::SetSyncViaAudioEnabled(bool Enabled) +{ + if (m_Set_SyncViaAudioEnabled != 0) + { + SetSystemSetting(m_Set_SyncViaAudioEnabled, Enabled ? 1 : 0); + } +} + void CSettings::SetAudioEnabled(bool Enabled) { if (m_Set_EnableAudio != 0) diff --git a/Source/Project64-audio/AudioSettings.h b/Source/Project64-audio/AudioSettings.h index 2e3d254f5..334d74099 100644 --- a/Source/Project64-audio/AudioSettings.h +++ b/Source/Project64-audio/AudioSettings.h @@ -26,8 +26,9 @@ public: inline bool FlushLogs(void) const { return m_FlushLogs; } inline const char * log_dir(void) const { return m_log_dir; } - void SetAudioEnabled(bool Enabled); - void SetVolume(uint32_t Volume); + void SetSyncViaAudioEnabled(bool Enabled); + void SetAudioEnabled(bool Enabled); + void SetVolume(uint32_t Volume); void SetTinyBuffer(bool TinyBuffer); void SetFPSBuffer(bool FPSBuffer); void ReadSettings(); @@ -45,8 +46,9 @@ private: void RegisterSettings(void); void LogLevelChanged(void); - short m_Set_EnableAudio; - short m_Set_FixedAudio; + short m_Set_SyncViaAudioEnabled; + short m_Set_EnableAudio; + short m_Set_FixedAudio; short m_Set_SyncAudio; short m_Set_FullSpeed; short m_Set_LimitFPS; diff --git a/Source/Project64-core/Plugins/AudioPlugin.cpp b/Source/Project64-core/Plugins/AudioPlugin.cpp index df7f879e7..85324f1e4 100644 --- a/Source/Project64-core/Plugins/AudioPlugin.cpp +++ b/Source/Project64-core/Plugins/AudioPlugin.cpp @@ -37,6 +37,8 @@ CAudioPlugin::~CAudioPlugin() bool CAudioPlugin::LoadFunctions(void) { + g_Settings->SaveBool(Setting_SyncViaAudioEnabled, false); + // Find entries for functions in DLL void(CALL *InitiateAudio)(void); LoadFunction(InitiateAudio); @@ -62,7 +64,6 @@ bool CAudioPlugin::LoadFunctions(void) bool CAudioPlugin::Initiate(CN64System * System, RenderWindow * Window) { - g_Settings->SaveBool(Setting_SyncViaAudioEnabled, false); struct AUDIO_INFO { void * hwnd; diff --git a/Source/Project64-core/Plugins/PluginClass.cpp b/Source/Project64-core/Plugins/PluginClass.cpp index faefa5b33..845c9ebe4 100644 --- a/Source/Project64-core/Plugins/PluginClass.cpp +++ b/Source/Project64-core/Plugins/PluginClass.cpp @@ -363,6 +363,11 @@ bool CPlugins::Reset(CN64System * System) if (!m_RSP->Initiate(this, System)) { return false; } WriteTrace(TraceRSPPlugin, TraceDebug, "RSP Initiate Done"); } + + if (System) + { + System->RefreshSyncToAudio(); + } WriteTrace(TracePlugins, TraceDebug, "Done"); return true; } diff --git a/Source/Project64-core/Settings/GameSettings.cpp b/Source/Project64-core/Settings/GameSettings.cpp index 6ee003245..e4886016a 100644 --- a/Source/Project64-core/Settings/GameSettings.cpp +++ b/Source/Project64-core/Settings/GameSettings.cpp @@ -57,7 +57,6 @@ void CGameSettings::RefreshGameSettings() m_DelaySI = g_Settings->LoadBool(Game_DelaySI); m_DelayDP = g_Settings->LoadBool(Game_DelayDP); m_bFixedAudio = g_Settings->LoadBool(Game_FixedAudio); - m_bSyncToAudio = g_Settings->LoadBool(Game_SyncViaAudio) && g_Settings->LoadBool(Setting_SyncViaAudioEnabled); m_FullSpeed = g_Settings->LoadBool(Game_FullSpeed); m_b32Bit = g_Settings->LoadBool(Game_32Bit); #ifdef ANDROID @@ -79,6 +78,7 @@ void CGameSettings::RefreshGameSettings() } if (m_OverClockModifier < 1) { m_OverClockModifier = 1; } if (m_OverClockModifier > 20) { m_OverClockModifier = 20; } + RefreshSyncToAudio(); WriteTrace(TraceN64System, TraceDebug, "Done"); } @@ -86,4 +86,9 @@ void CGameSettings::SpeedChanged(int SpeedLimit) { m_FullSpeed = (g_System->m_SystemType == SYSTEM_PAL ? 50 : 60) == SpeedLimit; g_Settings->SaveBool(Game_FullSpeed, m_FullSpeed); -} \ No newline at end of file +} + +void CGameSettings::RefreshSyncToAudio(void) +{ + m_bSyncToAudio = g_Settings->LoadBool(Game_SyncViaAudio) && g_Settings->LoadBool(Setting_SyncViaAudioEnabled); +} diff --git a/Source/Project64-core/Settings/GameSettings.h b/Source/Project64-core/Settings/GameSettings.h index 3fe145d25..c1ac29849 100644 --- a/Source/Project64-core/Settings/GameSettings.h +++ b/Source/Project64-core/Settings/GameSettings.h @@ -45,6 +45,8 @@ public: inline static CPU_TYPE CpuType(void) { return m_CpuType; } inline static uint32_t OverClockModifier(void) { return m_OverClockModifier; } + void RefreshSyncToAudio(void); + protected: static void SpeedChanged(int32_t SpeedLimit);