1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

WFM demod: use settings in demod

This commit is contained in:
f4exb 2017-10-08 03:17:13 +02:00
parent 8a7dcfa4dd
commit f9b426de69
3 changed files with 115 additions and 155 deletions

View File

@ -27,6 +27,7 @@
#include "dsp/pidcontroller.h"
MESSAGE_CLASS_DEFINITION(WFMDemod::MsgConfigureWFMDemod, Message)
MESSAGE_CLASS_DEFINITION(WFMDemod::MsgConfigureChannelizer, Message)
WFMDemod::WFMDemod(BasebandSampleSink* sampleSink) :
m_squelchOpen(false),
@ -42,24 +43,16 @@ WFMDemod::WFMDemod(BasebandSampleSink* sampleSink) :
{
setObjectName("WFMDemod");
m_config.m_inputSampleRate = 384000;
m_config.m_inputFrequencyOffset = 0;
m_config.m_rfBandwidth = 180000;
m_config.m_afBandwidth = 15000;
m_config.m_squelch = -60.0;
m_config.m_volume = 2.0;
m_config.m_audioSampleRate = DSPEngine::instance()->getAudioSampleRate();
m_rfFilter = new fftfilt(-50000.0 / 384000.0, 50000.0 / 384000.0, rfFilterFftLength);
m_phaseDiscri.setFMScaling(384000/75000);
apply();
m_audioBuffer.resize(16384);
m_audioBufferFill = 0;
m_movingAverage.resize(16, 0);
DSPEngine::instance()->addAudioSink(&m_audioFifo);
applySettings(m_settings, true);
}
WFMDemod::~WFMDemod()
@ -72,18 +65,6 @@ WFMDemod::~WFMDemod()
DSPEngine::instance()->removeAudioSink(&m_audioFifo);
}
void WFMDemod::configure(
MessageQueue* messageQueue,
Real rfBandwidth,
Real afBandwidth,
Real volume,
Real squelch,
bool audioMute)
{
Message* cmd = MsgConfigureWFMDemod::create(rfBandwidth, afBandwidth, volume, squelch, audioMute);
messageQueue->push(cmd);
}
void WFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst __attribute__((unused)))
{
Complex ci;
@ -119,7 +100,7 @@ void WFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
m_magsqCount++;
if(m_movingAverage.average() >= m_squelchLevel)
m_squelchState = m_running.m_rfBandwidth / 20; // decay rate
m_squelchState = m_settings.m_rfBandwidth / 20; // decay rate
if (m_squelchState > 0)
{
@ -132,7 +113,7 @@ void WFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
m_squelchOpen = false;
}
if (m_running.m_audioMute)
if (m_settings.m_audioMute)
{
demod = 0;
}
@ -141,7 +122,7 @@ void WFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVecto
if(m_interpolator.decimate(&m_interpolatorDistanceRemain, e, &ci))
{
quint16 sample = (qint16)(ci.real() * 3276.8f * m_running.m_volume);
quint16 sample = (qint16)(ci.real() * 3276.8f * m_settings.m_volume);
m_sampleBuffer.push_back(Sample(sample, sample));
m_audioBuffer[m_audioBufferFill].l = sample;
m_audioBuffer[m_audioBufferFill].r = sample;
@ -203,36 +184,42 @@ bool WFMDemod::handleMessage(const Message& cmd)
{
DownChannelizer::MsgChannelizerNotification& notif = (DownChannelizer::MsgChannelizerNotification&) cmd;
m_config.m_inputSampleRate = notif.getSampleRate();
m_config.m_inputFrequencyOffset = notif.getFrequencyOffset();
WFMDemodSettings settings = m_settings;
qDebug() << "WFMDemod::handleMessage: MsgChannelizerNotification: m_inputSampleRate: " << m_config.m_inputSampleRate
<< " m_inputFrequencyOffset: " << m_config.m_inputFrequencyOffset;
settings.m_inputSampleRate = notif.getSampleRate();
settings.m_inputFrequencyOffset = notif.getFrequencyOffset();
apply();
applySettings(settings);
qDebug() << "WFMDemod::handleMessage: MsgChannelizerNotification: m_inputSampleRate: " << settings.m_inputSampleRate
<< " m_inputFrequencyOffset: " << settings.m_inputFrequencyOffset;
return true;
}
else if (MsgConfigureWFMDemod::match(cmd))
{
MsgConfigureWFMDemod& cfg = (MsgConfigureWFMDemod&) cmd;
else if (MsgConfigureWFMDemod::match(cmd))
{
MsgConfigureWFMDemod& cfg = (MsgConfigureWFMDemod&) cmd;
m_config.m_rfBandwidth = cfg.getRFBandwidth();
m_config.m_afBandwidth = cfg.getAFBandwidth();
m_config.m_volume = cfg.getVolume();
m_config.m_squelch = cfg.getSquelch();
m_config.m_audioMute = cfg.getAudioMute();
WFMDemodSettings settings = cfg.getSettings();
qDebug() << "WFMDemod::handleMessage: MsgConfigureWFMDemod: m_rfBandwidth: " << m_config.m_rfBandwidth
<< " m_afBandwidth: " << m_config.m_afBandwidth
<< " m_volume: " << m_config.m_volume
<< " m_squelch: " << m_config.m_squelch
<< " m_audioMute: " << m_config.m_audioMute;
// These settings are set with DownChannelizer::MsgChannelizerNotification
settings.m_inputSampleRate = m_settings.m_inputSampleRate;
settings.m_inputFrequencyOffset = m_settings.m_inputFrequencyOffset;
apply();
applySettings(settings, cfg.getForce());
return true;
}
qDebug() << "WFMDemod::handleMessage: MsgConfigureWFMDemod:"
<< " m_rfBandwidth: " << settings.m_rfBandwidth
<< " m_afBandwidth: " << settings.m_afBandwidth
<< " m_volume: " << settings.m_volume
<< " m_squelch: " << settings.m_squelch
<< " m_copyAudioToUDP: " << settings.m_copyAudioToUDP
<< " m_udpAddress: " << settings.m_udpAddress
<< " m_udpPort: " << settings.m_udpPort
<< " force: " << cfg.getForce();
return true;
}
else
{
if (m_sampleSink != 0)
@ -246,49 +233,41 @@ bool WFMDemod::handleMessage(const Message& cmd)
}
}
void WFMDemod::apply()
void WFMDemod::applySettings(const WFMDemodSettings& settings, bool force)
{
if((settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) ||
(settings.m_inputSampleRate != m_settings.m_inputSampleRate) || force)
{
qDebug() << "WFMDemod::applySettings: m_nco.setFreq";
m_nco.setFreq(-settings.m_inputFrequencyOffset, settings.m_inputSampleRate);
}
if((m_config.m_inputFrequencyOffset != m_running.m_inputFrequencyOffset) ||
(m_config.m_inputSampleRate != m_running.m_inputSampleRate))
{
qDebug() << "WFMDemod::apply: m_nco.setFreq";
m_nco.setFreq(-m_config.m_inputFrequencyOffset, m_config.m_inputSampleRate);
}
if((m_config.m_inputSampleRate != m_running.m_inputSampleRate) ||
(m_config.m_audioSampleRate != m_running.m_audioSampleRate) ||
(m_config.m_afBandwidth != m_running.m_afBandwidth) ||
(m_config.m_rfBandwidth != m_running.m_rfBandwidth))
{
m_settingsMutex.lock();
qDebug() << "WFMDemod::apply: m_interpolator.create";
m_interpolator.create(16, m_config.m_inputSampleRate, m_config.m_afBandwidth);
m_interpolatorDistanceRemain = (Real) m_config.m_inputSampleRate / (Real) m_config.m_audioSampleRate;
m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_audioSampleRate;
qDebug() << "WFMDemod::apply: m_rfFilter->create_filter";
Real lowCut = -(m_config.m_rfBandwidth / 2.0) / m_config.m_inputSampleRate;
Real hiCut = (m_config.m_rfBandwidth / 2.0) / m_config.m_inputSampleRate;
if((settings.m_inputSampleRate != m_settings.m_inputSampleRate) ||
(settings.m_audioSampleRate != m_settings.m_audioSampleRate) ||
(settings.m_afBandwidth != m_settings.m_afBandwidth) ||
(settings.m_rfBandwidth != m_settings.m_rfBandwidth) || force)
{
m_settingsMutex.lock();
qDebug() << "WFMDemod::applySettings: m_interpolator.create";
m_interpolator.create(16, settings.m_inputSampleRate, settings.m_afBandwidth);
m_interpolatorDistanceRemain = (Real) settings.m_inputSampleRate / (Real) settings.m_audioSampleRate;
m_interpolatorDistance = (Real) settings.m_inputSampleRate / (Real) settings.m_audioSampleRate;
qDebug() << "WFMDemod::applySettings: m_rfFilter->create_filter";
Real lowCut = -(settings.m_rfBandwidth / 2.0) / settings.m_inputSampleRate;
Real hiCut = (settings.m_rfBandwidth / 2.0) / settings.m_inputSampleRate;
m_rfFilter->create_filter(lowCut, hiCut);
m_fmExcursion = m_config.m_rfBandwidth / (Real) m_config.m_inputSampleRate;
m_fmExcursion = settings.m_rfBandwidth / (Real) settings.m_inputSampleRate;
m_phaseDiscri.setFMScaling(1.0f/m_fmExcursion);
qDebug("WFMDemod::apply: m_fmExcursion: %f", m_fmExcursion);
m_settingsMutex.unlock();
}
qDebug("WFMDemod::applySettings: m_fmExcursion: %f", m_fmExcursion);
m_settingsMutex.unlock();
}
if(m_config.m_squelch != m_running.m_squelch)
{
qDebug() << "WFMDemod::apply: set m_squelchLevel";
m_squelchLevel = pow(10.0, m_config.m_squelch / 20.0);
m_squelchLevel *= m_squelchLevel;
}
if ((settings.m_squelch != m_settings.m_squelch) || force)
{
qDebug() << "WFMDemod::applySettings: set m_squelchLevel";
m_squelchLevel = pow(10.0, settings.m_squelch / 20.0);
m_squelchLevel *= m_squelchLevel;
}
m_running.m_inputSampleRate = m_config.m_inputSampleRate;
m_running.m_inputFrequencyOffset = m_config.m_inputFrequencyOffset;
m_running.m_rfBandwidth = m_config.m_rfBandwidth;
m_running.m_afBandwidth = m_config.m_afBandwidth;
m_running.m_squelch = m_config.m_squelch;
m_running.m_volume = m_config.m_volume;
m_running.m_audioSampleRate = m_config.m_audioSampleRate;
m_running.m_audioMute = m_config.m_audioMute;
m_settings = settings;
}

View File

@ -30,21 +30,61 @@
#include "audio/audiofifo.h"
#include "util/message.h"
#include "wfmdemodsettings.h"
#define rfFilterFftLength 1024
class WFMDemod : public BasebandSampleSink {
public:
class MsgConfigureWFMDemod : public Message {
MESSAGE_CLASS_DECLARATION
public:
const WFMDemodSettings& getSettings() const { return m_settings; }
bool getForce() const { return m_force; }
static MsgConfigureWFMDemod* create(const WFMDemodSettings& settings, bool force)
{
return new MsgConfigureWFMDemod(settings, force);
}
private:
WFMDemodSettings m_settings;
bool m_force;
MsgConfigureWFMDemod(const WFMDemodSettings& settings, bool force) :
Message(),
m_settings(settings),
m_force(force)
{ }
};
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)
{ }
};
WFMDemod(BasebandSampleSink* sampleSink);
virtual ~WFMDemod();
void configure(
MessageQueue* messageQueue,
Real rfBandwidth,
Real afBandwidth,
Real volume,
Real squelch,
bool auduiMute);
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po);
virtual void start();
virtual void stop();
@ -65,67 +105,12 @@ public:
}
private:
class MsgConfigureWFMDemod : public Message {
MESSAGE_CLASS_DECLARATION
public:
Real getRFBandwidth() const { return m_rfBandwidth; }
Real getAFBandwidth() const { return m_afBandwidth; }
Real getVolume() const { return m_volume; }
Real getSquelch() const { return m_squelch; }
bool getAudioMute() const { return m_audioMute; }
static MsgConfigureWFMDemod* create(Real rfBandwidth, Real afBandwidth, Real volume, Real squelch, bool audioMute)
{
return new MsgConfigureWFMDemod(rfBandwidth, afBandwidth, volume, squelch, audioMute);
}
private:
Real m_rfBandwidth;
Real m_afBandwidth;
Real m_volume;
Real m_squelch;
bool m_audioMute;
MsgConfigureWFMDemod(Real rfBandwidth, Real afBandwidth, Real volume, Real squelch, bool audioMute) :
Message(),
m_rfBandwidth(rfBandwidth),
m_afBandwidth(afBandwidth),
m_volume(volume),
m_squelch(squelch),
m_audioMute(audioMute)
{ }
};
enum RateState {
RSInitialFill,
RSRunning
};
struct Config {
int m_inputSampleRate;
qint64 m_inputFrequencyOffset;
Real m_rfBandwidth;
Real m_afBandwidth;
Real m_squelch;
Real m_volume;
quint32 m_audioSampleRate;
bool m_audioMute;
Config() :
m_inputSampleRate(-1),
m_inputFrequencyOffset(0),
m_rfBandwidth(-1),
m_afBandwidth(-1),
m_squelch(0),
m_volume(0),
m_audioSampleRate(0),
m_audioMute(false)
{ }
};
Config m_config;
Config m_running;
WFMDemodSettings m_settings;
NCO m_nco;
Interpolator m_interpolator; //!< Interpolator between sample rate sent from DSP engine and requested RF bandwidth (rational)
@ -155,7 +140,7 @@ private:
PhaseDiscriminators m_phaseDiscri;
void apply();
void applySettings(const WFMDemodSettings& settings, bool force = false);
};
#endif // INCLUDE_WFMDEMOD_H

View File

@ -225,12 +225,8 @@ void WFMDemodGUI::applySettings(bool force)
ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency());
m_wfmDemod->configure(m_wfmDemod->getInputMessageQueue(),
m_settings.m_rfBandwidth,
m_settings.m_afBandwidth,
m_settings.m_volume,
m_settings.m_squelch,
m_settings.m_audioMute);
WFMDemod::MsgConfigureWFMDemod* msgConfig = WFMDemod::MsgConfigureWFMDemod::create( m_settings, force);
m_wfmDemod->getInputMessageQueue()->push(msgConfig);
}
}