mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-15 12:51:49 -05:00
ChannelAnalyzerNG: decouple demod and GUI
This commit is contained in:
parent
54bd4b38f0
commit
4d07272503
@ -16,17 +16,23 @@
|
||||
|
||||
#include "chanalyzerng.h"
|
||||
|
||||
#include <dsp/downchannelizer.h>
|
||||
#include <QTime>
|
||||
#include <QDebug>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "device/devicesourceapi.h"
|
||||
#include "audio/audiooutput.h"
|
||||
#include "dsp/threadedbasebandsamplesink.h"
|
||||
#include "dsp/downchannelizer.h"
|
||||
|
||||
|
||||
MESSAGE_CLASS_DEFINITION(ChannelAnalyzerNG::MsgConfigureChannelAnalyzer, Message)
|
||||
MESSAGE_CLASS_DEFINITION(ChannelAnalyzerNG::MsgConfigureChannelizer, Message)
|
||||
MESSAGE_CLASS_DEFINITION(ChannelAnalyzerNG::MsgReportChannelSampleRateChanged, Message)
|
||||
|
||||
ChannelAnalyzerNG::ChannelAnalyzerNG(BasebandSampleSink* sampleSink) :
|
||||
m_sampleSink(sampleSink),
|
||||
ChannelAnalyzerNG::ChannelAnalyzerNG(DeviceSourceAPI *deviceAPI) :
|
||||
m_deviceAPI(deviceAPI),
|
||||
m_sampleSink(0),
|
||||
m_settingsMutex(QMutex::Recursive)
|
||||
{
|
||||
m_undersampleCount = 0;
|
||||
@ -38,6 +44,12 @@ ChannelAnalyzerNG::ChannelAnalyzerNG(BasebandSampleSink* sampleSink) :
|
||||
m_interpolatorDistanceRemain = 0.0f;
|
||||
SSBFilter = new fftfilt(m_config.m_LowCutoff / m_config.m_inputSampleRate, m_config.m_Bandwidth / m_config.m_inputSampleRate, ssbFftLen);
|
||||
DSBFilter = new fftfilt(m_config.m_Bandwidth / m_config.m_inputSampleRate, 2*ssbFftLen);
|
||||
|
||||
m_channelizer = new DownChannelizer(this);
|
||||
m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
|
||||
connect(m_channelizer, SIGNAL(inputSampleRateChanged()), this, SLOT(channelizerInputSampleRateChanged()));
|
||||
m_deviceAPI->addThreadedSink(m_threadedChannelizer);
|
||||
|
||||
apply(true);
|
||||
}
|
||||
|
||||
@ -45,6 +57,9 @@ ChannelAnalyzerNG::~ChannelAnalyzerNG()
|
||||
{
|
||||
if (SSBFilter) delete SSBFilter;
|
||||
if (DSBFilter) delete DSBFilter;
|
||||
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
|
||||
delete m_threadedChannelizer;
|
||||
delete m_channelizer;
|
||||
}
|
||||
|
||||
void ChannelAnalyzerNG::configure(MessageQueue* messageQueue,
|
||||
@ -102,6 +117,12 @@ void ChannelAnalyzerNG::stop()
|
||||
{
|
||||
}
|
||||
|
||||
void ChannelAnalyzerNG::channelizerInputSampleRateChanged()
|
||||
{
|
||||
MsgReportChannelSampleRateChanged *msg = MsgReportChannelSampleRateChanged::create();
|
||||
getMessageQueueToGUI()->push(msg);
|
||||
}
|
||||
|
||||
bool ChannelAnalyzerNG::handleMessage(const Message& cmd)
|
||||
{
|
||||
qDebug() << "ChannelAnalyzerNG::handleMessage: " << cmd.getIdentifier();
|
||||
@ -120,6 +141,14 @@ bool ChannelAnalyzerNG::handleMessage(const Message& cmd)
|
||||
apply();
|
||||
return true;
|
||||
}
|
||||
else if (MsgConfigureChannelizer::match(cmd))
|
||||
{
|
||||
MsgConfigureChannelizer& cfg = (MsgConfigureChannelizer&) cmd;
|
||||
m_channelizer->configure(m_channelizer->getInputMessageQueue(),
|
||||
cfg.getSampleRate(),
|
||||
cfg.getCenterFrequency());
|
||||
return true;
|
||||
}
|
||||
else if (MsgConfigureChannelAnalyzer::match(cmd))
|
||||
{
|
||||
MsgConfigureChannelAnalyzer& cfg = (MsgConfigureChannelAnalyzer&) cmd;
|
||||
@ -153,6 +182,8 @@ bool ChannelAnalyzerNG::handleMessage(const Message& cmd)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ChannelAnalyzerNG::apply(bool force)
|
||||
{
|
||||
if ((m_running.m_frequency != m_config.m_frequency) ||
|
||||
|
@ -29,28 +29,12 @@
|
||||
|
||||
#define ssbFftLen 1024
|
||||
|
||||
class DeviceSourceAPI;
|
||||
class ThreadedBasebandSampleSink;
|
||||
class DownChannelizer;
|
||||
|
||||
class ChannelAnalyzerNG : public BasebandSampleSink {
|
||||
public:
|
||||
ChannelAnalyzerNG(BasebandSampleSink* m_sampleSink);
|
||||
virtual ~ChannelAnalyzerNG();
|
||||
|
||||
void configure(MessageQueue* messageQueue,
|
||||
int channelSampleRate,
|
||||
Real Bandwidth,
|
||||
Real LowCutoff,
|
||||
int spanLog2,
|
||||
bool ssb);
|
||||
|
||||
int getInputSampleRate() const { return m_running.m_inputSampleRate; }
|
||||
int getChannelSampleRate() const { return m_running.m_channelSampleRate; }
|
||||
double getMagSq() const { return m_magsq; }
|
||||
|
||||
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly);
|
||||
virtual void start();
|
||||
virtual void stop();
|
||||
virtual bool handleMessage(const Message& cmd);
|
||||
|
||||
private:
|
||||
class MsgConfigureChannelAnalyzer : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
@ -68,7 +52,12 @@ private:
|
||||
int spanLog2,
|
||||
bool ssb)
|
||||
{
|
||||
return new MsgConfigureChannelAnalyzer(channelSampleRate, Bandwidth, LowCutoff, spanLog2, ssb);
|
||||
return new MsgConfigureChannelAnalyzer(
|
||||
channelSampleRate,
|
||||
Bandwidth,
|
||||
LowCutoff,
|
||||
spanLog2,
|
||||
ssb);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -93,6 +82,72 @@ private:
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgConfigureChannelizer : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
int getSampleRate() const { return m_sampleRate; }
|
||||
int getCenterFrequency() const { return m_centerFrequency; }
|
||||
|
||||
static MsgConfigureChannelizer* create(int sampleRate, int centerFrequency)
|
||||
{
|
||||
return new MsgConfigureChannelizer(sampleRate, centerFrequency);
|
||||
}
|
||||
|
||||
private:
|
||||
int m_sampleRate;
|
||||
int m_centerFrequency;
|
||||
|
||||
MsgConfigureChannelizer(int sampleRate, int centerFrequency) :
|
||||
Message(),
|
||||
m_sampleRate(sampleRate),
|
||||
m_centerFrequency(centerFrequency)
|
||||
{ }
|
||||
};
|
||||
|
||||
class MsgReportChannelSampleRateChanged : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
|
||||
static MsgReportChannelSampleRateChanged* create()
|
||||
{
|
||||
return new MsgReportChannelSampleRateChanged();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
MsgReportChannelSampleRateChanged() :
|
||||
Message()
|
||||
{ }
|
||||
};
|
||||
|
||||
ChannelAnalyzerNG(DeviceSourceAPI *deviceAPI);
|
||||
virtual ~ChannelAnalyzerNG();
|
||||
void setSampleSink(BasebandSampleSink* sampleSink) { m_sampleSink = sampleSink; }
|
||||
|
||||
void configure(MessageQueue* messageQueue,
|
||||
int channelSampleRate,
|
||||
Real Bandwidth,
|
||||
Real LowCutoff,
|
||||
int spanLog2,
|
||||
bool ssb);
|
||||
|
||||
DownChannelizer *getChannelizer() { return m_channelizer; }
|
||||
int getInputSampleRate() const { return m_running.m_inputSampleRate; }
|
||||
int getChannelSampleRate() const { return m_running.m_channelSampleRate; }
|
||||
double getMagSq() const { return m_magsq; }
|
||||
|
||||
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool positiveOnly);
|
||||
virtual void start();
|
||||
virtual void stop();
|
||||
virtual bool handleMessage(const Message& cmd);
|
||||
|
||||
private slots:
|
||||
void channelizerInputSampleRateChanged();
|
||||
|
||||
private:
|
||||
|
||||
struct Config
|
||||
{
|
||||
int m_frequency;
|
||||
@ -117,6 +172,10 @@ private:
|
||||
Config m_config;
|
||||
Config m_running;
|
||||
|
||||
DeviceSourceAPI *m_deviceAPI;
|
||||
ThreadedBasebandSampleSink* m_threadedChannelizer;
|
||||
DownChannelizer* m_channelizer;
|
||||
|
||||
int m_undersampleCount;
|
||||
fftfilt::cmplx m_sum;
|
||||
bool m_usb;
|
||||
|
@ -159,9 +159,31 @@ bool ChannelAnalyzerNGGUI::deserialize(const QByteArray& data)
|
||||
|
||||
bool ChannelAnalyzerNGGUI::handleMessage(const Message& message __attribute__((unused)))
|
||||
{
|
||||
if (ChannelAnalyzerNG::MsgReportChannelSampleRateChanged::match(message))
|
||||
{
|
||||
setNewFinalRate(m_spanLog2);
|
||||
applySettings();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ChannelAnalyzerNGGUI::handleInputMessages()
|
||||
{
|
||||
Message* message;
|
||||
|
||||
while ((message = getInputMessageQueue()->pop()) != 0)
|
||||
{
|
||||
qDebug("ChannelAnalyzerGUI::handleInputMessages: message: %s", message->getIdentifier());
|
||||
|
||||
if (handleMessage(*message))
|
||||
{
|
||||
delete message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelAnalyzerNGGUI::viewChanged()
|
||||
{
|
||||
applySettings();
|
||||
@ -174,12 +196,12 @@ void ChannelAnalyzerNGGUI::tick()
|
||||
ui->channelPower->setText(tr("%1 dB").arg(m_channelPowerDbAvg.average(), 0, 'f', 1));
|
||||
}
|
||||
|
||||
void ChannelAnalyzerNGGUI::channelizerInputSampleRateChanged()
|
||||
{
|
||||
//ui->channelSampleRate->setValueRange(7, 2000U, m_channelAnalyzer->getInputSampleRate());
|
||||
setNewFinalRate(m_spanLog2);
|
||||
applySettings();
|
||||
}
|
||||
//void ChannelAnalyzerNGGUI::channelizerInputSampleRateChanged()
|
||||
//{
|
||||
// //ui->channelSampleRate->setValueRange(7, 2000U, m_channelAnalyzer->getInputSampleRate());
|
||||
// setNewFinalRate(m_spanLog2);
|
||||
// applySettings();
|
||||
//}
|
||||
|
||||
void ChannelAnalyzerNGGUI::on_channelSampleRate_changed(quint64 value)
|
||||
{
|
||||
@ -204,7 +226,7 @@ int ChannelAnalyzerNGGUI::getRequestedChannelSampleRate()
|
||||
if (ui->useRationalDownsampler->isChecked()) {
|
||||
return ui->channelSampleRate->getValueNew();
|
||||
} else {
|
||||
return m_channelizer->getInputSampleRate();
|
||||
return m_channelAnalyzer->getChannelizer()->getInputSampleRate();
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,11 +370,13 @@ ChannelAnalyzerNGGUI::ChannelAnalyzerNGGUI(PluginAPI* pluginAPI, DeviceSourceAPI
|
||||
m_spectrumVis = new SpectrumVis(ui->glSpectrum);
|
||||
m_scopeVis = new ScopeVisNG(ui->glScope);
|
||||
m_spectrumScopeComboVis = new SpectrumScopeNGComboVis(m_spectrumVis, m_scopeVis);
|
||||
m_channelAnalyzer = new ChannelAnalyzerNG(m_spectrumScopeComboVis);
|
||||
m_channelizer = new DownChannelizer(m_channelAnalyzer);
|
||||
m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
|
||||
connect(m_channelizer, SIGNAL(inputSampleRateChanged()), this, SLOT(channelizerInputSampleRateChanged()));
|
||||
m_deviceAPI->addThreadedSink(m_threadedChannelizer);
|
||||
m_channelAnalyzer = new ChannelAnalyzerNG(m_deviceAPI);
|
||||
m_channelAnalyzer->setSampleSink(m_spectrumScopeComboVis);
|
||||
m_channelAnalyzer->setMessageQueueToGUI(getInputMessageQueue());
|
||||
// m_channelizer = new DownChannelizer(m_channelAnalyzer);
|
||||
// m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
|
||||
// connect(m_channelizer, SIGNAL(inputSampleRateChanged()), this, SLOT(channelizerInputSampleRateChanged()));
|
||||
// m_deviceAPI->addThreadedSink(m_threadedChannelizer);
|
||||
|
||||
ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03)));
|
||||
ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
|
||||
@ -389,6 +413,8 @@ ChannelAnalyzerNGGUI::ChannelAnalyzerNGGUI(PluginAPI* pluginAPI, DeviceSourceAPI
|
||||
ui->spectrumGUI->setBuddies(m_spectrumVis->getInputMessageQueue(), m_spectrumVis, ui->glSpectrum);
|
||||
ui->scopeGUI->setBuddies(m_scopeVis->getInputMessageQueue(), m_scopeVis, ui->glScope);
|
||||
|
||||
connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()));
|
||||
|
||||
applySettings();
|
||||
setNewFinalRate(m_spanLog2);
|
||||
}
|
||||
@ -396,9 +422,9 @@ ChannelAnalyzerNGGUI::ChannelAnalyzerNGGUI(PluginAPI* pluginAPI, DeviceSourceAPI
|
||||
ChannelAnalyzerNGGUI::~ChannelAnalyzerNGGUI()
|
||||
{
|
||||
m_deviceAPI->removeChannelInstance(this);
|
||||
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
|
||||
delete m_threadedChannelizer;
|
||||
delete m_channelizer;
|
||||
// m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
|
||||
// delete m_threadedChannelizer;
|
||||
// delete m_channelizer;
|
||||
delete m_channelAnalyzer;
|
||||
delete m_spectrumVis;
|
||||
delete m_scopeVis;
|
||||
@ -514,14 +540,25 @@ void ChannelAnalyzerNGGUI::applySettings()
|
||||
setTitleColor(m_channelMarker.getColor());
|
||||
ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency());
|
||||
|
||||
m_channelizer->configure(m_channelizer->getInputMessageQueue(),
|
||||
//m_channelizer->getInputSampleRate(),
|
||||
getRequestedChannelSampleRate(),
|
||||
int sampleRate = getRequestedChannelSampleRate();
|
||||
|
||||
ChannelAnalyzerNG::MsgConfigureChannelizer *msgChannelizer = ChannelAnalyzerNG::MsgConfigureChannelizer::create(sampleRate, m_channelMarker.getCenterFrequency());
|
||||
m_channelAnalyzer->getInputMessageQueue()->push(msgChannelizer);
|
||||
|
||||
ChannelAnalyzerNG::MsgConfigureChannelizer *msg =
|
||||
ChannelAnalyzerNG::MsgConfigureChannelizer::create(
|
||||
sampleRate,
|
||||
m_channelMarker.getCenterFrequency());
|
||||
m_channelAnalyzer->getInputMessageQueue()->push(msg);
|
||||
|
||||
// m_channelizer->configure(m_channelizer->getInputMessageQueue(),
|
||||
// //m_channelizer->getInputSampleRate(),
|
||||
// getRequestedChannelSampleRate(),
|
||||
// m_channelMarker.getCenterFrequency());
|
||||
|
||||
m_channelAnalyzer->configure(m_channelAnalyzer->getInputMessageQueue(),
|
||||
//m_channelizer->getInputSampleRate(), // TODO: specify required channel sample rate
|
||||
getRequestedChannelSampleRate(), // TODO: specify required channel sample rate
|
||||
sampleRate, // TODO: specify required channel sample rate
|
||||
ui->BW->value() * 100.0,
|
||||
ui->lowCut->value() * 100.0,
|
||||
m_spanLog2,
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
|
||||
private slots:
|
||||
void viewChanged();
|
||||
void channelizerInputSampleRateChanged();
|
||||
// void channelizerInputSampleRateChanged();
|
||||
void on_deltaFrequency_changed(qint64 value);
|
||||
void on_channelSampleRate_changed(quint64 value);
|
||||
void on_useRationalDownsampler_toggled(bool checked);
|
||||
@ -69,6 +69,7 @@ private slots:
|
||||
void on_ssb_toggled(bool checked);
|
||||
void onWidgetRolled(QWidget* widget, bool rollDown);
|
||||
void onMenuDoubleClicked();
|
||||
void handleInputMessages();
|
||||
void tick();
|
||||
|
||||
private:
|
||||
@ -82,8 +83,8 @@ private:
|
||||
int m_spanLog2;
|
||||
MovingAverage<double> m_channelPowerDbAvg;
|
||||
|
||||
ThreadedBasebandSampleSink* m_threadedChannelizer;
|
||||
DownChannelizer* m_channelizer;
|
||||
// ThreadedBasebandSampleSink* m_threadedChannelizer;
|
||||
// DownChannelizer* m_channelizer;
|
||||
ChannelAnalyzerNG* m_channelAnalyzer;
|
||||
SpectrumScopeNGComboVis* m_spectrumScopeComboVis;
|
||||
SpectrumVis* m_spectrumVis;
|
||||
|
Loading…
Reference in New Issue
Block a user