From 0c6ceee210e8dcb088ec2abf2db7c3ccaffda6ef Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 11 Jan 2015 17:28:46 +0100 Subject: [PATCH] Optimize the resampler a little. Update native with new ability to not force 44khz so we actually get any use. This causes Nexus 4 and Nexus 9 to end up on the fast path, greatly decreasing audio latency! This also removes the "atomic audio" setting as the new audio code is lock-free always. --- Core/Config.cpp | 2 -- Core/Config.h | 1 - Core/HW/StereoResampler.cpp | 43 +++++++++++-------------------------- Core/HW/StereoResampler.h | 4 ---- UI/GameSettingsScreen.cpp | 2 -- UI/NativeApp.cpp | 4 +++- 6 files changed, 16 insertions(+), 40 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index bbb5ccf899..60e96feed7 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -334,8 +334,6 @@ static bool DefaultForceFlushToZero() { static ConfigSetting cpuSettings[] = { ReportedConfigSetting("Jit", &g_Config.bJit, &DefaultJit, true, true), ReportedConfigSetting("SeparateCPUThread", &g_Config.bSeparateCPUThread, false, true, true), - ConfigSetting("AtomicAudioLocks", &g_Config.bAtomicAudioLocks, false, true, true), - ReportedConfigSetting("SeparateIOThread", &g_Config.bSeparateIOThread, true, true, true), ReportedConfigSetting("IOTimingMethod", &g_Config.iIOTimingMethod, IOTIMING_FAST, true, true), ConfigSetting("FastMemoryAccess", &g_Config.bFastMemory, true, true, true), diff --git a/Core/Config.h b/Core/Config.h index 7a3c825483..db12106ba8 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -118,7 +118,6 @@ public: bool bSeparateCPUThread; int iIOTimingMethod; bool bSeparateIOThread; - bool bAtomicAudioLocks; int iLockedCPUSpeed; bool bAutoSaveSymbolMap; bool bCacheFullIsoInRam; diff --git a/Core/HW/StereoResampler.cpp b/Core/HW/StereoResampler.cpp index 5e63e3223e..b08dfbe05b 100644 --- a/Core/HW/StereoResampler.cpp +++ b/Core/HW/StereoResampler.cpp @@ -71,20 +71,16 @@ unsigned int StereoResampler::MixerFifo::Mix(short* samples, unsigned int numSam u32 indexR = Common::AtomicLoad(m_indexR); u32 indexW = Common::AtomicLoad(m_indexW); + // Drift prevention mechanism float numLeft = (float)(((indexW - indexR) & INDEX_MASK) / 2); m_numLeftI = (numLeft + m_numLeftI*(CONTROL_AVG - 1)) / CONTROL_AVG; float offset = (m_numLeftI - LOW_WATERMARK) * CONTROL_FACTOR; if (offset > MAX_FREQ_SHIFT) offset = MAX_FREQ_SHIFT; if (offset < -MAX_FREQ_SHIFT) offset = -MAX_FREQ_SHIFT; - // render numleft sample pairs to samples[] - // advance indexR with sample position - // remember fractional offset - - float aid_sample_rate = m_input_sample_rate + offset; - /* + /* Hm? u32 framelimit = SConfig::GetInstance().m_Framelimit; if (consider_framelimit && framelimit > 1) { aid_sample_rate = aid_sample_rate * (framelimit - 1) * 5 / 59.994; @@ -96,21 +92,14 @@ unsigned int StereoResampler::MixerFifo::Mix(short* samples, unsigned int numSam // TODO: Add a fast path for 1:1. for (; currentSample < numSamples * 2 && ((indexW - indexR) & INDEX_MASK) > 2; currentSample += 2) { u32 indexR2 = indexR + 2; //next sample - s16 l1 = m_buffer[indexR & INDEX_MASK]; //current - s16 l2 = m_buffer[indexR2 & INDEX_MASK]; //next - int sampleL = ((l1 << 16) + (l2 - l1) * (u16)m_frac) >> 16; - sampleL += samples[currentSample + 1]; - MathUtil::Clamp(&sampleL, -32767, 32767); - samples[currentSample + 1] = sampleL; - s16 r1 = m_buffer[(indexR + 1) & INDEX_MASK]; //current + s16 l2 = m_buffer[indexR2 & INDEX_MASK]; //next s16 r2 = m_buffer[(indexR2 + 1) & INDEX_MASK]; //next + int sampleL = ((l1 << 16) + (l2 - l1) * (u16)m_frac) >> 16; int sampleR = ((r1 << 16) + (r2 - r1) * (u16)m_frac) >> 16; - sampleR += samples[currentSample]; - MathUtil::Clamp(&sampleR, -32767, 32767); - samples[currentSample] = sampleR; - + samples[currentSample] = clamp_s16(sampleL); // Do we even need to clamp after interpolation? + samples[currentSample + 1] = clamp_s16(sampleR); m_frac += ratio; indexR += 2 * (u16)(m_frac >> 16); m_frac &= 0xffff; @@ -120,23 +109,19 @@ unsigned int StereoResampler::MixerFifo::Mix(short* samples, unsigned int numSam // Padding with the last value to reduce clicking short s[2]; - s[0] = m_buffer[(indexR - 1) & INDEX_MASK]; - s[1] = m_buffer[(indexR - 2) & INDEX_MASK]; + s[0] = clamp_s16(m_buffer[(indexR - 1) & INDEX_MASK]); + s[1] = clamp_s16(m_buffer[(indexR - 2) & INDEX_MASK]); for (; currentSample < numSamples * 2; currentSample += 2) { - int sampleR = s[0] + samples[currentSample]; - MathUtil::Clamp(&sampleR, -32767, 32767); - samples[currentSample] = sampleR; - int sampleL = s[1] + samples[currentSample + 1]; - MathUtil::Clamp(&sampleL, -32767, 32767); - samples[currentSample + 1] = sampleL; + samples[currentSample] = s[0]; + samples[currentSample + 1] = s[1]; } // Flush cached variable Common::AtomicStore(m_indexR, indexR); - if (realSamples != numSamples * 2) { - ILOG("Underrun! %i / %i", realSamples / 2, numSamples); - } + //if (realSamples != numSamples * 2) { + // ILOG("Underrun! %i / %i", realSamples / 2, numSamples); + //} return realSamples / 2; } @@ -145,8 +130,6 @@ unsigned int StereoResampler::Mix(short* samples, unsigned int num_samples, bool if (!samples) return 0; - lock_guard lk(m_csMixing); - memset(samples, 0, num_samples * 2 * sizeof(short)); return m_dma_mixer.Mix(samples, num_samples, consider_framelimit, sample_rate); } diff --git a/Core/HW/StereoResampler.h b/Core/HW/StereoResampler.h index 7a3a9a3a0b..b0c1e7aeb0 100644 --- a/Core/HW/StereoResampler.h +++ b/Core/HW/StereoResampler.h @@ -57,8 +57,6 @@ public: void SetDMAInputSampleRate(unsigned int rate); - recursive_mutex& MixerCritical() { return m_csMixing; } - float GetCurrentSpeed() const { return m_speed; } void UpdateSpeed(volatile float val) { m_speed = val; } @@ -99,7 +97,5 @@ protected: MixerFifo m_dma_mixer; unsigned int m_sampleRate; - recursive_mutex m_csMixing; - volatile float m_speed; // Current rate of the emulation (1.0 = 100% speed) }; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index a6b80f6072..2b1e61f949 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -428,8 +428,6 @@ void GameSettingsScreen::CreateViews() { #endif systemSettings->Add(new CheckBox(&g_Config.bSetRoundingMode, s->T("Respect FPU rounding (disable for old GEB saves)")))->OnClick.Handle(this, &GameSettingsScreen::OnJitAffectingSetting); - systemSettings->Add(new CheckBox(&g_Config.bAtomicAudioLocks, s->T("Atomic Audio locks (experimental)")))->SetEnabled(!PSP_IsInited()); - systemSettings->Add(new ItemHeader(s->T("Developer Tools"))); systemSettings->Add(new Choice(s->T("Developer Tools")))->OnClick.Handle(this, &GameSettingsScreen::OnDeveloperTools); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index e78f5d7568..1b7547adcd 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -219,8 +219,10 @@ std::string NativeQueryConfig(std::string query) { sprintf(temp, "%i", scale); return std::string(temp); + } else if (query == "force44khz") { + return std::string("0"); } else { - return std::string(""); + return ""; } }