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);
|
||||
|
||||
if ((Frequency > 7000) && (Frequency < 9000)) { Frequency = 8000; }
|
||||
else if ((Frequency > 10000) && (Frequency < 12000)) { Frequency = 11025; }
|
||||
else if ((Frequency > 15000) && (Frequency < 17000)) { Frequency = 16000; }
|
||||
else if ((Frequency > 21000) && (Frequency < 23000)) { Frequency = 22050; }
|
||||
else if ((Frequency > 31000) && (Frequency < 33000)) { Frequency = 32000; }
|
||||
else if ((Frequency > 43000) && (Frequency < 45000)) { Frequency = 44100; }
|
||||
else if ((Frequency > 47000) && (Frequency < 49000)) { Frequency = 48000; }
|
||||
if (Frequency < 4000)
|
||||
{
|
||||
WriteTrace(TraceAudioDriver, TraceDebug, "Not Audio Data!");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
@ -135,7 +156,7 @@ EXPORT void CALL AiUpdate(int32_t Wait)
|
|||
}
|
||||
else
|
||||
{
|
||||
pjutil::Sleep(1);
|
||||
pjutil::Sleep(1); // TODO: Fixme -- Ai Update appears to be problematic
|
||||
}
|
||||
WriteTrace(TraceAudioInterface, TraceDebug, "Done");
|
||||
}
|
||||
|
@ -233,4 +254,4 @@ extern "C" void UseUnregisteredSetting(int /*SettingID*/)
|
|||
#ifdef _WIN32
|
||||
DebugBreak();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ CSettings::CSettings() :
|
|||
m_advanced_options(false),
|
||||
m_debugger_enabled(false),
|
||||
m_Volume(100),
|
||||
m_BufferDivider(90),
|
||||
m_BufferLevel(4),
|
||||
m_TinyBuffer(true),
|
||||
m_FPSBuffer(true),
|
||||
m_SyncAudio(false),
|
||||
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_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_TinyBuffer, Data_DWORD_Game, "TinyBuffer", "", (bool)true, NULL);
|
||||
RegisterSetting(Set_FPSBuffer, Data_DWORD_Game, "FPSBuffer", "", (bool)true, NULL);
|
||||
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)
|
||||
|
@ -144,8 +144,8 @@ void CSettings::ReadSettings(void)
|
|||
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_TinyBuffer = GetSetting(Set_TinyBuffer) != 0;
|
||||
m_FPSBuffer = GetSetting(Set_FPSBuffer) != 0;
|
||||
m_FullSpeed = m_Set_FullSpeed ? GetSystemSetting(m_Set_FullSpeed) != 0 : false;
|
||||
|
||||
m_SyncAudio = ((!m_advanced_options || bLimitFPS) && SyncAudio && m_FullSpeed);
|
||||
|
@ -172,4 +172,4 @@ void CleanupAudioSettings(void)
|
|||
delete g_settings;
|
||||
g_settings = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ 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 TinyBuffer(void) const { return m_TinyBuffer; }
|
||||
inline bool FPSBuffer(void) const { return m_FPSBuffer; }
|
||||
inline bool SyncAudio(void) const { return m_SyncAudio; }
|
||||
inline bool FullSpeed(void) const { return m_FullSpeed; }
|
||||
inline bool FlushLogs(void) const { return m_FlushLogs; }
|
||||
|
@ -28,8 +28,8 @@ public:
|
|||
|
||||
void SetAudioEnabled(bool Enabled);
|
||||
void SetVolume(uint32_t Volume);
|
||||
void SetBufferDivider(uint32_t BufferDivider);
|
||||
void SetBufferLevel(uint32_t BufferLevel);
|
||||
void SetTinyBuffer(bool TinyBuffer);
|
||||
void SetFPSBuffer(bool FPSBuffer);
|
||||
void ReadSettings();
|
||||
|
||||
private:
|
||||
|
@ -59,8 +59,8 @@ private:
|
|||
bool m_advanced_options;
|
||||
bool m_debugger_enabled;
|
||||
uint32_t m_Volume;
|
||||
uint32_t m_BufferDivider;
|
||||
uint32_t m_BufferLevel;
|
||||
bool m_TinyBuffer;
|
||||
bool m_FPSBuffer;
|
||||
bool m_SyncAudio;
|
||||
bool m_FullSpeed;
|
||||
};
|
||||
|
|
|
@ -103,47 +103,37 @@ public:
|
|||
|
||||
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)
|
||||
COMMAND_ID_HANDLER_EX(IDC_TINYBUFFER, ItemChanged)
|
||||
COMMAND_ID_HANDLER_EX(IDC_FPSBUFFER, 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_btnTinyBuffer.Attach(GetDlgItem(IDC_TINYBUFFER));
|
||||
m_btnTinyBuffer.SetCheck(g_settings->TinyBuffer() ? BST_CHECKED : BST_UNCHECKED);
|
||||
m_btnFPSBuffer.Attach(GetDlgItem(IDC_FPSBUFFER));
|
||||
m_btnFPSBuffer.SetCheck(g_settings->FPSBuffer() ? 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->SetTinyBuffer(m_btnTinyBuffer.GetCheck() == BST_CHECKED);
|
||||
g_settings->SetFPSBuffer(m_btnFPSBuffer.GetCheck() == BST_CHECKED);
|
||||
FlushSettings();
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
CEdit m_BufferDivider;
|
||||
CEdit m_BufferLevel;
|
||||
CButton m_btnTinyBuffer;
|
||||
CButton m_btnFPSBuffer;
|
||||
|
||||
LRESULT ItemChangedNotify(NMHDR* /*pNMHDR*/)
|
||||
void ItemChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
|
||||
{
|
||||
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;
|
||||
g_settings->SetTinyBuffer(m_btnTinyBuffer.GetCheck() == BST_CHECKED);
|
||||
g_settings->SetFPSBuffer(m_btnFPSBuffer.GetCheck() == BST_CHECKED);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -271,4 +261,4 @@ CAudioUI::~CAudioUI()
|
|||
void ConfigAudio(void * hParent)
|
||||
{
|
||||
CAudioUI().DoModal((HWND)hParent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,11 +119,11 @@ void DirectSoundDriver::StartAudio()
|
|||
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);
|
||||
StopAudio();
|
||||
m_LOCK_SIZE = (uint32_t)((Frequency / g_settings->BufferDivider())) * 4;
|
||||
m_LOCK_SIZE = (BufferSize * 2);
|
||||
SetSegmentSize(m_LOCK_SIZE, Frequency);
|
||||
|
||||
StartAudio();
|
||||
|
@ -132,10 +132,16 @@ void DirectSoundDriver::SetFrequency(uint32_t Frequency)
|
|||
|
||||
void DirectSoundDriver::SetVolume(uint32_t Volume)
|
||||
{
|
||||
/*DWORD dsVolume = ((DWORD)Volume * -25);
|
||||
if (Volume == 100) dsVolume = (DWORD)DSBVOLUME_MIN;
|
||||
if (Volume == 0) dsVolume = DSBVOLUME_MAX;
|
||||
if (lpdsb != NULL) lpdsb->SetVolume(dsVolume);*/
|
||||
LPDIRECTSOUNDBUFFER & lpdsb = (LPDIRECTSOUNDBUFFER &)m_lpdsb;
|
||||
int32_t dsVolume = -((100 - (int32_t)Volume) * 25);
|
||||
if (Volume == 0)
|
||||
{
|
||||
dsVolume = DSBVOLUME_MIN;
|
||||
}
|
||||
if (lpdsb != NULL)
|
||||
{
|
||||
lpdsb->SetVolume(dsVolume);
|
||||
}
|
||||
}
|
||||
|
||||
void DirectSoundDriver::SetSegmentSize(uint32_t length, uint32_t SampleRate)
|
||||
|
@ -278,4 +284,4 @@ void DirectSoundDriver::AudioThreadProc()
|
|||
lpdsbuf->Stop();
|
||||
}
|
||||
WriteTrace(TraceAudioDriver, TraceDebug, "Audio Thread Terminated...");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
bool Initialize();
|
||||
void StopAudio(); // Stops the Audio PlayBack (as if paused)
|
||||
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);
|
||||
|
||||
private:
|
||||
|
@ -37,4 +37,4 @@ private:
|
|||
void * m_lpdsbuf;
|
||||
void * m_handleAudioThread;
|
||||
uint32_t m_dwAudioThreadId;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -34,10 +34,10 @@ bool SoundDriverBase::Initialize()
|
|||
return true;
|
||||
}
|
||||
|
||||
void SoundDriverBase::AI_SetFrequency(uint32_t Frequency)
|
||||
void SoundDriverBase::AI_SetFrequency(uint32_t Frequency, uint32_t BufferSize)
|
||||
{
|
||||
SetFrequency(Frequency);
|
||||
m_MaxBufferSize = (uint32_t)((Frequency / g_settings->BufferDivider())) * 4 * g_settings->BufferLevel();
|
||||
SetFrequency(Frequency, BufferSize);
|
||||
m_MaxBufferSize = (BufferSize * 4);
|
||||
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);
|
||||
}
|
||||
|
||||
void SoundDriverBase::SetFrequency(uint32_t /*Frequency*/)
|
||||
void SoundDriverBase::SetFrequency(uint32_t /*Frequency*/, uint32_t /*Divider*/)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -197,4 +197,4 @@ void SoundDriverBase::StartAudio()
|
|||
|
||||
void SoundDriverBase::StopAudio()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,14 @@ class SoundDriverBase
|
|||
public:
|
||||
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_Startup();
|
||||
void AI_Shutdown();
|
||||
void AI_Update(bool Wait);
|
||||
uint32_t AI_ReadLength();
|
||||
|
||||
virtual void SetFrequency(uint32_t Frequency);
|
||||
virtual void SetFrequency(uint32_t Frequency, uint32_t BufferSize);
|
||||
virtual void StartAudio();
|
||||
virtual void StopAudio();
|
||||
|
||||
|
|
Binary file not shown.
|
@ -20,6 +20,6 @@ enum
|
|||
Set_Logging_InitShutdown,
|
||||
Set_Logging_Interface,
|
||||
Set_Logging_Driver,
|
||||
Set_BufferDivider,
|
||||
Set_BufferLevel,
|
||||
};
|
||||
Set_TinyBuffer,
|
||||
Set_FPSBuffer,
|
||||
};
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue