diff --git a/Source/Project64-audio/AudioMain.cpp b/Source/Project64-audio/AudioMain.cpp index 08d3ba5f2..507359d1d 100644 --- a/Source/Project64-audio/AudioMain.cpp +++ b/Source/Project64-audio/AudioMain.cpp @@ -86,6 +86,15 @@ EXPORT void CALL AiDacrateChanged(int SystemType) case SYSTEM_MPAL: video_clock = 48628316; break; } 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; } + g_SoundDriver->AI_SetFrequency(Frequency); } WriteTrace(TraceAudioInterface, TraceDebug, "Done"); diff --git a/Source/Project64-audio/AudioSettings.cpp b/Source/Project64-audio/AudioSettings.cpp index 86aefe22e..8f7044de0 100644 --- a/Source/Project64-audio/AudioSettings.cpp +++ b/Source/Project64-audio/AudioSettings.cpp @@ -19,6 +19,7 @@ CSettings::CSettings() : m_Set_EnableAudio(0), m_Set_SyncAudio(0), m_Set_FullSpeed(0), + m_Set_LimitFPS(0), m_Set_basic_mode(0), m_Set_debugger(0), m_Set_log_dir(0), @@ -43,6 +44,7 @@ CSettings::CSettings() : if (m_Set_log_flush != 0) { SettingsRegisterChange(true, m_Set_log_flush, this, stSettingsChanged); } if (m_Set_SyncAudio != 0) { SettingsRegisterChange(true, m_Set_SyncAudio, this, stSettingsChanged); } 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_Logging_MD5, this, stLogLevelChanged); @@ -61,6 +63,7 @@ CSettings::~CSettings() if (m_Set_log_flush != 0) { SettingsUnregisterChange(true, m_Set_log_flush, this, stSettingsChanged); } if (m_Set_SyncAudio != 0) { SettingsUnregisterChange(true, m_Set_SyncAudio, this, stSettingsChanged); } 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_Logging_MD5, this, stLogLevelChanged); @@ -77,6 +80,7 @@ void CSettings::RegisterSettings(void) m_Set_EnableAudio = FindSystemSettingId("Enable Audio"); m_Set_SyncAudio = FindSystemSettingId("Sync Audio"); m_Set_FullSpeed = FindSystemSettingId("Full Speed"); + m_Set_LimitFPS = FindSystemSettingId("Limit FPS"); m_Set_basic_mode = FindSystemSettingId("Basic Mode"); m_Set_debugger = FindSystemSettingId("Debugger"); m_Set_log_flush = FindSystemSettingId("Log Auto Flush"); @@ -133,15 +137,19 @@ void CSettings::LogLevelChanged(void) void CSettings::ReadSettings(void) { + bool SyncAudio = m_Set_SyncAudio ? GetSystemSetting(m_Set_SyncAudio) != 0 : false; + 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_BufferDivider = GetSetting(Set_BufferDivider); m_BufferLevel = GetSetting(Set_BufferLevel); - m_SyncAudio = m_Set_SyncAudio ? GetSystemSetting(m_Set_SyncAudio) != 0 : false; m_FullSpeed = m_Set_FullSpeed ? GetSystemSetting(m_Set_FullSpeed) != 0 : false; + m_SyncAudio = ((!m_advanced_options || bLimitFPS) && SyncAudio && m_FullSpeed); + if (m_Set_log_dir != 0) { GetSystemSettingSz(m_Set_log_dir, m_log_dir, sizeof(m_log_dir)); diff --git a/Source/Project64-audio/AudioSettings.h b/Source/Project64-audio/AudioSettings.h index da4a79e9c..dd7cd40ea 100644 --- a/Source/Project64-audio/AudioSettings.h +++ b/Source/Project64-audio/AudioSettings.h @@ -48,6 +48,7 @@ private: short m_Set_EnableAudio; short m_Set_SyncAudio; short m_Set_FullSpeed; + short m_Set_LimitFPS; short m_Set_basic_mode; short m_Set_debugger; short m_Set_log_dir; diff --git a/Source/Project64-audio/Driver/DirectSound.cpp b/Source/Project64-audio/Driver/DirectSound.cpp index 19d2df018..64c7d91e5 100644 --- a/Source/Project64-audio/Driver/DirectSound.cpp +++ b/Source/Project64-audio/Driver/DirectSound.cpp @@ -70,7 +70,7 @@ bool DirectSoundDriver::Initialize() WAVEFORMATEX wfm = { 0 }; wfm.wFormatTag = WAVE_FORMAT_PCM; wfm.nChannels = 2; - wfm.nSamplesPerSec = 44100; + wfm.nSamplesPerSec = 48000; wfm.wBitsPerSample = 16; wfm.nBlockAlign = wfm.wBitsPerSample / 8 * wfm.nChannels; wfm.nAvgBytesPerSec = wfm.nSamplesPerSec * wfm.nBlockAlign; @@ -206,7 +206,7 @@ void DirectSoundDriver::AudioThreadProc() break; } // Check to see if the audio pointer moved on to the next segment - if (write_pos == last_pos) + if (write_pos == 0) { WriteTrace(TraceAudioDriver, TraceVerbose, "Sleep"); Sleep(1); diff --git a/Source/Project64-audio/Driver/SoundBase.cpp b/Source/Project64-audio/Driver/SoundBase.cpp index ac1529744..d62b67854 100644 --- a/Source/Project64-audio/Driver/SoundBase.cpp +++ b/Source/Project64-audio/Driver/SoundBase.cpp @@ -108,7 +108,7 @@ void SoundDriverBase::AI_Update(bool Wait) uint32_t SoundDriverBase::AI_ReadLength() { CGuard guard(m_CS); - return m_AI_DMAPrimaryBytes & ~0x3; + return m_AI_DMAPrimaryBytes & ~0x7; } void SoundDriverBase::LoadAiBuffer(uint8_t *start, uint32_t length) diff --git a/Source/Project64-audio/Driver/SoundBase.h b/Source/Project64-audio/Driver/SoundBase.h index 61b9895f2..4d20907ac 100644 --- a/Source/Project64-audio/Driver/SoundBase.h +++ b/Source/Project64-audio/Driver/SoundBase.h @@ -30,7 +30,7 @@ public: virtual void StopAudio(); protected: - enum { MAX_SIZE = 44100 * 2 * 2 }; // Max Buffer Size (44100Hz * 16bit * Stereo) + enum { MAX_SIZE = 48000 * 2 * 2 }; // Max Buffer Size (44100Hz * 16bit * Stereo) virtual bool Initialize(); void LoadAiBuffer(uint8_t *start, uint32_t length); // Reads in length amount of audio bytes diff --git a/Source/Project64-core/Settings/SettingType/SettingsType-TempBool.cpp b/Source/Project64-core/Settings/SettingType/SettingsType-TempBool.cpp index 66078bfb4..13a0231d8 100644 --- a/Source/Project64-core/Settings/SettingType/SettingsType-TempBool.cpp +++ b/Source/Project64-core/Settings/SettingType/SettingsType-TempBool.cpp @@ -27,10 +27,10 @@ bool CSettingTypeTempBool::Load(int /*Index*/, bool & Value) const return true; } -bool CSettingTypeTempBool::Load(int /*Index*/, uint32_t & /*Value*/) const +bool CSettingTypeTempBool::Load(int /*Index*/, uint32_t & Value) const { - g_Notify->BreakPoint(__FILE__, __LINE__); - return false; + Value = m_value ? 1 : 0; + return true; } bool CSettingTypeTempBool::Load(int /*Index*/, stdstr & /*Value*/) const diff --git a/Source/Project64-core/Settings/SettingsClass.cpp b/Source/Project64-core/Settings/SettingsClass.cpp index 902293761..34f41cfa9 100644 --- a/Source/Project64-core/Settings/SettingsClass.cpp +++ b/Source/Project64-core/Settings/SettingsClass.cpp @@ -299,7 +299,7 @@ void CSettings::AddHowToHandleSetting(const char * BaseDirectory) AddHandler(GameRunning_CPU_Paused, new CSettingTypeTempBool(false)); AddHandler(GameRunning_CPU_PausedType, new CSettingTypeTempNumber(Default_None)); AddHandler(GameRunning_InstantSaveFile, new CSettingTypeTempString("")); - AddHandler(GameRunning_LimitFPS, new CSettingTypeTempBool(true)); + AddHandler(GameRunning_LimitFPS, new CSettingTypeTempBool(true, "Limit FPS")); AddHandler(GameRunning_ScreenHertz, new CSettingTypeTempNumber(60)); AddHandler(GameRunning_InReset, new CSettingTypeTempBool(false));