From a0101c5d29a77d5b0c60c9ece5624406aaab5178 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Thu, 17 Jul 2014 18:26:21 +1200 Subject: [PATCH 1/2] Audio Mixer: move Static variable to a member variable. The two instances of this class were sharing a frac variable causing audio glitches when both were running (which is now all the time). Fixes issue 7463 (Since DTK merge, audio has staic in it). --- Source/Core/AudioCommon/Mixer.cpp | 11 +++++------ Source/Core/AudioCommon/Mixer.h | 2 ++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/Core/AudioCommon/Mixer.cpp b/Source/Core/AudioCommon/Mixer.cpp index 388eb56b0d..24e8a1c128 100644 --- a/Source/Core/AudioCommon/Mixer.cpp +++ b/Source/Core/AudioCommon/Mixer.cpp @@ -51,7 +51,6 @@ unsigned int CMixer::MixerFifo::Mix(short* samples, unsigned int numSamples, boo aid_sample_rate = aid_sample_rate * (framelimit - 1) * 5 / VideoInterface::TargetRefreshRate; } - static u32 frac = 0; const u32 ratio = (u32)( 65536.0f * aid_sample_rate / (float)m_mixer->m_sampleRate ); s32 lvolume = m_LVolume; @@ -63,7 +62,7 @@ unsigned int CMixer::MixerFifo::Mix(short* samples, unsigned int numSamples, boo s16 l1 = Common::swap16(m_buffer[indexR & INDEX_MASK]); //current s16 l2 = Common::swap16(m_buffer[indexR2 & INDEX_MASK]); //next - int sampleL = ((l1 << 16) + (l2 - l1) * (u16)frac) >> 16; + int sampleL = ((l1 << 16) + (l2 - l1) * (u16)m_frac) >> 16; sampleL = (sampleL * lvolume) >> 8; sampleL += samples[currentSample + 1]; MathUtil::Clamp(&sampleL, -32767, 32767); @@ -71,15 +70,15 @@ unsigned int CMixer::MixerFifo::Mix(short* samples, unsigned int numSamples, boo s16 r1 = Common::swap16(m_buffer[(indexR + 1) & INDEX_MASK]); //current s16 r2 = Common::swap16(m_buffer[(indexR2 + 1) & INDEX_MASK]); //next - int sampleR = ((r1 << 16) + (r2 - r1) * (u16)frac) >> 16; + int sampleR = ((r1 << 16) + (r2 - r1) * (u16)m_frac) >> 16; sampleR = (sampleR * rvolume) >> 8; sampleR += samples[currentSample]; MathUtil::Clamp(&sampleR, -32767, 32767); samples[currentSample] = sampleR; - frac += ratio; - indexR += 2 * (u16)(frac >> 16); - frac &= 0xffff; + m_frac += ratio; + indexR += 2 * (u16)(m_frac >> 16); + m_frac &= 0xffff; } // Padding diff --git a/Source/Core/AudioCommon/Mixer.h b/Source/Core/AudioCommon/Mixer.h index d1096b2eb0..474ec128bb 100644 --- a/Source/Core/AudioCommon/Mixer.h +++ b/Source/Core/AudioCommon/Mixer.h @@ -91,6 +91,7 @@ protected: , m_LVolume(256) , m_RVolume(256) , m_numLeftI(0.0f) + , m_frac(0) { memset(m_buffer, 0, sizeof(m_buffer)); } @@ -107,6 +108,7 @@ protected: volatile s32 m_LVolume; volatile s32 m_RVolume; float m_numLeftI; + u32 m_frac; }; MixerFifo m_dma_mixer; MixerFifo m_streaming_mixer; From 48afab2685e3ce1a0e3ae7c21932fe3834c86482 Mon Sep 17 00:00:00 2001 From: Scott Mansell Date: Thu, 17 Jul 2014 18:41:18 +1200 Subject: [PATCH 2/2] Correct left/right volume for padded samples. --- Source/Core/AudioCommon/Mixer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/AudioCommon/Mixer.cpp b/Source/Core/AudioCommon/Mixer.cpp index 24e8a1c128..ce13f50689 100644 --- a/Source/Core/AudioCommon/Mixer.cpp +++ b/Source/Core/AudioCommon/Mixer.cpp @@ -85,8 +85,8 @@ unsigned int CMixer::MixerFifo::Mix(short* samples, unsigned int numSamples, boo short s[2]; s[0] = Common::swap16(m_buffer[(indexR - 1) & INDEX_MASK]); s[1] = Common::swap16(m_buffer[(indexR - 2) & INDEX_MASK]); - s[0] = (s[0] * lvolume) >> 8; - s[1] = (s[1] * rvolume) >> 8; + s[0] = (s[0] * rvolume) >> 8; + s[1] = (s[1] * lvolume) >> 8; for (; currentSample < numSamples * 2; currentSample += 2) { int sampleR = s[0] + samples[currentSample];