Update Project64-Audio

This commit is contained in:
Frank-74 2019-01-21 05:45:52 +00:00
parent 25bd63cc9b
commit 5d80fdaaa4
9 changed files with 124 additions and 95 deletions

View File

@ -33,12 +33,15 @@
void SetTimerResolution ( void );
#endif
#define ENDIAN_SWAP_BYTE (~0 & 0x7 & 3)
#define BES(address) ((address) ^ ENDIAN_SWAP_BYTE)
/* Read header for type definition */
AUDIO_INFO g_AudioInfo;
bool g_PluginInit = false;
bool g_romopen = false;
uint32_t g_Dacrate = 0;
uint32_t g_Dacrate = 0, hack = 0;
#ifdef _WIN32
DirectSoundDriver * g_SoundDriver = NULL;
@ -56,7 +59,7 @@ void PluginInit(void)
SetupAudioSettings();
StartTrace();
#ifdef _WIN32
SetTimerResolution();
SetTimerResolution();
#endif
g_PluginInit = true;
}
@ -65,10 +68,10 @@ EXPORT void CALL PluginLoaded(void)
{
PluginInit();
WriteTrace(TraceAudioInterface, TraceDebug, "Called");
if (g_settings != NULL)
{
g_settings->SetSyncViaAudioEnabled(true);
}
if (g_settings != NULL)
{
g_settings->SetSyncViaAudioEnabled(true);
}
}
EXPORT void CALL AiDacrateChanged(int SystemType)
@ -89,36 +92,48 @@ EXPORT void CALL AiDacrateChanged(int SystemType)
WriteTrace(TraceAudioInterface, TraceNotice, "Unknown/reserved bits in AI_DACRATE_REG set. 0x%08X", *g_AudioInfo.AI_DACRATE_REG);
}
uint32_t video_clock = 0; int32_t BufferSize = 0;
double audio_clock = 0; double framerate = (30 / 1.001);
uint32_t video_clock = 0, BufferSize = 0, Frequency = 0, divider = 0;
switch (SystemType)
{
case SYSTEM_NTSC: video_clock = 48681812; break;
case SYSTEM_PAL: video_clock = 49656530; framerate = 25; break;
case SYSTEM_PAL: video_clock = 49656530; break;
case SYSTEM_MPAL: video_clock = 48628316; break;
}
uint32_t Frequency = (video_clock / (g_Dacrate + 1));
if (Frequency < 4000)
Frequency = (video_clock / (g_Dacrate + 1));
if (Frequency < 8000)
{
WriteTrace(TraceAudioDriver, TraceDebug, "Not Audio Data!");
return;
}
else
switch (g_settings->GetBuffer())
{
if (g_settings->FPSBuffer() == false && SystemType != SYSTEM_PAL)
{
framerate = 30.475; // Needed for Body Harvest (U)
}
if (g_settings->TinyBuffer() == false)
{
framerate = (framerate / 2);
}
audio_clock = (video_clock / framerate);
BufferSize = (int32_t)(audio_clock / (g_Dacrate + 1)) + 1 & ~0x1;
g_SoundDriver->AI_SetFrequency(Frequency, BufferSize);
case 1: divider = 50; break;
case 2: divider = 45; break;
case 3: divider = 40; break;
case 4: divider = 30; break;
case 5: divider = 25; break;
case 6: divider = 20; break;
case 7: divider = 15; break;
}
BufferSize = ((Frequency / divider) + (int32_t)2.49 & ~0x3);
if (hack == 'BH' && SystemType != SYSTEM_PAL) BufferSize -= 16;
if (g_settings->RoundFreq())
{
Frequency = ((Frequency / 25) + 1) * 25;
}
WriteTrace(TraceAudioDriver, TraceInfo, "Frequency = %d", Frequency);
WriteTrace(TraceAudioDriver, TraceInfo, "Divider = %.3f", (double)divider);
WriteTrace(TraceAudioDriver, TraceInfo, "Buffer = %d", g_settings->GetBuffer());
WriteTrace(TraceAudioDriver, TraceInfo, "Buffer Size = %d", BufferSize);
g_SoundDriver->AI_SetFrequency(Frequency, BufferSize);
}
WriteTrace(TraceAudioInterface, TraceDebug, "Done");
}
@ -166,12 +181,12 @@ EXPORT void CALL AiUpdate(int32_t Wait)
EXPORT void CALL CloseDLL(void)
{
WriteTrace(TraceAudioInterface, TraceDebug, "Called");
if (g_SoundDriver != NULL)
{
g_SoundDriver->AI_Shutdown();
delete g_SoundDriver;
g_SoundDriver = NULL;
}
if (g_SoundDriver != NULL)
{
g_SoundDriver->AI_Shutdown();
delete g_SoundDriver;
g_SoundDriver = NULL;
}
CleanupAudioSettings();
StopTrace();
}
@ -224,6 +239,11 @@ EXPORT int32_t CALL InitiateAudio(AUDIO_INFO Audio_Info)
#else
g_SoundDriver = new OpenSLESDriver;
#endif
const uint16_t cart_ID = 0x0000
| (g_AudioInfo.HEADER[BES(0x3C)] << 8)
| (g_AudioInfo.HEADER[BES(0x3D)] << 0)
;
hack = cart_ID;
WriteTrace(TraceAudioInterface, TraceDebug, "Done (res: true)");
return true;
}
@ -272,13 +292,13 @@ extern "C" void UseUnregisteredSetting(int /*SettingID*/)
#ifdef _WIN32
void SetTimerResolution(void)
{
HMODULE hMod = GetModuleHandle("ntdll.dll");
if (hMod != NULL)
{
typedef LONG(NTAPI* tNtSetTimerResolution)(IN ULONG DesiredResolution, IN BOOLEAN SetResolution, OUT PULONG CurrentResolution);
tNtSetTimerResolution NtSetTimerResolution = (tNtSetTimerResolution)GetProcAddress(hMod, "NtSetTimerResolution");
ULONG CurrentResolution = 0;
NtSetTimerResolution(10000, TRUE, &CurrentResolution);
}
HMODULE hMod = GetModuleHandle("ntdll.dll");
if (hMod != NULL)
{
typedef LONG(NTAPI* tNtSetTimerResolution)(IN ULONG DesiredResolution, IN BOOLEAN SetResolution, OUT PULONG CurrentResolution);
tNtSetTimerResolution NtSetTimerResolution = (tNtSetTimerResolution)GetProcAddress(hMod, "NtSetTimerResolution");
ULONG CurrentResolution = 0;
NtSetTimerResolution(10000, TRUE, &CurrentResolution);
}
}
#endif

