From 4a5a29a59a65dfe54bfe23783a88d1b1a9f7e4a8 Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Tue, 13 Jul 2021 18:47:34 +0200 Subject: [PATCH] Fixed the audio glitches!!! --- core/src/dsp/resampling.h | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/core/src/dsp/resampling.h b/core/src/dsp/resampling.h index bf8edc24..00fa637a 100644 --- a/core/src/dsp/resampling.h +++ b/core/src/dsp/resampling.h @@ -113,28 +113,39 @@ namespace dsp { return -1; } - int outCount = calcOutSize(count); memcpy(&buffer[tapsPerPhase], _in->readBuf, count * sizeof(T)); _in->flush(); // Write to output int outIndex = 0; - int _interp_m_1 = _interp - 1; + int inOffset = offset; + int _counter = counter; if constexpr (std::is_same_v) { - for (int i = 0; outIndex < outCount; i += _decim) { - int phase = i % _interp; - volk_32f_x2_dot_prod_32f(&out.writeBuf[outIndex], &buffer[i / _interp], tapPhases[phase], tapsPerPhase); - outIndex++; + while (inOffset < count) { + volk_32f_x2_dot_prod_32f(&out.writeBuf[outIndex++], &buffer[inOffset], tapPhases[_counter], tapsPerPhase); + _counter += _decim; + while (_counter >= _interp) { + _counter -= _interp; + inOffset++; + } } + } if constexpr (std::is_same_v || std::is_same_v) { - for (int i = 0; outIndex < outCount; i += _decim) { - int phase = i % _interp; - volk_32fc_32f_dot_prod_32fc((lv_32fc_t*)&out.writeBuf[outIndex], (lv_32fc_t*)&buffer[(i / _interp)], tapPhases[phase], tapsPerPhase); - outIndex++; + while (inOffset < count) { + volk_32fc_32f_dot_prod_32fc((lv_32fc_t*)&out.writeBuf[outIndex++], (lv_32fc_t*)&buffer[inOffset], tapPhases[_counter], tapsPerPhase); + _counter += _decim; + while (_counter >= _interp) { + _counter -= _interp; + inOffset++; + } } } - if (!out.swap(outCount)) { return -1; } + + if (!out.swap(outIndex)) { return -1; } + + offset = inOffset - count; + counter = _counter; memmove(buffer, &buffer[count], tapsPerPhase * sizeof(T)); @@ -193,6 +204,9 @@ namespace dsp { float _inSampleRate, _outSampleRate; float* taps; + int counter = 0; + int offset = 0; + int tapsPerPhase; std::vector tapPhases;