Merge pull request #1390 from Frank-74/AudioSync-BufferChanges
Audio sync buffer changes
This commit is contained in:
commit
8c7830a037
|
@ -87,15 +87,36 @@ EXPORT void CALL AiDacrateChanged(int SystemType)
|
||||||
}
|
}
|
||||||
uint32_t Frequency = video_clock / (g_Dacrate + 1);
|
uint32_t Frequency = video_clock / (g_Dacrate + 1);
|
||||||
|
|
||||||
if ((Frequency > 7000) && (Frequency < 9000)) { Frequency = 8000; }
|
if (Frequency < 4000)
|
||||||
else if ((Frequency > 10000) && (Frequency < 12000)) { Frequency = 11025; }
|
{
|
||||||
else if ((Frequency > 15000) && (Frequency < 17000)) { Frequency = 16000; }
|
WriteTrace(TraceAudioDriver, TraceDebug, "Not Audio Data!");
|
||||||
else if ((Frequency > 21000) && (Frequency < 23000)) { Frequency = 22050; }
|
return;
|
||||||
else if ((Frequency > 31000) && (Frequency < 33000)) { Frequency = 32000; }
|
}
|
||||||
else if ((Frequency > 43000) && (Frequency < 45000)) { Frequency = 44100; }
|
else
|
||||||
else if ((Frequency > 47000) && (Frequency < 49000)) { Frequency = 48000; }
|
{
|
||||||
|
int32_t BufferSize = 0; double audio_clock = 0;
|
||||||
|
double framerate1 = 59.94004; double framerate2 = 64; double framerate = 0;
|
||||||
|
|
||||||
g_SoundDriver->AI_SetFrequency(Frequency);
|
if (g_settings->FPSBuffer() == true)
|
||||||
|
{
|
||||||
|
framerate = framerate1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
framerate = framerate2;
|
||||||
|
}
|
||||||
|
if (g_settings->TinyBuffer() == true)
|
||||||
|
{
|
||||||
|
audio_clock = ((video_clock / framerate) * 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
audio_clock = ((video_clock / framerate) * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferSize = (int32_t)audio_clock / (g_Dacrate) + 1 & ~0x1;
|
||||||
|
g_SoundDriver->AI_SetFrequency(Frequency, BufferSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
WriteTrace(TraceAudioInterface, TraceDebug, "Done");
|
WriteTrace(TraceAudioInterface, TraceDebug, "Done");
|
||||||
}
|
}
|
||||||
|
@ -135,7 +156,7 @@ EXPORT void CALL AiUpdate(int32_t Wait)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pjutil::Sleep(1);
|
pjutil::Sleep(1); // TODO: Fixme -- Ai Update appears to be problematic
|
||||||
}
|
}
|
||||||
WriteTrace(TraceAudioInterface, TraceDebug, "Done");
|
WriteTrace(TraceAudioInterface, TraceDebug, "Done");
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ CSettings::CSettings() :
|
||||||
m_advanced_options(false),
|
m_advanced_options(false),
|
||||||
m_debugger_enabled(false),
|
m_debugger_enabled(false),
|
||||||
m_Volume(100),
|
m_Volume(100),
|
||||||
m_BufferDivider(90),
|
m_TinyBuffer(true),
|
||||||
m_BufferLevel(4),
|
m_FPSBuffer(true),
|
||||||
m_SyncAudio(false),
|
m_SyncAudio(false),
|
||||||
m_FullSpeed(true)
|
m_FullSpeed(true)
|
||||||
{
|
{
|
||||||
|
@ -94,8 +94,8 @@ void CSettings::RegisterSettings(void)
|
||||||
RegisterSetting(Set_Logging_InitShutdown, Data_DWORD_General, "InitShutdown", "Logging", g_ModuleLogLevel[TraceAudioInitShutdown], NULL);
|
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_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_Logging_Driver, Data_DWORD_General, "Driver", "Logging", g_ModuleLogLevel[TraceAudioDriver], NULL);
|
||||||
RegisterSetting(Set_BufferDivider, Data_DWORD_Game, "BufferDivider", "", 90, NULL);
|
RegisterSetting(Set_TinyBuffer, Data_DWORD_Game, "TinyBuffer", "", (bool)true, NULL);
|
||||||
RegisterSetting(Set_BufferLevel, Data_DWORD_Game, "BufferLevel", "", 4, NULL);
|
RegisterSetting(Set_FPSBuffer, Data_DWORD_Game, "FPSBuffer", "", (bool)true, NULL);
|
||||||
LogLevelChanged();
|
LogLevelChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,14 +115,14 @@ void CSettings::SetVolume(uint32_t Volume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSettings::SetBufferDivider(uint32_t BufferDivider)
|
void CSettings::SetTinyBuffer(bool TinyBuffer)
|
||||||
{
|
{
|
||||||
SetSetting(Set_BufferDivider, BufferDivider);
|
SetSetting(Set_TinyBuffer, TinyBuffer ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSettings::SetBufferLevel(uint32_t BufferLevel)
|
void CSettings::SetFPSBuffer(bool FPSBuffer)
|
||||||
{
|
{
|
||||||
SetSetting(Set_BufferLevel, BufferLevel);
|
SetSetting(Set_FPSBuffer, FPSBuffer ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSettings::LogLevelChanged(void)
|
void CSettings::LogLevelChanged(void)
|
||||||
|
@ -144,8 +144,8 @@ void CSettings::ReadSettings(void)
|
||||||
m_AudioEnabled = m_Set_EnableAudio ? GetSystemSetting(m_Set_EnableAudio) != 0 : true;
|
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_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_debugger_enabled = m_advanced_options && m_Set_debugger ? GetSystemSetting(m_Set_debugger) == 1 : false;
|
||||||
m_BufferDivider = GetSetting(Set_BufferDivider);
|
m_TinyBuffer = GetSetting(Set_TinyBuffer) != 0;
|
||||||
m_BufferLevel = GetSetting(Set_BufferLevel);
|
m_FPSBuffer = GetSetting(Set_FPSBuffer) != 0;
|
||||||
m_FullSpeed = m_Set_FullSpeed ? GetSystemSetting(m_Set_FullSpeed) != 0 : false;
|
m_FullSpeed = m_Set_FullSpeed ? GetSystemSetting(m_Set_FullSpeed) != 0 : false;
|
||||||
|
|
||||||
m_SyncAudio = ((!m_advanced_options || bLimitFPS) && SyncAudio && m_FullSpeed);
|
m_SyncAudio = ((!m_advanced_options || bLimitFPS) && SyncAudio && m_FullSpeed);
|
||||||
|
|
|
@ -19,8 +19,8 @@ public:
|
||||||
inline bool AudioEnabled(void) const { return m_AudioEnabled; }
|
inline bool AudioEnabled(void) const { return m_AudioEnabled; }
|
||||||
inline bool debugger_enabled(void) const { return m_debugger_enabled; }
|
inline bool debugger_enabled(void) const { return m_debugger_enabled; }
|
||||||
inline uint32_t GetVolume(void) const { return m_Volume; }
|
inline uint32_t GetVolume(void) const { return m_Volume; }
|
||||||
inline uint32_t BufferDivider(void) const { return m_BufferDivider; }
|
inline bool TinyBuffer(void) const { return m_TinyBuffer; }
|
||||||
inline uint32_t BufferLevel(void) const { return m_BufferLevel; }
|
inline bool FPSBuffer(void) const { return m_FPSBuffer; }
|
||||||
inline bool SyncAudio(void) const { return m_SyncAudio; }
|
inline bool SyncAudio(void) const { return m_SyncAudio; }
|
||||||
inline bool FullSpeed(void) const { return m_FullSpeed; }
|
inline bool FullSpeed(void) const { return m_FullSpeed; }
|
||||||
inline bool FlushLogs(void) const { return m_FlushLogs; }
|
inline bool FlushLogs(void) const { return m_FlushLogs; }
|
||||||
|
@ -28,8 +28,8 @@ public:
|
||||||
|
|
||||||
void SetAudioEnabled(bool Enabled);
|
void SetAudioEnabled(bool Enabled);
|
||||||
void SetVolume(uint32_t Volume);
|
void SetVolume(uint32_t Volume);
|
||||||
void SetBufferDivider(uint32_t BufferDivider);
|
void SetTinyBuffer(bool TinyBuffer);
|
||||||
void SetBufferLevel(uint32_t BufferLevel);
|
void SetFPSBuffer(bool FPSBuffer);
|
||||||
void ReadSettings();
|
void ReadSettings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -59,8 +59,8 @@ private:
|
||||||
bool m_advanced_options;
|
bool m_advanced_options;
|
||||||
bool m_debugger_enabled;
|
bool m_debugger_enabled;
|
||||||
uint32_t m_Volume;
|
uint32_t m_Volume;
|
||||||
uint32_t m_BufferDivider;
|
bool m_TinyBuffer;
|
||||||
uint32_t m_BufferLevel;
|
bool m_FPSBuffer;
|
||||||
bool m_SyncAudio;
|
bool m_SyncAudio;
|
||||||
bool m_FullSpeed;
|
bool m_FullSpeed;
|
||||||
};
|
};
|
||||||
|
|
|
@ -103,47 +103,37 @@ public:
|
||||||
|
|
||||||
BEGIN_MSG_MAP(CDebugSettings)
|
BEGIN_MSG_MAP(CDebugSettings)
|
||||||
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
|
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
|
||||||
COMMAND_HANDLER(IDC_BUFFER_DIVIDER, EN_CHANGE, ItemChanged)
|
COMMAND_ID_HANDLER_EX(IDC_TINYBUFFER, ItemChanged)
|
||||||
COMMAND_HANDLER(IDC_BUFFER_LEVEL, EN_CHANGE, ItemChanged)
|
COMMAND_ID_HANDLER_EX(IDC_FPSBUFFER, ItemChanged)
|
||||||
CHAIN_MSG_MAP(CPropertyPageImpl<CGameSettings>)
|
CHAIN_MSG_MAP(CPropertyPageImpl<CGameSettings>)
|
||||||
END_MSG_MAP()
|
END_MSG_MAP()
|
||||||
|
|
||||||
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
||||||
{
|
{
|
||||||
m_BufferDivider.Attach(GetDlgItem(IDC_BUFFER_DIVIDER));
|
m_btnTinyBuffer.Attach(GetDlgItem(IDC_TINYBUFFER));
|
||||||
m_BufferDivider.SetWindowText(stdstr_f("%d", g_settings->BufferDivider()).c_str());
|
m_btnTinyBuffer.SetCheck(g_settings->TinyBuffer() ? BST_CHECKED : BST_UNCHECKED);
|
||||||
|
m_btnFPSBuffer.Attach(GetDlgItem(IDC_FPSBUFFER));
|
||||||
m_BufferLevel.Attach(GetDlgItem(IDC_BUFFER_LEVEL));
|
m_btnFPSBuffer.SetCheck(g_settings->FPSBuffer() ? BST_CHECKED : BST_UNCHECKED);
|
||||||
m_BufferLevel.SetWindowText(stdstr_f("%d", g_settings->BufferLevel()).c_str());
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnApply()
|
bool OnApply()
|
||||||
{
|
{
|
||||||
char buffer[100];
|
g_settings->SetTinyBuffer(m_btnTinyBuffer.GetCheck() == BST_CHECKED);
|
||||||
m_BufferDivider.GetWindowText(buffer, sizeof(buffer));
|
g_settings->SetFPSBuffer(m_btnFPSBuffer.GetCheck() == BST_CHECKED);
|
||||||
g_settings->SetBufferDivider(atoi(buffer));
|
|
||||||
m_BufferLevel.GetWindowText(buffer, sizeof(buffer));
|
|
||||||
g_settings->SetBufferLevel(atoi(buffer));
|
|
||||||
|
|
||||||
FlushSettings();
|
FlushSettings();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CEdit m_BufferDivider;
|
CButton m_btnTinyBuffer;
|
||||||
CEdit m_BufferLevel;
|
CButton m_btnFPSBuffer;
|
||||||
|
|
||||||
LRESULT ItemChangedNotify(NMHDR* /*pNMHDR*/)
|
void ItemChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
|
||||||
{
|
{
|
||||||
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
|
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
|
||||||
return 0;
|
g_settings->SetTinyBuffer(m_btnTinyBuffer.GetCheck() == BST_CHECKED);
|
||||||
}
|
g_settings->SetFPSBuffer(m_btnFPSBuffer.GetCheck() == BST_CHECKED);
|
||||||
|
|
||||||
LRESULT ItemChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
|
|
||||||
{
|
|
||||||
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -119,11 +119,11 @@ void DirectSoundDriver::StartAudio()
|
||||||
WriteTrace(TraceAudioDriver, TraceDebug, "Done");
|
WriteTrace(TraceAudioDriver, TraceDebug, "Done");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectSoundDriver::SetFrequency(uint32_t Frequency)
|
void DirectSoundDriver::SetFrequency(uint32_t Frequency, uint32_t BufferSize)
|
||||||
{
|
{
|
||||||
WriteTrace(TraceAudioDriver, TraceDebug, "Start (Frequency: 0x%08X)", Frequency);
|
WriteTrace(TraceAudioDriver, TraceDebug, "Start (Frequency: 0x%08X)", Frequency);
|
||||||
StopAudio();
|
StopAudio();
|
||||||
m_LOCK_SIZE = (uint32_t)((Frequency / g_settings->BufferDivider())) * 4;
|
m_LOCK_SIZE = (BufferSize * 2);
|
||||||
SetSegmentSize(m_LOCK_SIZE, Frequency);
|
SetSegmentSize(m_LOCK_SIZE, Frequency);
|
||||||
|
|
||||||
StartAudio();
|
StartAudio();
|
||||||
|
@ -132,10 +132,16 @@ void DirectSoundDriver::SetFrequency(uint32_t Frequency)
|
||||||
|
|
||||||
void DirectSoundDriver::SetVolume(uint32_t Volume)
|
void DirectSoundDriver::SetVolume(uint32_t Volume)
|
||||||
{
|
{
|
||||||
/*DWORD dsVolume = ((DWORD)Volume * -25);
|
LPDIRECTSOUNDBUFFER & lpdsb = (LPDIRECTSOUNDBUFFER &)m_lpdsb;
|
||||||
if (Volume == 100) dsVolume = (DWORD)DSBVOLUME_MIN;
|
int32_t dsVolume = -((100 - (int32_t)Volume) * 25);
|
||||||
if (Volume == 0) dsVolume = DSBVOLUME_MAX;
|
if (Volume == 0)
|
||||||
if (lpdsb != NULL) lpdsb->SetVolume(dsVolume);*/
|
{
|
||||||
|
dsVolume = DSBVOLUME_MIN;
|
||||||
|
}
|
||||||
|
if (lpdsb != NULL)
|
||||||
|
{
|
||||||
|
lpdsb->SetVolume(dsVolume);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectSoundDriver::SetSegmentSize(uint32_t length, uint32_t SampleRate)
|
void DirectSoundDriver::SetSegmentSize(uint32_t length, uint32_t SampleRate)
|
||||||
|
|
|
@ -21,7 +21,7 @@ public:
|
||||||
bool Initialize();
|
bool Initialize();
|
||||||
void StopAudio(); // Stops the Audio PlayBack (as if paused)
|
void StopAudio(); // Stops the Audio PlayBack (as if paused)
|
||||||
void StartAudio(); // Starts the Audio PlayBack (as if unpaused)
|
void StartAudio(); // Starts the Audio PlayBack (as if unpaused)
|
||||||
void SetFrequency(uint32_t Frequency);
|
void SetFrequency(uint32_t Frequency, uint32_t BufferSize);
|
||||||
void SetVolume(uint32_t Volume);
|
void SetVolume(uint32_t Volume);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -34,10 +34,10 @@ bool SoundDriverBase::Initialize()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundDriverBase::AI_SetFrequency(uint32_t Frequency)
|
void SoundDriverBase::AI_SetFrequency(uint32_t Frequency, uint32_t BufferSize)
|
||||||
{
|
{
|
||||||
SetFrequency(Frequency);
|
SetFrequency(Frequency, BufferSize);
|
||||||
m_MaxBufferSize = (uint32_t)((Frequency / g_settings->BufferDivider())) * 4 * g_settings->BufferLevel();
|
m_MaxBufferSize = (BufferSize * 4);
|
||||||
m_BufferRemaining = 0;
|
m_BufferRemaining = 0;
|
||||||
m_CurrentReadLoc = m_CurrentWriteLoc = m_BufferRemaining = 0;
|
m_CurrentReadLoc = m_CurrentWriteLoc = m_BufferRemaining = 0;
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ void SoundDriverBase::BufferAudio()
|
||||||
WriteTrace(TraceAudioDriver, TraceVerbose, "Done (m_BufferRemaining: 0x%08X)", m_BufferRemaining);
|
WriteTrace(TraceAudioDriver, TraceVerbose, "Done (m_BufferRemaining: 0x%08X)", m_BufferRemaining);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundDriverBase::SetFrequency(uint32_t /*Frequency*/)
|
void SoundDriverBase::SetFrequency(uint32_t /*Frequency*/, uint32_t /*Divider*/)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,14 @@ class SoundDriverBase
|
||||||
public:
|
public:
|
||||||
SoundDriverBase();
|
SoundDriverBase();
|
||||||
|
|
||||||
void AI_SetFrequency(uint32_t Frequency);
|
void AI_SetFrequency(uint32_t Frequency, uint32_t BufferSize);
|
||||||
void AI_LenChanged(uint8_t *start, uint32_t length);
|
void AI_LenChanged(uint8_t *start, uint32_t length);
|
||||||
void AI_Startup();
|
void AI_Startup();
|
||||||
void AI_Shutdown();
|
void AI_Shutdown();
|
||||||
void AI_Update(bool Wait);
|
void AI_Update(bool Wait);
|
||||||
uint32_t AI_ReadLength();
|
uint32_t AI_ReadLength();
|
||||||
|
|
||||||
virtual void SetFrequency(uint32_t Frequency);
|
virtual void SetFrequency(uint32_t Frequency, uint32_t BufferSize);
|
||||||
virtual void StartAudio();
|
virtual void StartAudio();
|
||||||
virtual void StopAudio();
|
virtual void StopAudio();
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -20,6 +20,6 @@ enum
|
||||||
Set_Logging_InitShutdown,
|
Set_Logging_InitShutdown,
|
||||||
Set_Logging_Interface,
|
Set_Logging_Interface,
|
||||||
Set_Logging_Driver,
|
Set_Logging_Driver,
|
||||||
Set_BufferDivider,
|
Set_TinyBuffer,
|
||||||
Set_BufferLevel,
|
Set_FPSBuffer,
|
||||||
};
|
};
|
Binary file not shown.
Loading…
Reference in New Issue