From d0779be1d209e61e6400037f09920fcbfd188c4a Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 28 Apr 2019 22:05:54 +0200 Subject: [PATCH] Remote input: R/W balance: calculate exponential moving average on floating point for better accuracy --- plugins/samplesource/remoteinput/remoteinputbuffer.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/samplesource/remoteinput/remoteinputbuffer.cpp b/plugins/samplesource/remoteinput/remoteinputbuffer.cpp index a2e138779..2a349932c 100644 --- a/plugins/samplesource/remoteinput/remoteinputbuffer.cpp +++ b/plugins/samplesource/remoteinput/remoteinputbuffer.cpp @@ -147,10 +147,14 @@ void RemoteInputBuffer::rwCorrectionEstimate(int slotIndex) } else // read lags { - dBytes = (nbDecoderSlots * sizeof(BufferFrame)) - normalizedReadIndex - rwDelta; + int bufSize = (nbDecoderSlots * sizeof(BufferFrame)); + dBytes = bufSize - normalizedReadIndex - rwDelta; } - m_balCorrection = (m_balCorrection / 4) + (dBytes / (int) (m_currentMeta.m_sampleBytes * 2 * m_nbReads)); // correction is in number of samples. Alpha = 0.25 + // calculate exponential moving average on floating point for better accuracy (was int) + double newCorrection = ((double) dBytes) / (((int) m_currentMeta.m_sampleBytes) * 2 * m_nbReads); + m_balCorrection = 0.25*m_balCorrection + 0.75*newCorrection; // exponential average with alpha = 0.75 (original is wrong) + //m_balCorrection = (m_balCorrection / 4) + (dBytes / (int) (m_currentMeta.m_sampleBytes * 2 * m_nbReads)); // correction is in number of samples. Alpha = 0.25 if (m_balCorrection < -m_balCorrLimit) { m_balCorrection = -m_balCorrLimit;