View File

@ -31,8 +31,8 @@ CSettings::CSettings() :
m_advanced_options(false),
m_debugger_enabled(false),
m_Volume(100),
m_TinyBuffer(true),
m_FPSBuffer(true),
m_Buffer(4),
m_RoundFreq(false),
m_FixedAudio(false),
m_SyncAudio(false),
m_FullSpeed(true)
@ -50,6 +50,8 @@ CSettings::CSettings() :
if (m_Set_FullSpeed != 0) { SettingsRegisterChange(true, m_Set_FullSpeed, this, stSettingsChanged); }
if (m_Set_LimitFPS != 0) { SettingsRegisterChange(true, m_Set_LimitFPS, this, stSettingsChanged); }
SettingsRegisterChange(false, Set_Volume, this, stSettingsChanged);
SettingsRegisterChange(false, Set_Buffer, this, stSettingsChanged);
SettingsRegisterChange(false, Set_RoundFreq, this, stSettingsChanged);
SettingsRegisterChange(false, Set_Logging_MD5, this, stLogLevelChanged);
SettingsRegisterChange(false, Set_Logging_Thread, this, stLogLevelChanged);
@ -70,6 +72,8 @@ CSettings::~CSettings()
if (m_Set_FullSpeed != 0) { SettingsUnregisterChange(true, m_Set_FullSpeed, this, stSettingsChanged); }
if (m_Set_LimitFPS != 0) { SettingsUnregisterChange(true, m_Set_LimitFPS, this, stSettingsChanged); }
SettingsUnregisterChange(false, Set_Volume, this, stSettingsChanged);
SettingsUnregisterChange(false, Set_Buffer, this, stSettingsChanged);
SettingsUnregisterChange(false, Set_RoundFreq, this, stSettingsChanged);
SettingsUnregisterChange(false, Set_Logging_MD5, this, stLogLevelChanged);
SettingsUnregisterChange(false, Set_Logging_Thread, this, stLogLevelChanged);
@ -101,8 +105,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_TinyBuffer, Data_DWORD_Game, "TinyBuffer", "", (bool)true, NULL);
RegisterSetting(Set_FPSBuffer, Data_DWORD_Game, "FPSBuffer", "", (bool)true, NULL);
RegisterSetting(Set_RoundFreq, Data_DWORD_General, "RoundFrequency", "Settings", (bool)false, NULL);
RegisterSetting(Set_Buffer, Data_DWORD_Game, "Buffer", "", 4, NULL);
LogLevelChanged();
}
@ -130,14 +134,14 @@ void CSettings::SetVolume(uint32_t Volume)
}
}
void CSettings::SetTinyBuffer(bool TinyBuffer)
void CSettings::SetBuffer(uint32_t Buffer)
{
SetSetting(Set_TinyBuffer, TinyBuffer ? 1 : 0);
SetSetting(Set_Buffer, Buffer);
}
void CSettings::SetFPSBuffer(bool FPSBuffer)
void CSettings::SetRoundFreq(bool RoundFreq)
{
SetSetting(Set_FPSBuffer, FPSBuffer ? 1 : 0);
SetSetting(Set_RoundFreq, RoundFreq ? 1 : 0);
}
void CSettings::LogLevelChanged(void)
@ -153,15 +157,14 @@ void CSettings::LogLevelChanged(void)
void CSettings::ReadSettings(void)
{
bool bLimitFPS = m_Set_LimitFPS ? GetSystemSetting(m_Set_LimitFPS) != 0 : true;
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_TinyBuffer = GetSetting(Set_TinyBuffer) != 0;
m_FPSBuffer = GetSetting(Set_FPSBuffer) != 0;
m_RoundFreq = GetSetting(Set_RoundFreq) != 0;
m_Buffer = GetSetting(Set_Buffer);
m_FullSpeed = m_Set_FullSpeed ? GetSystemSetting(m_Set_FullSpeed) != 0 : false;
m_FixedAudio = m_Set_FixedAudio ? GetSystemSetting(m_Set_FixedAudio) != 0 : false;
m_SyncAudio = (!m_advanced_options || bLimitFPS);
if (m_Set_log_dir != 0)

View File

@ -19,18 +19,19 @@ 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 bool TinyBuffer(void) const { return m_TinyBuffer; }
inline bool FPSBuffer(void) const { return m_FPSBuffer; }
inline uint32_t GetBuffer(void) const { return m_Buffer; }
inline bool RoundFreq(void) const { return m_RoundFreq; }
inline bool FixedAudio(void) const { return m_FixedAudio; }
inline bool SyncAudio(void) const { return m_SyncAudio; }
inline bool FullSpeed(void) const { return m_FullSpeed; }
inline bool FlushLogs(void) const { return m_FlushLogs; }
inline const char * log_dir(void) const { return m_log_dir; }
void SetSyncViaAudioEnabled(bool Enabled);
void SetAudioEnabled(bool Enabled);
void SetVolume(uint32_t Volume);
void SetTinyBuffer(bool TinyBuffer);
void SetFPSBuffer(bool FPSBuffer);
void SetSyncViaAudioEnabled(bool Enabled);
void SetAudioEnabled(bool Enabled);
void SetVolume(uint32_t Volume);
void SetBuffer(uint32_t Buffer);
void SetRoundFreq(bool RoundFreq);
void ReadSettings();
private:
@ -62,8 +63,8 @@ private:
bool m_advanced_options;
bool m_debugger_enabled;
uint32_t m_Volume;
bool m_TinyBuffer;
bool m_FPSBuffer;
uint32_t m_Buffer;
bool m_RoundFreq;
bool m_FixedAudio;
bool m_SyncAudio;
bool m_FullSpeed;

View File

@ -54,6 +54,7 @@ public:
BEGIN_MSG_MAP(CDebugSettings)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER_EX(IDC_MUTE, ItemChanged)
COMMAND_ID_HANDLER_EX(IDC_ROUND, ItemChanged)
NOTIFY_HANDLER_EX(IDC_VOLUME, NM_RELEASEDCAPTURE, ItemChangedNotify);
CHAIN_MSG_MAP(CPropertyPageImpl<CGeneralSettings>)
END_MSG_MAP()
@ -68,6 +69,8 @@ public:
m_Volume.SetTicFreq(20);
m_Volume.SetRangeMin(0);
m_Volume.SetRangeMax(100);
m_btnRound.Attach(GetDlgItem(IDC_ROUND));
m_btnRound.SetCheck(g_settings->RoundFreq() ? BST_CHECKED : BST_UNCHECKED);
return TRUE;
}
@ -75,6 +78,7 @@ public:
{
g_settings->SetAudioEnabled(m_btnMute.GetCheck() != BST_CHECKED);
g_settings->SetVolume(100 - m_Volume.GetPos());
g_settings->SetRoundFreq(m_btnRound.GetCheck() == BST_CHECKED);
FlushSettings();
return true;
}
@ -89,10 +93,12 @@ private:
void ItemChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
g_settings->SetRoundFreq(m_btnRound.GetCheck() == BST_CHECKED);
}
CTrackBarCtrl m_Volume;
CButton m_btnMute;
CButton m_btnRound;
};
class CGameSettings :
@ -103,37 +109,40 @@ public:
BEGIN_MSG_MAP(CDebugSettings)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER_EX(IDC_TINYBUFFER, ItemChanged)
COMMAND_ID_HANDLER_EX(IDC_FPSBUFFER, ItemChanged)
CHAIN_MSG_MAP(CPropertyPageImpl<CGameSettings>)
NOTIFY_HANDLER_EX(IDC_BUFFER, NM_RELEASEDCAPTURE, ItemChangedNotify);
CHAIN_MSG_MAP(CPropertyPageImpl<CGameSettings>)
END_MSG_MAP()
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
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);
m_Buffer.Attach(GetDlgItem(IDC_BUFFER));
m_Buffer.SetTicFreq(1);
m_Buffer.SetRangeMin(1);
m_Buffer.SetRangeMax(7);
m_Buffer.SetPos(g_settings->GetBuffer());
return TRUE;
}
bool OnApply()
{
g_settings->SetTinyBuffer(m_btnTinyBuffer.GetCheck() == BST_CHECKED);
g_settings->SetFPSBuffer(m_btnFPSBuffer.GetCheck() == BST_CHECKED);
g_settings->SetBuffer(m_Buffer.GetPos());
FlushSettings();
return true;
}
private:
CButton m_btnTinyBuffer;
CButton m_btnFPSBuffer;
CTrackBarCtrl m_Buffer;
void ItemChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
g_settings->SetTinyBuffer(m_btnTinyBuffer.GetCheck() == BST_CHECKED);
g_settings->SetFPSBuffer(m_btnFPSBuffer.GetCheck() == BST_CHECKED);
}
LRESULT ItemChangedNotify(NMHDR* /*pNMHDR*/)
{
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
g_settings->SetBuffer(m_Buffer.GetPos());
return 0;
}
};

