From f2b8418a2539f6f5302cf92fd7a39e034f8dedc0 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Wed, 22 Jun 2022 04:58:03 +0200 Subject: [PATCH] hopefully a fix for the linux crash --- core/src/dsp/loop/agc.h | 8 ++++---- core/src/dsp/sink/ring_buffer.h | 7 ++++++- decoder_modules/radio/src/radio_module.h | 2 ++ sink_modules/portaudio_sink/src/main.cpp | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/core/src/dsp/loop/agc.h b/core/src/dsp/loop/agc.h index e20018b..659dadb 100644 --- a/core/src/dsp/loop/agc.h +++ b/core/src/dsp/loop/agc.h @@ -89,17 +89,17 @@ namespace dsp::loop { float maxAmp = 0; for (int j = i; j < count; j++) { if constexpr (std::is_same_v) { - inAmp = in[i].amplitude(); + inAmp = in[j].amplitude(); } if constexpr (std::is_same_v) { - inAmp = fabsf(in[i]); + inAmp = fabsf(in[j]); } if (inAmp > maxAmp) { maxAmp = inAmp; } } amp = maxAmp; - gain = _setPoint / maxAmp; + gain = std::min(_setPoint / amp, _maxGain); } - + // Scale output by gain out[i] = in[i] * gain; } diff --git a/core/src/dsp/sink/ring_buffer.h b/core/src/dsp/sink/ring_buffer.h index 5298ae6..be07626 100644 --- a/core/src/dsp/sink/ring_buffer.h +++ b/core/src/dsp/sink/ring_buffer.h @@ -11,7 +11,12 @@ namespace dsp::sink { public: RingBuffer() {} - RingBuffer(stream* in) { base_type::init(in); } + RingBuffer(stream* in, int maxLatency) { init(in, maxLatency); } + + void init(stream* in, int maxLatency) { + data.init(maxLatency); + base_type::init(in); + } int run() { int count = base_type::_in->read(); diff --git a/decoder_modules/radio/src/radio_module.h b/decoder_modules/radio/src/radio_module.h index f504884..8470737 100644 --- a/decoder_modules/radio/src/radio_module.h +++ b/decoder_modules/radio/src/radio_module.h @@ -318,11 +318,13 @@ private: void selectDemod(demod::Demodulator* demod) { // Stopcurrently selected demodulator and select new + afChain.stop(); if (selectedDemod) { selectedDemod->stop(); delete selectedDemod; } selectedDemod = demod; + afChain.start(); // Give the demodulator the most recent audio SR selectedDemod->AFSampRateChanged(audioSampleRate); diff --git a/sink_modules/portaudio_sink/src/main.cpp b/sink_modules/portaudio_sink/src/main.cpp index 8f9f2e3..c17df33 100644 --- a/sink_modules/portaudio_sink/src/main.cpp +++ b/sink_modules/portaudio_sink/src/main.cpp @@ -34,8 +34,8 @@ public: _stream = stream; _streamName = streamName; s2m.init(_stream->sinkOut); - monoRB.init(&s2m.out); - stereoRB.init(_stream->sinkOut); + monoRB.init(&s2m.out, 480); + stereoRB.init(_stream->sinkOut, 480); // monoPacker.init(&s2m.out, 240); // stereoPacker.init(_stream->sinkOut, 240);