From 5582105c25445bbe43986956e5a4208df7d85ebc Mon Sep 17 00:00:00 2001 From: f4exb Date: Mon, 24 Aug 2015 02:59:18 +0200 Subject: [PATCH] Deep redesign: debug WFM demod interpolator init --- plugins/channel/wfm/wfmdemod.cpp | 41 ++++++++++++++++++++--------- plugins/channel/wfm/wfmdemod.h | 13 ++++----- plugins/channel/wfm/wfmdemodgui.cpp | 6 +---- plugins/channel/wfm/wfmdemodgui.h | 2 -- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/plugins/channel/wfm/wfmdemod.cpp b/plugins/channel/wfm/wfmdemod.cpp index 23d31fb1e..adc3e419f 100644 --- a/plugins/channel/wfm/wfmdemod.cpp +++ b/plugins/channel/wfm/wfmdemod.cpp @@ -20,15 +20,16 @@ #include #include #include "audio/audiooutput.h" +#include "dsp/dspengine.h" #include "dsp/channelizer.h" #include "dsp/pidcontroller.h" #include "wfmdemod.h" MESSAGE_CLASS_DEFINITION(WFMDemod::MsgConfigureWFMDemod, Message) -WFMDemod::WFMDemod(AudioFifo* audioFifo, SampleSink* sampleSink) : +WFMDemod::WFMDemod(SampleSink* sampleSink) : m_sampleSink(sampleSink), - m_audioFifo(audioFifo) + m_audioFifo(4, 250000) { setObjectName("WFMDemod"); @@ -38,7 +39,7 @@ WFMDemod::WFMDemod(AudioFifo* audioFifo, SampleSink* sampleSink) : m_config.m_afBandwidth = 15000; m_config.m_squelch = -60.0; m_config.m_volume = 2.0; - m_config.m_audioSampleRate = 48000; + m_config.m_audioSampleRate = DSPEngine::instance()->getAudioSampleRate(); m_rfFilter = new fftfilt(-50000.0 / 384000.0, 50000.0 / 384000.0, rfFilterFftLength); apply(); @@ -47,6 +48,8 @@ WFMDemod::WFMDemod(AudioFifo* audioFifo, SampleSink* sampleSink) : m_audioBufferFill = 0; m_movingAverage.resize(16, 0); + + DSPEngine::instance()->addAudioSink(&m_audioFifo); } WFMDemod::~WFMDemod() @@ -55,6 +58,8 @@ WFMDemod::~WFMDemod() { delete m_rfFilter; } + + DSPEngine::instance()->removeAudioSink(&m_audioFifo); } void WFMDemod::configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, Real volume, Real squelch) @@ -70,7 +75,7 @@ void WFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter int rf_out; Real msq, demod; - if (m_audioFifo->size() <= 0) + if (m_audioFifo.size() <= 0) return; for (SampleVector::const_iterator it = begin; it != end; ++it) @@ -122,9 +127,13 @@ void WFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter if(m_audioBufferFill >= m_audioBuffer.size()) { - uint res = m_audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1); + uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1); + if(res != m_audioBufferFill) - qDebug("lost %u samples", m_audioBufferFill - res); + { + qDebug("WFMDemod::feed: %u/%u audio samples written", res, m_audioBufferFill); + } + m_audioBufferFill = 0; } @@ -133,25 +142,30 @@ void WFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter } } - if(m_audioBufferFill > 0) { - uint res = m_audioFifo->write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1); + if(m_audioBufferFill > 0) + { + uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1); + if(res != m_audioBufferFill) - qDebug("lost %u samples", m_audioBufferFill - res); + { + qDebug("WFMDemod::feed: %u/%u tail samples written", res, m_audioBufferFill); + } + m_audioBufferFill = 0; } if(m_sampleSink != NULL) + { m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), false); + } + m_sampleBuffer.clear(); } void WFMDemod::start() { m_squelchState = 0; - m_audioFifo->clear(); - m_interpolatorRegulation = 0.9999; - m_interpolatorDistance = 1.0; - m_interpolatorDistanceRemain = 0.0; + m_audioFifo.clear(); m_m1Sample = 0; } @@ -169,6 +183,7 @@ bool WFMDemod::handleMessage(const Message& cmd) m_config.m_inputSampleRate = notif.getSampleRate(); m_config.m_inputFrequencyOffset = notif.getFrequencyOffset(); + apply(); qDebug() << "WFMDemod::handleMessage: MsgChannelizerNotification: m_inputSampleRate: " << m_config.m_inputSampleRate diff --git a/plugins/channel/wfm/wfmdemod.h b/plugins/channel/wfm/wfmdemod.h index a0f3527a6..f639965a3 100644 --- a/plugins/channel/wfm/wfmdemod.h +++ b/plugins/channel/wfm/wfmdemod.h @@ -30,11 +30,9 @@ #define rfFilterFftLength 1024 -class AudioFifo; - class WFMDemod : public SampleSink { public: - WFMDemod(AudioFifo* audioFifo, SampleSink* sampleSink); + WFMDemod(SampleSink* sampleSink); virtual ~WFMDemod(); void configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, Real volume, Real squelch); @@ -109,8 +107,7 @@ private: Config m_running; NCO m_nco; - Real m_interpolatorRegulation; - Interpolator m_interpolator; // Interpolator between sample rate sent from DSP engine and requested RF bandwidth (rational) + Interpolator m_interpolator; //!< Interpolator between sample rate sent from DSP engine and requested RF bandwidth (rational) Real m_interpolatorDistance; Real m_interpolatorDistanceRemain; Lowpass m_lowpass; @@ -120,15 +117,15 @@ private: int m_squelchState; Real m_lastArgument; - Complex m_m1Sample; // x^-1 sample - Complex m_m2Sample; // x^-1 sample + Complex m_m1Sample; //!< x^-1 sample + Complex m_m2Sample; //!< x^-1 sample MovingAverage m_movingAverage; AudioVector m_audioBuffer; uint m_audioBufferFill; SampleSink* m_sampleSink; - AudioFifo* m_audioFifo; + AudioFifo m_audioFifo; SampleVector m_sampleBuffer; void apply(); diff --git a/plugins/channel/wfm/wfmdemodgui.cpp b/plugins/channel/wfm/wfmdemodgui.cpp index c654ab08d..6383c1a5a 100644 --- a/plugins/channel/wfm/wfmdemodgui.cpp +++ b/plugins/channel/wfm/wfmdemodgui.cpp @@ -211,11 +211,9 @@ WFMDemodGUI::WFMDemodGUI(PluginAPI* pluginAPI, QWidget* parent) : connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked())); - m_audioFifo = new AudioFifo(4, 250000); // TODO: check. Room for 1s FIFO at max rate - m_wfmDemod = new WFMDemod(m_audioFifo, 0); + m_wfmDemod = new WFMDemod(0); m_channelizer = new Channelizer(m_wfmDemod); m_threadedChannelizer = new ThreadedSampleSink(m_channelizer, this); - DSPEngine::instance()->addAudioSink(m_audioFifo); DSPEngine::instance()->addThreadedSink(m_threadedChannelizer); m_channelMarker = new ChannelMarker(this); @@ -232,12 +230,10 @@ WFMDemodGUI::WFMDemodGUI(PluginAPI* pluginAPI, QWidget* parent) : WFMDemodGUI::~WFMDemodGUI() { m_pluginAPI->removeChannelInstance(this); - DSPEngine::instance()->removeAudioSink(m_audioFifo); DSPEngine::instance()->removeThreadedSink(m_threadedChannelizer); delete m_threadedChannelizer; delete m_channelizer; delete m_wfmDemod; - delete m_audioFifo; delete m_channelMarker; delete ui; } diff --git a/plugins/channel/wfm/wfmdemodgui.h b/plugins/channel/wfm/wfmdemodgui.h index e35929502..c576e7c6e 100644 --- a/plugins/channel/wfm/wfmdemodgui.h +++ b/plugins/channel/wfm/wfmdemodgui.h @@ -7,7 +7,6 @@ class PluginAPI; class ChannelMarker; -class AudioFifo; class ThreadedSampleSink; class Channelizer; class WFMDemod; @@ -51,7 +50,6 @@ private: bool m_basicSettingsShown; bool m_doApplySettings; - AudioFifo* m_audioFifo; ThreadedSampleSink* m_threadedChannelizer; Channelizer* m_channelizer; WFMDemod* m_wfmDemod;