summaryrefslogtreecommitdiff
path: root/Source/Core/AudioCommon
diff options
context:
space:
mode:
authordegasus <wickmarkus@web.de>2014-02-06 13:03:40 +0100
committerdegasus <wickmarkus@web.de>2014-02-11 14:35:19 +0100
commitca9fd64df916949518fe8dfd3ca9c0432eade388 (patch)
treea22a9410ef8fc7652645686e7b0c608c23cc91c8 /Source/Core/AudioCommon
parentd20dbbc92fe78bd5e5005bb6512c688beb3df681 (diff)
controll the interpolation frac by the fifo size
Diffstat (limited to 'Source/Core/AudioCommon')
-rw-r--r--Source/Core/AudioCommon/Mixer.cpp8
-rw-r--r--Source/Core/AudioCommon/Mixer.h10
2 files changed, 15 insertions, 3 deletions
diff --git a/Source/Core/AudioCommon/Mixer.cpp b/Source/Core/AudioCommon/Mixer.cpp
index dd1e7ed386..99c5a56176 100644
--- a/Source/Core/AudioCommon/Mixer.cpp
+++ b/Source/Core/AudioCommon/Mixer.cpp
@@ -44,12 +44,18 @@ unsigned int CMixer::Mix(short* samples, unsigned int numSamples)
u32 indexR = Common::AtomicLoad(m_indexR);
u32 indexW = Common::AtomicLoad(m_indexW);
+ float numLeft = ((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
static u32 frac = 0;
- const u32 ratio = (u32)( 65536.0f * (float)AudioInterface::GetAIDSampleRate() / (float)m_sampleRate );
+ const u32 ratio = (u32)( 65536.0f * (float)AudioInterface::GetAIDSampleRate() / (float)m_sampleRate + offset );
if(ratio > 0x10000)
ERROR_LOG(AUDIO, "ratio out of range");
diff --git a/Source/Core/AudioCommon/Mixer.h b/Source/Core/AudioCommon/Mixer.h
index e38a64b067..954aa7b99a 100644
--- a/Source/Core/AudioCommon/Mixer.h
+++ b/Source/Core/AudioCommon/Mixer.h
@@ -8,9 +8,13 @@
#include "StdMutex.h"
// 16 bit Stereo
-#define MAX_SAMPLES (1024 * 8)
+#define MAX_SAMPLES (1024 * 2) // 64ms
#define INDEX_MASK (MAX_SAMPLES * 2 - 1)
-#define RESERVED_SAMPLES (256)
+
+#define LOW_WATERMARK 1280 // 40 ms
+#define MAX_FREQ_SHIFT 0x0100 // of 0x10000
+#define CONTROL_FACTOR 0.3 // in freq_shift per fifo size offset
+#define CONTROL_AVG 32
class CMixer {
@@ -24,6 +28,7 @@ public:
, m_logAudio(0)
, m_indexW(0)
, m_indexR(0)
+ , m_numLeftI(0.0f)
{
// AyuanX: The internal (Core & DSP) sample rate is fixed at 32KHz
// So when AI/DAC sample rate differs than 32KHz, we have to do re-sampling
@@ -97,6 +102,7 @@ protected:
volatile u32 m_indexR;
std::mutex m_csMixing;
+ float m_numLeftI;
volatile float m_speed; // Current rate of the emulation (1.0 = 100% speed)
private: