From 2fddaff6d24d64c9afe88cf97b7ea6848d674c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20DEL=20NERO?= Date: Fri, 2 Aug 2024 12:17:00 +0200 Subject: [PATCH 1/2] Fix audio glitches in the DAB plugin. The glitches were generated by an int16 integer overflow. The issue appeared when the audio was near or at the saturation level. When the input audio signal is saturated, the polyphase filter based interpolation/decimation functions tend to increase the samples values and then make them pass the int16 limits. The int16 sample scale() parameter defeat the min/max limitation. This fix removes the intermediate int16 type conversion by using the Complex Real type. fixes f4exb/sdrangel#1978 --- plugins/channelrx/demoddab/dabdemodsink.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/channelrx/demoddab/dabdemodsink.cpp b/plugins/channelrx/demoddab/dabdemodsink.cpp index 86d9e0d8af..44a62673e8 100644 --- a/plugins/channelrx/demoddab/dabdemodsink.cpp +++ b/plugins/channelrx/demoddab/dabdemodsink.cpp @@ -366,7 +366,7 @@ void DABDemodSink::tii(int tii) } } -static int16_t scale(int16_t sample, float factor) +static int16_t scale(Real sample, float factor) { int32_t prod = (int32_t)(((int32_t)sample) * factor); prod = std::min(prod, 32767); From 5888645957e75f065af8afacd233879337bfed57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20DEL=20NERO?= Date: Fri, 2 Aug 2024 12:23:27 +0200 Subject: [PATCH 2/2] Don't decimate the audio signal if not needed. --- plugins/channelrx/demoddab/dabdemodsink.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/channelrx/demoddab/dabdemodsink.cpp b/plugins/channelrx/demoddab/dabdemodsink.cpp index 44a62673e8..193d00dacf 100644 --- a/plugins/channelrx/demoddab/dabdemodsink.cpp +++ b/plugins/channelrx/demoddab/dabdemodsink.cpp @@ -403,7 +403,12 @@ void DABDemodSink::audio(int16_t *buffer, int size, int samplerate, bool stereo) ci.real(0.0f); ci.imag(0.0f); } - if (m_audioInterpolatorDistance < 1.0f) // interpolate + + if (m_audioInterpolatorDistance == 1.0f) + { + processOneAudioSample(ci); + } + else if (m_audioInterpolatorDistance < 1.0f) // interpolate { while (!m_audioInterpolator.interpolate(&m_audioInterpolatorDistanceRemain, ci, &ca)) {