From ce1057f17d3b57e9a54e7da0e8ad7e441dca1897 Mon Sep 17 00:00:00 2001 From: pierre Date: Tue, 28 Sep 2010 21:43:38 +0000 Subject: [PATCH] Core/AudioCommon: Feed bigger audio chunks to the output devices in case of underrun. This should eliminate the crackling with alsa and pulseaudio backends and replace it with much nicer pauses. This is only interesting for audio backends that do not respect Mixer::GetNumSamples() and should not impact users able to run the DSPLLE at full speed. The cost of this is an added LLE audio latency of about 0.06 s in the continuous playback case. If that is too much, lower the low watermark. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6239 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/AudioCommon/Src/Mixer.cpp | 39 ++++++++++++++++++--------- Source/Core/AudioCommon/Src/Mixer.h | 3 +++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Source/Core/AudioCommon/Src/Mixer.cpp b/Source/Core/AudioCommon/Src/Mixer.cpp index 36a3030707..b5843a3e8d 100644 --- a/Source/Core/AudioCommon/Src/Mixer.cpp +++ b/Source/Core/AudioCommon/Src/Mixer.cpp @@ -37,19 +37,30 @@ unsigned int CMixer::Mix(short* samples, unsigned int numSamples) } unsigned int numLeft = Common::AtomicLoad(m_numSamples); - numLeft = (numLeft > numSamples) ? numSamples : numLeft; - - // Do re-sampling if needed - if (m_sampleRate == 32000) - { - for (unsigned int i = 0; i < numLeft * 2; i++) - samples[i] = Common::swap16(m_buffer[(m_indexR + i) & INDEX_MASK]); - m_indexR += numLeft * 2; + if (m_LLEplaying) { + if (numLeft < numSamples)//cannot do much about this + m_LLEplaying = false; + if (numLeft < MAX_SAMPLES/4)//low watermark + m_LLEplaying = false; + } else { + if (numLeft > MAX_SAMPLES/2)//high watermark + m_LLEplaying = true; } - else - { - // AyuanX: Up-sampling is not implemented yet - PanicAlert("Mixer: Up-sampling is not implemented yet!"); + + if (m_LLEplaying) { + numLeft = (numLeft > numSamples) ? numSamples : numLeft; + + // Do re-sampling if needed + if (m_sampleRate == 32000) + { + for (unsigned int i = 0; i < numLeft * 2; i++) + samples[i] = Common::swap16(m_buffer[(m_indexR + i) & INDEX_MASK]); + m_indexR += numLeft * 2; + } + else + { + // AyuanX: Up-sampling is not implemented yet + PanicAlert("Mixer: Up-sampling is not implemented yet!"); /* static int PV1l=0,PV2l=0,PV3l=0,PV4l=0; static int PV1r=0,PV2r=0,PV3r=0,PV4r=0; @@ -112,6 +123,10 @@ unsigned int CMixer::Mix(short* samples, unsigned int numSamples) m_queueSize += 2; } */ + } + + } else { + numLeft = 0; } // Padding diff --git a/Source/Core/AudioCommon/Src/Mixer.h b/Source/Core/AudioCommon/Src/Mixer.h index c1bf17be1a..8db6da1ca7 100644 --- a/Source/Core/AudioCommon/Src/Mixer.h +++ b/Source/Core/AudioCommon/Src/Mixer.h @@ -35,6 +35,7 @@ public: , m_numSamples(0) , m_indexW(0) , m_indexR(0) + , m_LLEplaying(true) { // 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 @@ -80,6 +81,8 @@ protected: u32 m_indexW; u32 m_indexR; + bool m_LLEplaying; + private: };