View File

@ -123,7 +123,7 @@ void DirectSoundDriver::SetFrequency(uint32_t Frequency, uint32_t BufferSize)
{
WriteTrace(TraceAudioDriver, TraceDebug, "Start (Frequency: 0x%08X)", Frequency);
StopAudio();
m_LOCK_SIZE = (BufferSize * 2);
m_LOCK_SIZE = (BufferSize * 4);
SetSegmentSize(m_LOCK_SIZE, Frequency);
StartAudio();

View File

@ -37,12 +37,7 @@ bool SoundDriverBase::Initialize()
void SoundDriverBase::AI_SetFrequency(uint32_t Frequency, uint32_t BufferSize)
{
SetFrequency(Frequency, BufferSize);
m_MaxBufferSize = (BufferSize * 4);
if (g_settings->TinyBuffer() == true)
{
m_MaxBufferSize = m_MaxBufferSize * 2;
}
m_BufferRemaining = 0;
m_MaxBufferSize = (BufferSize * 8);
m_CurrentReadLoc = m_CurrentWriteLoc = m_BufferRemaining = 0;
}

View File

@ -18,6 +18,7 @@
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
@ -58,6 +59,7 @@ BEGIN
CONTROL "",IDC_VOLUME,"msctls_trackbar32",TBS_AUTOTICKS | TBS_VERT | TBS_BOTH | WS_BORDER | WS_TABSTOP,8,14,32,67,WS_EX_STATICEDGE
GROUPBOX "Volume",IDC_STATIC,3,3,45,94
CONTROL "Mute",IDC_MUTE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,83,32,10
CONTROL "Rounded Frequencies",IDC_ROUND,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,103,85,10
END
IDD_LOG_SETTINGS DIALOGEX 0, 0, 311, 177
@ -83,8 +85,8 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSM
CAPTION "Game Settings"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "FPS Buffer",IDC_FPSBUFFER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,18,50,10
CONTROL "Tiny Buffer",IDC_TINYBUFFER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,36,51,10
CONTROL "",IDC_BUFFER,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,35,79,240,19
GROUPBOX "Buffer Size",IDC_BUFFERTEXT,31,67,249,44,BS_CENTER
END
@ -139,13 +141,13 @@ BEGIN
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", VER_FILE_DESCRIPTION_STR "\0"
VALUE "FileVersion", VER_FILE_VERSION_STR "\0"
VALUE "InternalName", VER_INTERNAL_NAME_STR "\0"
VALUE "LegalCopyright", VER_COPYRIGHT_STR "\0"
VALUE "FileDescription", VER_FILE_DESCRIPTION_STR "\0"
VALUE "FileVersion", VER_FILE_VERSION_STR "\0"
VALUE "InternalName", VER_INTERNAL_NAME_STR "\0"
VALUE "LegalCopyright", VER_COPYRIGHT_STR "\0"
VALUE "OriginalFilename", VER_ORIGINAL_FILENAME_STR "\0"
VALUE "ProductName", VER_PRODUCTNAME_STR
VALUE "ProductVersion", VER_PRODUCT_VERSION_STR "\0"
VALUE "ProductName", VER_PRODUCTNAME_STR
VALUE "ProductVersion", VER_PRODUCT_VERSION_STR "\0"
END
END
BLOCK "VarFileInfo"

View File

@ -20,6 +20,6 @@ enum
Set_Logging_InitShutdown,
Set_Logging_Interface,
Set_Logging_Driver,
Set_TinyBuffer,
Set_FPSBuffer,
Set_Buffer,
Set_RoundFreq,
};

View File

@ -9,13 +9,12 @@
#define IDD_CONFIG 9
#define IDD_LOG_SETTINGS 103
#define IDD_GAME_SETTING 104
#define IDC_BUFFER_DIVIDER 1001
#define IDC_BUFFER_LEVEL 1002
#define IDC_VOLUME 1003
#define IDC_MUTE 1004
#define IDC_FPSBUFFER 1004
#define IDC_CHECK2 1005
#define IDC_TINYBUFFER 1005
#define VERSION_BUILD 835
#define IDC_VOLUME 1001
#define IDC_MUTE 1002
#define IDC_BUFFER 1003
#define IDC_ROUND 1004
#define IDC_BUFFERTEXT 1005
#define IDC_CMB_TRACE_PATH 1019
#define IDC_CMB_TRACE_INIT_SHUTDOWN 1020
#define IDC_CMB_TRACE_INTERFACE 1021