From a92569deb1678b72c324b42a16c0b61dd2c504f2 Mon Sep 17 00:00:00 2001 From: zilmar Date: Tue, 26 Sep 2017 23:57:33 +1000 Subject: [PATCH] [Audio] Add settings for BufferDivided, BufferFPS, etc --- Source/Project64-audio/AudioMain.cpp | 4 ++ Source/Project64-audio/AudioSettings.cpp | 30 +++++++- Source/Project64-audio/AudioSettings.h | 12 +++- Source/Project64-audio/ConfigUI.cpp | 67 ++++++++++++++++++ Source/Project64-audio/Driver/DirectSound.cpp | 2 +- Source/Project64-audio/Driver/SoundBase.cpp | 7 +- Source/Project64-audio/Driver/SoundBase.h | 6 -- Source/Project64-audio/Project64-audio.rc | Bin 9350 -> 11164 bytes Source/Project64-audio/SettingsID.h | 3 + Source/Project64-audio/resource.h | Bin 2108 -> 2474 bytes 10 files changed, 115 insertions(+), 16 deletions(-) diff --git a/Source/Project64-audio/AudioMain.cpp b/Source/Project64-audio/AudioMain.cpp index c6eb45db4..08d3ba5f2 100644 --- a/Source/Project64-audio/AudioMain.cpp +++ b/Source/Project64-audio/AudioMain.cpp @@ -33,6 +33,7 @@ AUDIO_INFO g_AudioInfo; bool g_PluginInit = false; +bool g_romopen = false; uint32_t g_Dacrate = 0; #ifdef _WIN32 @@ -191,6 +192,8 @@ EXPORT int32_t CALL InitiateAudio(AUDIO_INFO Audio_Info) EXPORT void CALL RomOpen() { WriteTrace(TraceAudioInterface, TraceDebug, "Start"); + g_romopen = true; + g_settings->ReadSettings(); if (g_SoundDriver) { g_SoundDriver->AI_Startup(); @@ -206,6 +209,7 @@ EXPORT void CALL RomClosed(void) { g_SoundDriver->AI_Shutdown(); } + g_romopen = false; WriteTrace(TraceAudioInterface, TraceDebug, "Done"); } diff --git a/Source/Project64-audio/AudioSettings.cpp b/Source/Project64-audio/AudioSettings.cpp index 813ba6b86..4176bbeea 100644 --- a/Source/Project64-audio/AudioSettings.cpp +++ b/Source/Project64-audio/AudioSettings.cpp @@ -25,11 +25,14 @@ CSettings::CSettings() : m_AudioEnabled(true), m_advanced_options(false), m_debugger_enabled(false), - m_Volume(100) + m_Volume(100), + m_BufferDivider(90), + m_BufferLevel(4), + m_SyncAudio(false) { memset(m_log_dir, 0, sizeof(m_log_dir)); RegisterSettings(); - SettingsChanged(); + ReadSettings(); if (m_Set_EnableAudio != 0) { SettingsRegisterChange(false, m_Set_EnableAudio, this, stSettingsChanged); } if (m_Set_basic_mode != 0) { SettingsRegisterChange(false, m_Set_basic_mode, this, stSettingsChanged); } @@ -78,6 +81,9 @@ void CSettings::RegisterSettings(void) RegisterSetting(Set_Logging_InitShutdown, Data_DWORD_General, "InitShutdown", "Logging", g_ModuleLogLevel[TraceAudioInitShutdown], NULL); RegisterSetting(Set_Logging_Interface, Data_DWORD_General, "Interface", "Logging", g_ModuleLogLevel[TraceAudioInterface], NULL); RegisterSetting(Set_Logging_Driver, Data_DWORD_General, "Driver", "Logging", g_ModuleLogLevel[TraceAudioDriver], NULL); + RegisterSetting(Set_BufferDivider, Data_DWORD_Game, "BufferDivider", "", 90, NULL); + RegisterSetting(Set_BufferLevel, Data_DWORD_Game, "BufferLevel", "", 4, NULL); + RegisterSetting(Set_SyncAudio, Data_DWORD_Game, "SyncAudio", "", (uint32_t)false, NULL); LogLevelChanged(); } @@ -97,6 +103,21 @@ void CSettings::SetVolume(uint32_t Volume) } } +void CSettings::SetBufferDivider(uint32_t BufferDivider) +{ + SetSetting(Set_BufferDivider, BufferDivider); +} + +void CSettings::SetBufferLevel(uint32_t BufferLevel) +{ + SetSetting(Set_BufferLevel, BufferLevel); +} + +void CSettings::SetSyncAudio(bool Enabled) +{ + SetSetting(Set_SyncAudio, Enabled ? 1 : 0); +} + void CSettings::LogLevelChanged(void) { g_ModuleLogLevel[TraceMD5] = GetSetting(Set_Logging_MD5); @@ -107,12 +128,15 @@ void CSettings::LogLevelChanged(void) g_ModuleLogLevel[TraceAudioDriver] = GetSetting(Set_Logging_Driver); } -void CSettings::SettingsChanged(void) +void CSettings::ReadSettings(void) { m_Volume = GetSetting(Set_Volume); m_AudioEnabled = m_Set_EnableAudio ? GetSystemSetting(m_Set_EnableAudio) != 0 : true; m_advanced_options = m_Set_basic_mode ? GetSystemSetting(m_Set_basic_mode) == 0 : false; m_debugger_enabled = m_advanced_options && m_Set_debugger ? GetSystemSetting(m_Set_debugger) == 1 : false; + m_BufferDivider = GetSetting(Set_BufferDivider); + m_BufferLevel = GetSetting(Set_BufferLevel); + m_SyncAudio = GetSetting(Set_SyncAudio) != 0; if (m_Set_log_dir != 0) { diff --git a/Source/Project64-audio/AudioSettings.h b/Source/Project64-audio/AudioSettings.h index 993f8a801..feb8ac73a 100644 --- a/Source/Project64-audio/AudioSettings.h +++ b/Source/Project64-audio/AudioSettings.h @@ -19,11 +19,17 @@ public: inline bool AudioEnabled(void) const { return m_AudioEnabled; } inline bool debugger_enabled(void) const { return m_debugger_enabled; } inline uint32_t GetVolume(void) const { return m_Volume; } + inline uint32_t BufferDivider(void) const { return m_BufferDivider; } + inline uint32_t BufferLevel(void) const { return m_BufferLevel; } + inline bool SyncAudio(void) const { return m_SyncAudio; } 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 SetBufferDivider(uint32_t BufferDivider); + void SetBufferLevel(uint32_t BufferLevel); + void SetSyncAudio(bool Enabled); void ReadSettings(); private: @@ -33,12 +39,11 @@ private: } static void stSettingsChanged(void * _this) { - ((CSettings *)_this)->SettingsChanged(); + ((CSettings *)_this)->ReadSettings(); } void RegisterSettings(void); void LogLevelChanged(void); - void SettingsChanged(void); short m_Set_EnableAudio; short m_Set_basic_mode; @@ -51,6 +56,9 @@ private: bool m_advanced_options; bool m_debugger_enabled; uint32_t m_Volume; + uint32_t m_BufferDivider; + uint32_t m_BufferLevel; + bool m_SyncAudio; }; extern CSettings * g_settings; diff --git a/Source/Project64-audio/ConfigUI.cpp b/Source/Project64-audio/ConfigUI.cpp index 972a41fe4..431566f2a 100644 --- a/Source/Project64-audio/ConfigUI.cpp +++ b/Source/Project64-audio/ConfigUI.cpp @@ -24,11 +24,14 @@ #include #pragma warning(pop) #include +#include #include "trace.h" #include "AudioSettings.h" #include "SettingsID.h" #include "resource.h" +extern bool g_romopen; + void SetComboBoxIndex(CComboBox & cmb, uint32_t data) { cmb.SetCurSel(0); @@ -92,6 +95,63 @@ private: CButton m_btnMute; }; +class CGameSettings : + public CPropertyPageImpl +{ +public: + enum { IDD = IDD_GAME_SETTING }; + + BEGIN_MSG_MAP(CDebugSettings) + MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) + COMMAND_HANDLER(IDC_BUFFER_DIVIDER, EN_CHANGE, ItemChanged) + COMMAND_HANDLER(IDC_BUFFER_LEVEL, EN_CHANGE, ItemChanged) + CHAIN_MSG_MAP(CPropertyPageImpl) + END_MSG_MAP() + + LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) + { + m_BufferDivider.Attach(GetDlgItem(IDC_BUFFER_DIVIDER)); + m_BufferDivider.SetWindowText(stdstr_f("%d", g_settings->BufferDivider()).c_str()); + + m_BufferLevel.Attach(GetDlgItem(IDC_BUFFER_LEVEL)); + m_BufferLevel.SetWindowText(stdstr_f("%d", g_settings->BufferLevel()).c_str()); + + m_btnSyncAudio.Attach(GetDlgItem(IDC_SYNC_AUDIO)); + m_btnSyncAudio.SetCheck(g_settings->SyncAudio() ? BST_CHECKED : BST_UNCHECKED); + return TRUE; + } + + bool OnApply() + { + char buffer[100]; + m_BufferDivider.GetWindowText(buffer, sizeof(buffer)); + g_settings->SetBufferDivider(atoi(buffer)); + m_BufferLevel.GetWindowText(buffer, sizeof(buffer)); + g_settings->SetBufferLevel(atoi(buffer)); + g_settings->SetSyncAudio(m_btnSyncAudio.GetCheck() == BST_CHECKED); + + FlushSettings(); + return true; + } + +private: + CEdit m_BufferDivider; + CEdit m_BufferLevel; + CButton m_btnSyncAudio; + + LRESULT ItemChangedNotify(NMHDR* /*pNMHDR*/) + { + SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); + return 0; + } + + LRESULT ItemChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) + { + SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); + return 0; + } +}; + class CLogSettings : public CPropertyPageImpl { @@ -186,14 +246,20 @@ public: private: CGeneralSettings * m_pgGeneralSettings; + CGameSettings * m_pgGameSettings; CLogSettings * m_pgLogSettings; }; CAudioUI::CAudioUI() : m_pgGeneralSettings(new CGeneralSettings), + m_pgGameSettings(new CGameSettings), m_pgLogSettings(new CLogSettings) { AddPage(&m_pgGeneralSettings->m_psp); + if (g_romopen) + { + AddPage(&m_pgGameSettings->m_psp); + } if (g_settings->debugger_enabled()) { AddPage(&m_pgLogSettings->m_psp); @@ -203,6 +269,7 @@ CAudioUI::CAudioUI() : CAudioUI::~CAudioUI() { delete m_pgLogSettings; + delete m_pgGameSettings; delete m_pgGeneralSettings; } diff --git a/Source/Project64-audio/Driver/DirectSound.cpp b/Source/Project64-audio/Driver/DirectSound.cpp index a543c3806..19d2df018 100644 --- a/Source/Project64-audio/Driver/DirectSound.cpp +++ b/Source/Project64-audio/Driver/DirectSound.cpp @@ -123,7 +123,7 @@ void DirectSoundDriver::SetFrequency(uint32_t Frequency) { WriteTrace(TraceAudioDriver, TraceDebug, "Start (Frequency: 0x%08X)", Frequency); StopAudio(); - m_LOCK_SIZE = (uint32_t)((Frequency / BufferFPS)) * 4; + m_LOCK_SIZE = (uint32_t)((Frequency / g_settings->BufferDivider())) * 4; SetSegmentSize(m_LOCK_SIZE, Frequency); StartAudio(); diff --git a/Source/Project64-audio/Driver/SoundBase.cpp b/Source/Project64-audio/Driver/SoundBase.cpp index 17b577375..ac1529744 100644 --- a/Source/Project64-audio/Driver/SoundBase.cpp +++ b/Source/Project64-audio/Driver/SoundBase.cpp @@ -24,8 +24,7 @@ SoundDriverBase::SoundDriverBase() : m_AI_DMASecondaryBytes(0), m_CurrentReadLoc(0), m_CurrentWriteLoc(0), - m_BufferRemaining(0), - m_SyncAudio(false) + m_BufferRemaining(0) { memset(&m_Buffer, 0, sizeof(m_Buffer)); } @@ -38,7 +37,7 @@ bool SoundDriverBase::Initialize() void SoundDriverBase::AI_SetFrequency(uint32_t Frequency) { SetFrequency(Frequency); - m_MaxBufferSize = (uint32_t)((Frequency / BufferFPS)) * 4 * BufferLevel; + m_MaxBufferSize = (uint32_t)((Frequency / g_settings->BufferDivider())) * 4 * g_settings->BufferLevel(); m_BufferRemaining = 0; m_CurrentReadLoc = m_CurrentWriteLoc = m_BufferRemaining = 0; } @@ -48,7 +47,7 @@ void SoundDriverBase::AI_LenChanged(uint8_t *start, uint32_t length) WriteTrace(TraceAudioDriver, TraceDebug, "Start"); // Bleed off some of this buffer to smooth out audio - if (length < m_MaxBufferSize && m_SyncAudio) + if (length < m_MaxBufferSize && g_settings->SyncAudio()) { while ((m_BufferRemaining) == m_MaxBufferSize) { diff --git a/Source/Project64-audio/Driver/SoundBase.h b/Source/Project64-audio/Driver/SoundBase.h index 1ac71f71a..61b9895f2 100644 --- a/Source/Project64-audio/Driver/SoundBase.h +++ b/Source/Project64-audio/Driver/SoundBase.h @@ -16,11 +16,6 @@ class SoundDriverBase { public: - enum - { - BufferFPS = 90, - BufferLevel = 2, - }; SoundDriverBase(); void AI_SetFrequency(uint32_t Frequency); @@ -52,5 +47,4 @@ private: uint32_t m_CurrentReadLoc; // Currently playing Buffer uint32_t m_CurrentWriteLoc; // Currently writing Buffer uint8_t m_Buffer[MAX_SIZE]; // Emulated buffers - bool m_SyncAudio; }; diff --git a/Source/Project64-audio/Project64-audio.rc b/Source/Project64-audio/Project64-audio.rc index bd59485c749015aba255079a7c66520e9c922470..6e8184f9eb02844b11d994b18ad34f5e5e7bfef8 100644 GIT binary patch delta 1413 zcmb7EOK1~O6uq&cnMu-=*tE1Z%_K#OpOD11wAF>=Z(y1U`IVxOidCp+6+cD6g>GDm zcwFT?K%_ zrM{!LHVgbBqChp&6_r|&h1d&5Q#9+~Ow0R> zQz`9KDxlXk`e>qCi_Tz|L#9P0nH(EP#suF>2qB&U{AF6jwIug8|6ph^VUUe}f>N@| zq=P=Q8~1rPcN0CdaG5UNN{9dC9dYwE!FLtc6-RS$9#fnr9EBzvWo*s`_?Kr-&zsJp zk#~D|c+@{_+xyQ!!T1Qlg#{TjVPP+g@-Qq1%eH4kwITlD)eopF1BTq8Gz>I3svYE4 zdjFuiW)YP$;9BPgS{Uac-qgM0?q@78vWHMHZO{Uk6!@hc=0*SBu={y+`az5Ox=f7D zmbTwBYdB4|F}14gJesp7uMAl6-l2UoSI4>r0pfIyQvAu6;7Q*I5L75px=8jvj(|HN zJn@bGK~VX4&rwM+Al*vns=Ko)tC4 zpmcQ*`<-hh_?v$usk-he=pKe``TW^;40*l080eQBD+cbYZ6mY;|3Q8c`09+U-pLxe WC%Wq=lS+KrIKrF8(T*8A+4CD0+VS52 delta 519 zcmbOe-sU-B*~V+f*d|-4t(p8pu1MIBL5INrh(WX^1Ws<2SH&vMtspu1ojjMi0Ye2) zeHw!g11|#?gEB)Vke$Mi3M3U6;u%~RTp64gLK)mAb1O)TLe#=krZVI(6f>lPWW+%- z25>V{8S;Q;08N@4s36J@k~0Cyf}jb5&*X^;lI$QcBOv>#g8XJCMHWVRC58ZoB8Gg1 zETGlN3?&R^K&842i43J+gYqXIRMMTCqa-7$1azz(&>%f94fEtdC2t%ilmVRq@(#p= zB4s62B?f1pJp~MvK>IQo(it*vAYRwBG3&fz#zy0 zyX}Jt-{cMzKB8RlK}89tKg1`Os0vNKC&M+lPIb>@GqnwyeK-#AfEiX&>zF3Lk@eYZ RrnZZ5au~bR<{AwJW&l^RZfyVn diff --git a/Source/Project64-audio/SettingsID.h b/Source/Project64-audio/SettingsID.h index 4e63489e1..8e76072b3 100644 --- a/Source/Project64-audio/SettingsID.h +++ b/Source/Project64-audio/SettingsID.h @@ -20,4 +20,7 @@ enum Set_Logging_InitShutdown, Set_Logging_Interface, Set_Logging_Driver, + Set_BufferDivider, + Set_BufferLevel, + Set_SyncAudio, }; \ No newline at end of file diff --git a/Source/Project64-audio/resource.h b/Source/Project64-audio/resource.h index f10720b50d8dcdec16c8687b736d7c20e525d18f..919a05bfdec1c7c42e2121753194c061427eb821 100644 GIT binary patch delta 186 zcmdlZuu6Et97bsuhIj^d21f>823H^}7)XWyp(leMgZpGgM#ae!m{=H1CMU9sP7Yw= zkal7SWpD#RSB4;