1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 17:28:50 -05:00

Deep redesign: debug NFM demod interpolator init

This commit is contained in:
f4exb 2015-08-24 02:06:11 +02:00
parent b36f3057ae
commit 11cc3044f8
6 changed files with 40 additions and 46 deletions

View File

@ -53,6 +53,7 @@ AMDemod::AMDemod() :
AMDemod::~AMDemod()
{
DSPEngine::instance()->removeAudioSink(&m_audioFifo);
}
void AMDemod::configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, Real volume, Real squelch)
@ -225,8 +226,6 @@ void AMDemod::apply()
m_interpolator.create(16, m_config.m_inputSampleRate, m_config.m_rfBandwidth / 2.2);
m_interpolatorDistanceRemain = 0;
m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_audioSampleRate;
qDebug() << "AMDemod::apply: m_inputSampleRate: " << m_config.m_inputSampleRate
<< " m_interpolatorDistance: " << m_interpolatorDistance;
}
if((m_config.m_afBandwidth != m_running.m_afBandwidth) ||

View File

@ -30,13 +30,12 @@ static const Real afSqTones[2] = {1200.0, 8000.0};
MESSAGE_CLASS_DEFINITION(NFMDemod::MsgConfigureNFMDemod, Message)
NFMDemod::NFMDemod(AudioFifo* audioFifo, SampleSink* sampleSink) :
NFMDemod::NFMDemod() :
m_ctcssIndex(0),
m_sampleCount(0),
m_afSquelch(2, afSqTones),
m_squelchOpen(false),
m_sampleSink(sampleSink),
m_audioFifo(audioFifo)
m_audioFifo(4, 48000)
{
setObjectName("NFMDemod");
@ -46,11 +45,11 @@ NFMDemod::NFMDemod(AudioFifo* audioFifo, SampleSink* sampleSink) :
m_config.m_afBandwidth = 3000;
m_config.m_squelch = -30.0;
m_config.m_volume = 2.0;
m_config.m_audioSampleRate = 48000;
m_config.m_audioSampleRate = DSPEngine::instance()->getAudioSampleRate();
apply();
m_audioBuffer.resize(16384);
m_audioBuffer.resize(1<<14);
m_audioBufferFill = 0;
m_movingAverage.resize(16, 0);
@ -61,10 +60,13 @@ NFMDemod::NFMDemod(AudioFifo* audioFifo, SampleSink* sampleSink) :
m_ctcssDetector.setCoefficients(3000, 6000.0); // 0.5s / 2 Hz resolution
m_afSquelch.setCoefficients(24, 48000.0, 5, 1); // 4000 Hz span, 250us
m_afSquelch.setThreshold(0.001);
DSPEngine::instance()->addAudioSink(&m_audioFifo);
}
NFMDemod::~NFMDemod()
{
DSPEngine::instance()->removeAudioSink(&m_audioFifo);
}
void NFMDemod::configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, Real volume, Real squelch)
@ -107,7 +109,7 @@ void NFMDemod::feed(SampleVector::const_iterator begin, SampleVector::const_iter
{
Complex ci;
if (m_audioFifo->size() == 0)
if (m_audioFifo.size() == 0)
{
return;
}
@ -227,13 +229,12 @@ void NFMDemod::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, 10);
/* FIXME: Not necessarily bad, There is a race between threads but generally it works i.e. samples are not lost
if (res != m_audioBufferFill)
{
qDebug("lost %u audio samples", m_audioBufferFill - res);
}*/
qDebug("NFMDemod::feed: %u/%u audio samples written", res, m_audioBufferFill);
}
m_audioBufferFill = 0;
}
@ -245,28 +246,22 @@ void NFMDemod::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);
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
/* Same remark as above
if (res != m_audioBufferFill)
{
qDebug("lost %u samples", m_audioBufferFill - res);
}*/
qDebug("NFMDemod::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 NFMDemod::start()
{
m_audioFifo->clear();
m_interpolatorRegulation = 0.9999;
m_interpolatorDistance = 1.0;
m_interpolatorDistanceRemain = 0.0;
m_audioFifo.clear();
m_m1Sample = 0;
}
@ -312,14 +307,7 @@ bool NFMDemod::handleMessage(const Message& cmd)
}
else
{
if (m_sampleSink != 0)
{
return m_sampleSink->handleMessage(cmd);
}
else
{
return false;
}
return false;
}
}

View File

