[Audio] Add settings for BufferDivided, BufferFPS, etc

This commit is contained in:
zilmar 2017-09-26 23:57:33 +10:00
parent 64bcfa15dd
commit a92569deb1
10 changed files with 115 additions and 16 deletions

View File

@ -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");
}

View File

@ -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)
{

View File

@ -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;

View File

@ -24,11 +24,14 @@
#include <wtl/atlcrack.h>
#pragma warning(pop)
#include <Settings/Settings.h>
#include <Common/StdString.h>
#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<CGameSettings>
{
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<CGameSettings>)
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<CLogSettings>
{
@ -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;
}

View File

@ -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();

View File

@ -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)
{

View File

@ -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;
};

View File

@ -20,4 +20,7 @@ enum
Set_Logging_InitShutdown,
Set_Logging_Interface,
Set_Logging_Driver,
Set_BufferDivider,
Set_BufferLevel,
Set_SyncAudio,
};

Binary file not shown.