2015-12-06 04:30:51 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2015-12-06 13:47:55 -05:00
|
|
|
// Copyright (C) 2015 F4EXB //
|
|
|
|
// written by Edouard Griffiths //
|
2015-12-06 04:30:51 -05:00
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <QTime>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <complex.h>
|
2017-10-01 06:48:31 -04:00
|
|
|
|
2015-12-06 04:30:51 -05:00
|
|
|
#include "audio/audiooutput.h"
|
2018-03-10 01:03:11 -05:00
|
|
|
#include "audio/audionetsink.h"
|
2015-12-06 04:30:51 -05:00
|
|
|
#include "dsp/dspengine.h"
|
2018-02-14 14:11:36 -05:00
|
|
|
#include "dsp/downchannelizer.h"
|
2017-10-01 06:48:31 -04:00
|
|
|
#include "dsp/threadedbasebandsamplesink.h"
|
2018-02-14 14:11:36 -05:00
|
|
|
#include "dsp/dspcommands.h"
|
2017-10-01 06:48:31 -04:00
|
|
|
#include "device/devicesourceapi.h"
|
2016-10-02 15:52:39 -04:00
|
|
|
|
2017-08-25 23:32:01 -04:00
|
|
|
#include "rdsparser.h"
|
2017-10-01 06:48:31 -04:00
|
|
|
#include "bfmdemod.h"
|
2016-10-02 07:18:07 -04:00
|
|
|
|
2017-10-01 06:48:31 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(BFMDemod::MsgConfigureChannelizer, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(BFMDemod::MsgReportChannelSampleRateChanged, Message)
|
2015-12-06 04:30:51 -05:00
|
|
|
MESSAGE_CLASS_DEFINITION(BFMDemod::MsgConfigureBFMDemod, Message)
|
|
|
|
|
2017-11-22 19:19:32 -05:00
|
|
|
const QString BFMDemod::m_channelIdURI = "sdrangel.channel.bfm";
|
|
|
|
const QString BFMDemod::m_channelId = "BFMDemod";
|
2016-03-21 03:40:42 -04:00
|
|
|
const Real BFMDemod::default_deemphasis = 50.0; // 50 us
|
2017-08-25 12:56:43 -04:00
|
|
|
const int BFMDemod::m_udpBlockSize = 512;
|
2016-03-21 03:40:42 -04:00
|
|
|
|
2017-10-01 06:48:31 -04:00
|
|
|
BFMDemod::BFMDemod(DeviceSourceAPI *deviceAPI) :
|
2017-12-20 17:57:06 -05:00
|
|
|
ChannelSinkAPI(m_channelIdURI),
|
|
|
|
m_deviceAPI(deviceAPI),
|
2017-12-29 05:04:47 -05:00
|
|
|
m_inputSampleRate(384000),
|
|
|
|
m_inputFrequencyOffset(0),
|
2017-12-20 17:57:06 -05:00
|
|
|
m_audioFifo(250000),
|
|
|
|
m_settingsMutex(QMutex::Recursive),
|
|
|
|
m_pilotPLL(19000/384000, 50/384000, 0.01),
|
|
|
|
m_deemphasisFilterX(default_deemphasis * 48000 * 1.0e-6),
|
|
|
|
m_deemphasisFilterY(default_deemphasis * 48000 * 1.0e-6),
|
2015-12-16 19:13:42 -05:00
|
|
|
m_fmExcursion(default_excursion)
|
2015-12-06 04:30:51 -05:00
|
|
|
{
|
2017-11-22 19:19:32 -05:00
|
|
|
setObjectName(m_channelId);
|
2015-12-06 04:30:51 -05:00
|
|
|
|
2018-03-27 17:57:29 -04:00
|
|
|
DSPEngine::instance()->getAudioDeviceManager()->addAudioSink(&m_audioFifo, getInputMessageQueue());
|
|
|
|
m_audioSampleRate = DSPEngine::instance()->getAudioDeviceManager()->getOutputSampleRate();
|
|
|
|
|
2017-10-01 10:02:34 -04:00
|
|
|
m_magsq = 0.0f;
|
|
|
|
m_magsqSum = 0.0f;
|
|
|
|
m_magsqPeak = 0.0f;
|
|
|
|
m_magsqCount = 0;
|
|
|
|
|
|
|
|
m_squelchLevel = 0;
|
2017-10-01 14:17:20 -04:00
|
|
|
m_squelchState = 0;
|
2017-10-01 10:02:34 -04:00
|
|
|
|
|
|
|
m_interpolatorDistance = 0.0f;
|
|
|
|
m_interpolatorDistanceRemain = 0.0f;
|
|
|
|
|
|
|
|
m_interpolatorRDSDistance = 0.0f;
|
|
|
|
m_interpolatorRDSDistanceRemain = 0.0f;
|
|
|
|
|
|
|
|
m_interpolatorStereoDistance = 0.0f;
|
|
|
|
m_interpolatorStereoDistanceRemain = 0.0f;
|
|
|
|
|
|
|
|
m_sampleSink = 0;
|
|
|
|
m_m1Arg = 0;
|
|
|
|
|
|
|
|
m_rfFilter = new fftfilt(-50000.0 / 384000.0, 50000.0 / 384000.0, filtFftLen);
|
|
|
|
|
2017-10-01 06:48:31 -04:00
|
|
|
|
2018-03-27 17:57:29 -04:00
|
|
|
m_deemphasisFilterX.configure(default_deemphasis * m_audioSampleRate * 1.0e-6);
|
|
|
|
m_deemphasisFilterY.configure(default_deemphasis * m_audioSampleRate * 1.0e-6);
|
2017-10-01 10:02:34 -04:00
|
|
|
m_phaseDiscri.setFMScaling(384000/m_fmExcursion);
|
2015-12-06 04:30:51 -05:00
|
|
|
|
|
|
|
m_audioBuffer.resize(16384);
|
|
|
|
m_audioBufferFill = 0;
|
|
|
|
|
2018-03-16 05:24:19 -04:00
|
|
|
applyChannelSettings(m_inputSampleRate, m_inputFrequencyOffset, true);
|
|
|
|
applySettings(m_settings, true);
|
|
|
|
|
2017-11-05 19:39:44 -05:00
|
|
|
m_channelizer = new DownChannelizer(this);
|
|
|
|
m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
|
|
|
|
m_deviceAPI->addThreadedSink(m_threadedChannelizer);
|
2017-11-18 21:38:07 -05:00
|
|
|
m_deviceAPI->addChannelAPI(this);
|
2015-12-06 04:30:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
BFMDemod::~BFMDemod()
|
|
|
|
{
|
|
|
|
if (m_rfFilter)
|
|
|
|
{
|
|
|
|
delete m_rfFilter;
|
|
|
|
}
|
|
|
|
|
2018-03-23 22:36:49 -04:00
|
|
|
DSPEngine::instance()->getAudioDeviceManager()->removeAudioSink(&m_audioFifo);
|
2017-10-01 06:48:31 -04:00
|
|
|
|
2017-11-18 21:38:07 -05:00
|
|
|
m_deviceAPI->removeChannelAPI(this);
|
2017-10-01 06:48:31 -04:00
|
|
|
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
|
|
|
|
delete m_threadedChannelizer;
|
|
|
|
delete m_channelizer;
|
2015-12-06 04:30:51 -05:00
|
|
|
}
|
|
|
|
|
2017-05-25 14:13:34 -04:00
|
|
|
void BFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst __attribute__((unused)))
|
2015-12-06 04:30:51 -05:00
|
|
|
{
|
2015-12-12 09:14:26 -05:00
|
|
|
Complex ci, cs, cr;
|
2015-12-06 04:30:51 -05:00
|
|
|
fftfilt::cmplx *rf;
|
|
|
|
int rf_out;
|
2017-05-16 17:39:49 -04:00
|
|
|
double msq;
|
|
|
|
Real demod;
|
2015-12-06 04:30:51 -05:00
|
|
|
|
2015-12-06 13:47:55 -05:00
|
|
|
m_sampleBuffer.clear();
|
|
|
|
|
2015-12-06 04:30:51 -05:00
|
|
|
m_settingsMutex.lock();
|
|
|
|
|
|
|
|
for (SampleVector::const_iterator it = begin; it != end; ++it)
|
|
|
|
{
|
2018-01-22 02:46:05 -05:00
|
|
|
Complex c(it->real() / SDR_RX_SCALEF, it->imag() / SDR_RX_SCALEF);
|
2015-12-06 04:30:51 -05:00
|
|
|
c *= m_nco.nextIQ();
|
|
|
|
|
|
|
|
rf_out = m_rfFilter->runFilt(c, &rf); // filter RF before demod
|
|
|
|
|
|
|
|
for (int i =0 ; i <rf_out; i++)
|
|
|
|
{
|
|
|
|
msq = rf[i].real()*rf[i].real() + rf[i].imag()*rf[i].imag();
|
|
|
|
|
2016-12-06 13:06:38 -05:00
|
|
|
m_magsqSum += msq;
|
2015-12-06 04:30:51 -05:00
|
|
|
|
2016-12-06 13:06:38 -05:00
|
|
|
if (msq > m_magsqPeak)
|
|
|
|
{
|
|
|
|
m_magsqPeak = msq;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_magsqCount++;
|
|
|
|
|
|
|
|
// m_movingAverage.feed(msq);
|
|
|
|
|
|
|
|
if(m_magsq >= m_squelchLevel) {
|
2017-10-01 14:17:20 -04:00
|
|
|
m_squelchState = m_settings.m_rfBandwidth / 20; // decay rate
|
2016-12-06 13:06:38 -05:00
|
|
|
}
|
2015-12-06 04:30:51 -05:00
|
|
|
|
|
|
|
if(m_squelchState > 0)
|
|
|
|
{
|
|
|
|
m_squelchState--;
|
|
|
|
|
2015-12-11 20:17:41 -05:00
|
|
|
//demod = phaseDiscriminator2(rf[i], msq);
|
2015-12-16 19:13:42 -05:00
|
|
|
demod = m_phaseDiscri.phaseDiscriminator(rf[i]);
|
2015-12-06 04:30:51 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
demod = 0;
|
|
|
|
}
|
|
|
|
|
2017-10-01 14:17:20 -04:00
|
|
|
if (!m_settings.m_showPilot)
|
2015-12-08 18:04:46 -05:00
|
|
|
{
|
2018-01-22 02:46:05 -05:00
|
|
|
m_sampleBuffer.push_back(Sample(demod * SDR_RX_SCALEF, 0.0));
|
2015-12-08 18:04:46 -05:00
|
|
|
}
|
|
|
|
|
2017-10-01 14:17:20 -04:00
|
|
|
if (m_settings.m_rdsActive)
|
2015-12-10 08:10:48 -05:00
|
|
|
{
|
2015-12-25 18:19:41 -05:00
|
|
|
//Complex r(demod * 2.0 * std::cos(3.0 * m_pilotPLLSamples[3]), 0.0);
|
|
|
|
Complex r(demod * 2.0 * std::cos(3.0 * m_pilotPLLSamples[3]), 0.0);
|
2015-12-12 09:14:26 -05:00
|
|
|
|
2016-10-09 19:53:32 -04:00
|
|
|
if (m_interpolatorRDS.decimate(&m_interpolatorRDSDistanceRemain, r, &cr))
|
2015-12-12 09:14:26 -05:00
|
|
|
{
|
2015-12-12 20:54:22 -05:00
|
|
|
bool bit;
|
|
|
|
|
|
|
|
if (m_rdsDemod.process(cr.real(), bit))
|
|
|
|
{
|
2015-12-13 03:45:29 -05:00
|
|
|
if (m_rdsDecoder.frameSync(bit))
|
|
|
|
{
|
2017-10-01 05:50:16 -04:00
|
|
|
m_rdsParser.parseGroup(m_rdsDecoder.getGroup());
|
2015-12-13 03:45:29 -05:00
|
|
|
}
|
2015-12-12 20:54:22 -05:00
|
|
|
}
|
|
|
|
|
2015-12-12 09:14:26 -05:00
|
|
|
m_interpolatorRDSDistanceRemain += m_interpolatorRDSDistance;
|
|
|
|
}
|
2015-12-10 08:10:48 -05:00
|
|
|
}
|
|
|
|
|
2017-05-25 14:13:34 -04:00
|
|
|
Real sampleStereo = 0.0f;
|
2015-12-06 22:16:05 -05:00
|
|
|
|
2015-12-07 02:55:22 -05:00
|
|
|
// Process stereo if stereo mode is selected
|
|
|
|
|
2017-10-01 14:17:20 -04:00
|
|
|
if (m_settings.m_audioStereo)
|
2015-12-06 22:16:05 -05:00
|
|
|
{
|
2015-12-07 16:31:44 -05:00
|
|
|
m_pilotPLL.process(demod, m_pilotPLLSamples);
|
2015-12-08 18:04:46 -05:00
|
|
|
|
2017-10-01 14:17:20 -04:00
|
|
|
if (m_settings.m_showPilot)
|
2015-12-08 18:04:46 -05:00
|
|
|
{
|
2018-01-22 02:46:05 -05:00
|
|
|
m_sampleBuffer.push_back(Sample(m_pilotPLLSamples[1] * SDR_RX_SCALEF, 0.0)); // debug 38 kHz pilot
|
2015-12-08 18:04:46 -05:00
|
|
|
}
|
2015-12-07 02:55:22 -05:00
|
|
|
|
2017-10-01 14:17:20 -04:00
|
|
|
if (m_settings.m_lsbStereo)
|
2015-12-25 18:19:41 -05:00
|
|
|
{
|
|
|
|
// 1.17 * 0.7 = 0.819
|
|
|
|
Complex s(demod * m_pilotPLLSamples[1], demod * m_pilotPLLSamples[2]);
|
2015-12-06 22:16:05 -05:00
|
|
|
|
2016-10-09 19:53:32 -04:00
|
|
|
if (m_interpolatorStereo.decimate(&m_interpolatorStereoDistanceRemain, s, &cs))
|
2015-12-25 18:19:41 -05:00
|
|
|
{
|
|
|
|
sampleStereo = cs.real() + cs.imag();
|
|
|
|
m_interpolatorStereoDistanceRemain += m_interpolatorStereoDistance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2015-12-07 02:55:22 -05:00
|
|
|
{
|
2015-12-25 18:19:41 -05:00
|
|
|
Complex s(demod * 1.17 * m_pilotPLLSamples[1], 0);
|
|
|
|
|
2016-10-09 19:53:32 -04:00
|
|
|
if (m_interpolatorStereo.decimate(&m_interpolatorStereoDistanceRemain, s, &cs))
|
2015-12-25 18:19:41 -05:00
|
|
|
{
|
|
|
|
sampleStereo = cs.real();
|
|
|
|
m_interpolatorStereoDistanceRemain += m_interpolatorStereoDistance;
|
|
|
|
}
|
2015-12-07 02:55:22 -05:00
|
|
|
}
|
|
|
|
}
|
2015-12-06 22:16:05 -05:00
|
|
|
|
2015-12-06 04:30:51 -05:00
|
|
|
Complex e(demod, 0);
|
|
|
|
|
2016-10-09 19:53:32 -04:00
|
|
|
if (m_interpolator.decimate(&m_interpolatorDistanceRemain, e, &ci))
|
2015-12-06 04:30:51 -05:00
|
|
|
{
|
2017-10-01 14:17:20 -04:00
|
|
|
if (m_settings.m_audioStereo)
|
2015-12-07 02:55:22 -05:00
|
|
|
{
|
2015-12-07 20:00:30 -05:00
|
|
|
Real deemph_l, deemph_r; // Pre-emphasis is applied on each channel before multiplexing
|
|
|
|
m_deemphasisFilterX.process(ci.real() + sampleStereo, deemph_l);
|
|
|
|
m_deemphasisFilterY.process(ci.real() - sampleStereo, deemph_r);
|
2018-02-24 04:29:27 -05:00
|
|
|
m_audioBuffer[m_audioBufferFill].l = (qint16)(deemph_l * (1<<12) * m_settings.m_volume);
|
|
|
|
m_audioBuffer[m_audioBufferFill].r = (qint16)(deemph_r * (1<<12) * m_settings.m_volume);
|
2015-12-07 02:55:22 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-07 20:00:30 -05:00
|
|
|
Real deemph;
|
2015-12-08 02:30:45 -05:00
|
|
|
m_deemphasisFilterX.process(ci.real(), deemph);
|
2017-10-01 14:17:20 -04:00
|
|
|
quint16 sample = (qint16)(deemph * (1<<12) * m_settings.m_volume);
|
2015-12-07 02:55:22 -05:00
|
|
|
m_audioBuffer[m_audioBufferFill].l = sample;
|
|
|
|
m_audioBuffer[m_audioBufferFill].r = sample;
|
|
|
|
}
|
|
|
|
|
2015-12-06 04:30:51 -05:00
|
|
|
++m_audioBufferFill;
|
|
|
|
|
|
|
|
if(m_audioBufferFill >= m_audioBuffer.size())
|
|
|
|
{
|
|
|
|
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1);
|
|
|
|
|
|
|
|
if(res != m_audioBufferFill)
|
|
|
|
{
|
|
|
|
qDebug("BFMDemod::feed: %u/%u audio samples written", res, m_audioBufferFill);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_audioBufferFill = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_interpolatorDistanceRemain += m_interpolatorDistance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_audioBufferFill > 0)
|
|
|
|
{
|
|
|
|
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 1);
|
|
|
|
|
|
|
|
if(res != m_audioBufferFill)
|
|
|
|
{
|
|
|
|
qDebug("BFMDemod::feed: %u/%u tail samples written", res, m_audioBufferFill);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_audioBufferFill = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_sampleSink != 0)
|
|
|
|
{
|
2015-12-06 13:47:55 -05:00
|
|
|
m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), true);
|
2015-12-06 04:30:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
m_sampleBuffer.clear();
|
|
|
|
|
|
|
|
m_settingsMutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BFMDemod::start()
|
|
|
|
{
|
|
|
|
m_squelchState = 0;
|
|
|
|
m_audioFifo.clear();
|
2015-12-16 19:13:42 -05:00
|
|
|
m_phaseDiscri.reset();
|
2018-01-08 18:59:10 -05:00
|
|
|
applyChannelSettings(m_inputSampleRate, m_inputFrequencyOffset, true);
|
2015-12-06 04:30:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void BFMDemod::stop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BFMDemod::handleMessage(const Message& cmd)
|
|
|
|
{
|
2016-10-02 15:52:39 -04:00
|
|
|
if (DownChannelizer::MsgChannelizerNotification::match(cmd))
|
2015-12-06 04:30:51 -05:00
|
|
|
{
|
2016-10-02 15:52:39 -04:00
|
|
|
DownChannelizer::MsgChannelizerNotification& notif = (DownChannelizer::MsgChannelizerNotification&) cmd;
|
2015-12-06 04:30:51 -05:00
|
|
|
|
2017-12-29 05:04:47 -05:00
|
|
|
qDebug() << "BFMDemod::handleMessage: MsgChannelizerNotification:"
|
|
|
|
<< " inputSampleRate: " << notif.getSampleRate()
|
|
|
|
<< " inputFrequencyOffset: " << notif.getFrequencyOffset();
|
2015-12-06 04:30:51 -05:00
|
|
|
|
2017-12-29 05:04:47 -05:00
|
|
|
applyChannelSettings(notif.getSampleRate(), notif.getFrequencyOffset());
|
2015-12-06 04:30:51 -05:00
|
|
|
|
2017-11-12 08:58:52 -05:00
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
MsgReportChannelSampleRateChanged *msg = MsgReportChannelSampleRateChanged::create(getSampleRate());
|
|
|
|
getMessageQueueToGUI()->push(msg);
|
|
|
|
}
|
|
|
|
|
2015-12-06 04:30:51 -05:00
|
|
|
return true;
|
|
|
|
}
|
2017-10-21 04:35:03 -04:00
|
|
|
else if (MsgConfigureChannelizer::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureChannelizer& cfg = (MsgConfigureChannelizer&) cmd;
|
|
|
|
|
2017-12-29 05:04:47 -05:00
|
|
|
qDebug() << "BFMDemod::handleMessage: MsgConfigureChannelizer: sampleRate: " << cfg.getSampleRate()
|
|
|
|
<< " centerFrequency: " << cfg.getCenterFrequency();
|
|
|
|
|
2017-10-21 04:35:03 -04:00
|
|
|
m_channelizer->configure(m_channelizer->getInputMessageQueue(),
|
|
|
|
cfg.getSampleRate(),
|
|
|
|
cfg.getCenterFrequency());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-01 14:17:20 -04:00
|
|
|
else if (MsgConfigureBFMDemod::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureBFMDemod& cfg = (MsgConfigureBFMDemod&) cmd;
|
2017-12-29 05:04:47 -05:00
|
|
|
qDebug() << "BFMDemod::handleMessage: MsgConfigureBFMDemod";
|
2017-10-01 14:17:20 -04:00
|
|
|
|
2017-12-29 05:04:47 -05:00
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
2017-10-01 14:17:20 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-27 17:57:29 -04:00
|
|
|
else if (DSPConfigureAudio::match(cmd))
|
|
|
|
{
|
|
|
|
DSPConfigureAudio& cfg = (DSPConfigureAudio&) cmd;
|
|
|
|
uint32_t sampleRate = cfg.getSampleRate();
|
|
|
|
|
|
|
|
qDebug() << "BFMDemod::handleMessage: DSPConfigureAudio:"
|
|
|
|
<< " sampleRate: " << sampleRate;
|
|
|
|
|
|
|
|
if (sampleRate != m_audioSampleRate) {
|
|
|
|
applyAudioSampleRate(sampleRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-10 01:03:11 -05:00
|
|
|
else if (BasebandSampleSink::MsgThreadedSink::match(cmd))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-14 14:11:36 -05:00
|
|
|
else if (DSPSignalNotification::match(cmd))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2015-12-06 04:30:51 -05:00
|
|
|
else
|
|
|
|
{
|
2017-10-21 04:35:03 -04:00
|
|
|
qDebug() << "BFMDemod::handleMessage: passed: " << cmd.getIdentifier();
|
2015-12-11 20:17:41 -05:00
|
|
|
|
2015-12-06 04:30:51 -05:00
|
|
|
if (m_sampleSink != 0)
|
|
|
|
{
|
|
|
|
return m_sampleSink->handleMessage(cmd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-27 17:57:29 -04:00
|
|
|
void BFMDemod::applyAudioSampleRate(int sampleRate)
|
|
|
|
{
|
|
|
|
qDebug("BFMDemod::applyAudioSampleRate: %d", sampleRate);
|
|
|
|
|
|
|
|
m_settingsMutex.lock();
|
|
|
|
|
|
|
|
m_interpolator.create(16, m_inputSampleRate, m_settings.m_afBandwidth);
|
|
|
|
m_interpolatorDistanceRemain = (Real) m_inputSampleRate / sampleRate;
|
|
|
|
m_interpolatorDistance = (Real) m_inputSampleRate / (Real) sampleRate;
|
|
|
|
|
|
|
|
m_interpolatorStereo.create(16, m_inputSampleRate, m_settings.m_afBandwidth);
|
|
|
|
m_interpolatorStereoDistanceRemain = (Real) m_inputSampleRate / sampleRate;
|
|
|
|
m_interpolatorStereoDistance = (Real) m_inputSampleRate / (Real) sampleRate;
|
|
|
|
|
|
|
|
m_deemphasisFilterX.configure(default_deemphasis * sampleRate * 1.0e-6);
|
|
|
|
m_deemphasisFilterY.configure(default_deemphasis * sampleRate * 1.0e-6);
|
|
|
|
|
|
|
|
m_settingsMutex.unlock();
|
|
|
|
|
|
|
|
m_audioSampleRate = sampleRate;
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:59:10 -05:00
|
|
|
void BFMDemod::applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force)
|
2015-12-06 04:30:51 -05:00
|
|
|
{
|
2017-12-29 05:04:47 -05:00
|
|
|
qDebug() << "BFMDemod::applyChannelSettings:"
|
|
|
|
<< " inputSampleRate: " << inputSampleRate
|
|
|
|
<< " inputFrequencyOffset: " << inputFrequencyOffset;
|
|
|
|
|
|
|
|
if((inputFrequencyOffset != m_inputFrequencyOffset) ||
|
2018-01-08 18:59:10 -05:00
|
|
|
(inputSampleRate != m_inputSampleRate) || force)
|
2017-12-29 05:04:47 -05:00
|
|
|
{
|
|
|
|
m_nco.setFreq(-inputFrequencyOffset, inputSampleRate);
|
|
|
|
}
|
|
|
|
|
2018-01-08 18:59:10 -05:00
|
|
|
if ((inputSampleRate != m_inputSampleRate) || force)
|
2017-10-01 14:17:20 -04:00
|
|
|
{
|
2017-12-29 05:04:47 -05:00
|
|
|
m_pilotPLL.configure(19000.0/inputSampleRate, 50.0/inputSampleRate, 0.01);
|
|
|
|
|
|
|
|
m_settingsMutex.lock();
|
|
|
|
|
|
|
|
m_interpolator.create(16, inputSampleRate, m_settings.m_afBandwidth);
|
2018-03-27 17:57:29 -04:00
|
|
|
m_interpolatorDistanceRemain = (Real) inputSampleRate / m_audioSampleRate;
|
|
|
|
m_interpolatorDistance = (Real) inputSampleRate / (Real) m_audioSampleRate;
|
2017-12-29 05:04:47 -05:00
|
|
|
|
|
|
|
m_interpolatorStereo.create(16, inputSampleRate, m_settings.m_afBandwidth);
|
2018-03-27 17:57:29 -04:00
|
|
|
m_interpolatorStereoDistanceRemain = (Real) inputSampleRate / m_audioSampleRate;
|
|
|
|
m_interpolatorStereoDistance = (Real) inputSampleRate / (Real) m_audioSampleRate;
|
2017-12-29 05:04:47 -05:00
|
|
|
|
|
|
|
m_interpolatorRDS.create(4, inputSampleRate, 600.0);
|
|
|
|
m_interpolatorRDSDistanceRemain = (Real) inputSampleRate / 250000.0;
|
|
|
|
m_interpolatorRDSDistance = (Real) inputSampleRate / 250000.0;
|
|
|
|
|
|
|
|
Real lowCut = -(m_settings.m_rfBandwidth / 2.0) / inputSampleRate;
|
|
|
|
Real hiCut = (m_settings.m_rfBandwidth / 2.0) / inputSampleRate;
|
|
|
|
m_rfFilter->create_filter(lowCut, hiCut);
|
|
|
|
m_phaseDiscri.setFMScaling(inputSampleRate / m_fmExcursion);
|
|
|
|
|
|
|
|
m_settingsMutex.unlock();
|
2017-10-01 14:17:20 -04:00
|
|
|
}
|
2015-12-06 04:30:51 -05:00
|
|
|
|
2017-12-29 05:04:47 -05:00
|
|
|
m_inputSampleRate = inputSampleRate;
|
|
|
|
m_inputFrequencyOffset = inputFrequencyOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BFMDemod::applySettings(const BFMDemodSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
qDebug() << "BFMDemod::applySettings: MsgConfigureBFMDemod:"
|
|
|
|
<< " m_inputFrequencyOffset: " << settings.m_inputFrequencyOffset
|
|
|
|
<< " m_rfBandwidth: " << settings.m_rfBandwidth
|
|
|
|
<< " m_volume: " << settings.m_volume
|
|
|
|
<< " m_squelch: " << settings.m_squelch
|
|
|
|
<< " m_audioStereo: " << settings.m_audioStereo
|
|
|
|
<< " m_lsbStereo: " << settings.m_lsbStereo
|
|
|
|
<< " m_showPilot: " << settings.m_showPilot
|
|
|
|
<< " m_rdsActive: " << settings.m_rdsActive
|
|
|
|
<< " m_udpAddress: " << settings.m_udpAddress
|
|
|
|
<< " m_udpPort: " << settings.m_udpPort
|
|
|
|
<< " force: " << force;
|
|
|
|
|
|
|
|
if ((settings.m_audioStereo && (settings.m_audioStereo != m_settings.m_audioStereo)) || force)
|
2017-10-01 14:17:20 -04:00
|
|
|
{
|
2017-12-29 05:04:47 -05:00
|
|
|
m_pilotPLL.configure(19000.0/m_inputSampleRate, 50.0/m_inputSampleRate, 0.01);
|
2017-10-01 14:17:20 -04:00
|
|
|
}
|
2015-12-06 04:30:51 -05:00
|
|
|
|
2017-12-29 05:04:47 -05:00
|
|
|
if((settings.m_afBandwidth != m_settings.m_afBandwidth) || force)
|
2017-10-01 14:17:20 -04:00
|
|
|
{
|
|
|
|
m_settingsMutex.lock();
|
2015-12-12 09:14:26 -05:00
|
|
|
|
2017-12-29 05:04:47 -05:00
|
|
|
m_interpolator.create(16, m_inputSampleRate, settings.m_afBandwidth);
|
2018-03-27 17:57:29 -04:00
|
|
|
m_interpolatorDistanceRemain = (Real) m_inputSampleRate / m_audioSampleRate;
|
|
|
|
m_interpolatorDistance = (Real) m_inputSampleRate / (Real) m_audioSampleRate;
|
2015-12-12 09:14:26 -05:00
|
|
|
|
2017-12-29 05:04:47 -05:00
|
|
|
m_interpolatorStereo.create(16, m_inputSampleRate, settings.m_afBandwidth);
|
2018-03-27 17:57:29 -04:00
|
|
|
m_interpolatorStereoDistanceRemain = (Real) m_inputSampleRate / m_audioSampleRate;
|
|
|
|
m_interpolatorStereoDistance = (Real) m_inputSampleRate / (Real) m_audioSampleRate;
|
2015-12-12 09:14:26 -05:00
|
|
|
|
2017-12-29 05:04:47 -05:00
|
|
|
m_interpolatorRDS.create(4, m_inputSampleRate, 600.0);
|
|
|
|
m_interpolatorRDSDistanceRemain = (Real) m_inputSampleRate / 250000.0;
|
|
|
|
m_interpolatorRDSDistance = (Real) m_inputSampleRate / 250000.0;
|
2015-12-12 09:14:26 -05:00
|
|
|
|
2017-10-01 14:17:20 -04:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
}
|
2015-12-06 04:30:51 -05:00
|
|
|
|
2017-12-29 05:04:47 -05:00
|
|
|
if((settings.m_rfBandwidth != m_settings.m_rfBandwidth) ||
|
|
|
|
(settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force)
|
2017-10-01 14:17:20 -04:00
|
|
|
{
|
|
|
|
m_settingsMutex.lock();
|
2017-12-29 05:04:47 -05:00
|
|
|
Real lowCut = -(settings.m_rfBandwidth / 2.0) / m_inputSampleRate;
|
|
|
|
Real hiCut = (settings.m_rfBandwidth / 2.0) / m_inputSampleRate;
|
2017-10-01 14:17:20 -04:00
|
|
|
m_rfFilter->create_filter(lowCut, hiCut);
|
2017-12-29 05:04:47 -05:00
|
|
|
m_phaseDiscri.setFMScaling(m_inputSampleRate / m_fmExcursion);
|
2017-10-01 14:17:20 -04:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
}
|
2015-12-06 04:30:51 -05:00
|
|
|
|
2018-03-27 17:57:29 -04:00
|
|
|
if ((settings.m_afBandwidth != m_settings.m_afBandwidth) || force)
|
2017-10-01 14:17:20 -04:00
|
|
|
{
|
|
|
|
m_settingsMutex.lock();
|
|
|
|
qDebug() << "BFMDemod::handleMessage: m_lowpass.create";
|
2018-03-27 17:57:29 -04:00
|
|
|
m_lowpass.create(21, m_audioSampleRate, settings.m_afBandwidth);
|
2017-10-01 14:17:20 -04:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
}
|
2015-12-06 04:30:51 -05:00
|
|
|
|
2017-10-01 14:17:20 -04:00
|
|
|
if ((settings.m_squelch != m_settings.m_squelch) || force)
|
|
|
|
{
|
|
|
|
qDebug() << "BFMDemod::handleMessage: set m_squelchLevel";
|
|
|
|
m_squelchLevel = std::pow(10.0, settings.m_squelch / 20.0);
|
|
|
|
m_squelchLevel *= m_squelchLevel;
|
|
|
|
}
|
2015-12-06 04:30:51 -05:00
|
|
|
|
2018-03-27 17:57:29 -04:00
|
|
|
if ((settings.m_audioDeviceName != m_settings.m_audioDeviceName) || force)
|
2017-10-01 14:17:20 -04:00
|
|
|
{
|
2018-03-27 17:57:29 -04:00
|
|
|
AudioDeviceManager *audioDeviceManager = DSPEngine::instance()->getAudioDeviceManager();
|
|
|
|
int audioDeviceIndex = audioDeviceManager->getOutputDeviceIndex(settings.m_audioDeviceName);
|
|
|
|
//qDebug("AMDemod::applySettings: audioDeviceName: %s audioDeviceIndex: %d", qPrintable(settings.m_audioDeviceName), audioDeviceIndex);
|
|
|
|
audioDeviceManager->addAudioSink(&m_audioFifo, getInputMessageQueue(), audioDeviceIndex);
|
|
|
|
uint32_t audioSampleRate = audioDeviceManager->getOutputSampleRate(audioDeviceIndex);
|
|
|
|
|
|
|
|
if (m_audioSampleRate != audioSampleRate) {
|
|
|
|
applyAudioSampleRate(audioSampleRate);
|
|
|
|
}
|
2017-10-01 14:17:20 -04:00
|
|
|
}
|
2015-12-07 20:00:30 -05:00
|
|
|
|
2017-10-01 14:17:20 -04:00
|
|
|
m_settings = settings;
|
2015-12-06 04:30:51 -05:00
|
|
|
}
|
2017-12-17 17:15:42 -05:00
|
|
|
|
|
|
|
QByteArray BFMDemod::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BFMDemod::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
MsgConfigureBFMDemod *msg = MsgConfigureBFMDemod::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
MsgConfigureBFMDemod *msg = MsgConfigureBFMDemod::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|