@ -36,7 +36,7 @@ class NFMDemodGUI;
class NFMDemod : public SampleSink {
public:
NFMDemod(AudioFifo* audioFifo, SampleSink* sampleSink);
NFMDemod();
~NFMDemod();
void configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, Real volume, Real squelch);
@ -126,7 +126,6 @@ private:
Config m_running;
NCO m_nco;
Real m_interpolatorRegulation;
Interpolator m_interpolator;
Real m_interpolatorDistance;
Real m_interpolatorDistanceRemain;
@ -153,8 +152,7 @@ private:
AudioVector m_audioBuffer;
uint m_audioBufferFill;
SampleSink* m_sampleSink;
AudioFifo* m_audioFifo;
AudioFifo m_audioFifo;
SampleVector m_sampleBuffer;
NFMDemodGUI *m_nfmDemodGUI;

View File

@ -217,9 +217,7 @@ NFMDemodGUI::NFMDemodGUI(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, 48000);
m_nfmDemod = new NFMDemod(m_audioFifo, 0);
m_nfmDemod = new NFMDemod();
m_nfmDemod->registerGUI(this);
int ctcss_nbTones;
@ -233,11 +231,9 @@ NFMDemodGUI::NFMDemodGUI(PluginAPI* pluginAPI, QWidget* parent) :
}
ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
//ui->deltaFrequency->setBold(true);
m_channelizer = new Channelizer(m_nfmDemod);
m_threadedChannelizer = new ThreadedSampleSink(m_channelizer, this);
DSPEngine::instance()->addAudioSink(m_audioFifo);
DSPEngine::instance()->addThreadedSink(m_threadedChannelizer);
m_channelMarker = new ChannelMarker(this);
@ -245,7 +241,9 @@ NFMDemodGUI::NFMDemodGUI(PluginAPI* pluginAPI, QWidget* parent) :
m_channelMarker->setBandwidth(12500);
m_channelMarker->setCenterFrequency(0);
m_channelMarker->setVisible(true);
connect(m_channelMarker, SIGNAL(changed()), this, SLOT(viewChanged()));
m_pluginAPI->addChannelMarker(m_channelMarker);
applySettings();
@ -254,12 +252,10 @@ NFMDemodGUI::NFMDemodGUI(PluginAPI* pluginAPI, QWidget* parent) :
NFMDemodGUI::~NFMDemodGUI()
{
m_pluginAPI->removeChannelInstance(this);
DSPEngine::instance()->removeAudioSink(m_audioFifo);
DSPEngine::instance()->removeThreadedSink(m_threadedChannelizer);
delete m_threadedChannelizer;
delete m_channelizer;
delete m_nfmDemod;
delete m_audioFifo;
delete m_channelMarker;
delete ui;
}

View File

@ -9,8 +9,8 @@ MESSAGE_CLASS_DEFINITION(Channelizer::MsgChannelizerNotification, Message)
Channelizer::Channelizer(SampleSink* sampleSink) :
m_sampleSink(sampleSink),
m_inputSampleRate(10),
m_requestedOutputSampleRate(10),
m_inputSampleRate(0),
m_requestedOutputSampleRate(0),
m_requestedCenterFrequency(0),
m_currentOutputSampleRate(0),
m_currentCenterFrequency(0)
@ -55,7 +55,7 @@ void Channelizer::feed(SampleVector::const_iterator begin, SampleVector::const_i
void Channelizer::start()
{
if(m_sampleSink != 0)
if (m_sampleSink != 0)
{
qDebug() << "Channelizer::start: thread: " << thread()
<< " m_inputSampleRate: " << m_inputSampleRate
@ -119,10 +119,18 @@ bool Channelizer::handleMessage(const Message& cmd)
void Channelizer::applyConfiguration()
{
if (m_inputSampleRate == 0)
{
qDebug() << "Channelizer::applyConfiguration: m_inputSampleRate=0 aborting";
return;
}
freeFilterChain();
m_currentCenterFrequency = createFilterChain(
m_inputSampleRate / -2, m_inputSampleRate / 2,
m_requestedCenterFrequency - m_requestedOutputSampleRate / 2, m_requestedCenterFrequency + m_requestedOutputSampleRate / 2);
m_currentOutputSampleRate = m_inputSampleRate / (1 << m_filterStages.size());
qDebug() << "Channelizer::applyConfiguration in=" << m_inputSampleRate

View File

@ -502,12 +502,17 @@ void MainWindow::on_presetLoad_clicked()
qDebug() << "MainWindow::on_presetLoad_clicked";
QTreeWidgetItem* item = ui->presetTree->currentItem();
if(item == 0) {
if(item == 0)
{
updatePresetControls();
return;
}
const Preset* preset = qvariant_cast<const Preset*>(item->data(0, Qt::UserRole));
if(preset == 0) {
if(preset == 0)
{
return;
}