2016-04-07 11:05:53 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2016-04-22 01:53:16 +00:00
|
|
|
// Copyright (C) 2016 F4EXB //
|
2016-04-08 16:14:50 +00:00
|
|
|
// written by Edouard Griffiths //
|
2016-04-07 11:05:53 +00: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/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-02 11:18:07 +00:00
|
|
|
|
2016-04-07 11:05:53 +00:00
|
|
|
#include <QTime>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <complex.h>
|
2017-10-02 11:56:40 +00:00
|
|
|
|
2016-04-07 11:05:53 +00:00
|
|
|
#include "audio/audiooutput.h"
|
|
|
|
#include "dsp/dspengine.h"
|
2017-10-02 11:56:40 +00:00
|
|
|
#include "dsp/threadedbasebandsamplesink.h"
|
2018-02-14 19:11:36 +00:00
|
|
|
#include "dsp/downchannelizer.h"
|
|
|
|
#include "dsp/dspcommands.h"
|
|
|
|
#include "device/devicesourceapi.h"
|
2017-10-02 11:56:40 +00:00
|
|
|
|
|
|
|
#include "dsddemod.h"
|
2016-04-07 11:05:53 +00:00
|
|
|
|
2017-10-02 11:56:40 +00:00
|
|
|
MESSAGE_CLASS_DEFINITION(DSDDemod::MsgConfigureChannelizer, Message)
|
2016-04-07 11:05:53 +00:00
|
|
|
MESSAGE_CLASS_DEFINITION(DSDDemod::MsgConfigureDSDDemod, Message)
|
2016-09-28 15:58:29 +00:00
|
|
|
MESSAGE_CLASS_DEFINITION(DSDDemod::MsgConfigureMyPosition, Message)
|
2016-04-07 11:05:53 +00:00
|
|
|
|
2017-11-23 00:19:32 +00:00
|
|
|
const QString DSDDemod::m_channelIdURI = "sdrangel.channel.dsddemod";
|
|
|
|
const QString DSDDemod::m_channelId = "DSDDemod";
|
2017-08-24 06:46:14 +00:00
|
|
|
const int DSDDemod::m_udpBlockSize = 512;
|
|
|
|
|
2017-10-02 11:56:40 +00:00
|
|
|
DSDDemod::DSDDemod(DeviceSourceAPI *deviceAPI) :
|
2017-12-20 22:57:06 +00:00
|
|
|
ChannelSinkAPI(m_channelIdURI),
|
|
|
|
m_deviceAPI(deviceAPI),
|
2017-12-29 10:04:47 +00:00
|
|
|
m_inputSampleRate(48000),
|
|
|
|
m_inputFrequencyOffset(0),
|
2017-12-20 22:57:06 +00:00
|
|
|
m_interpolatorDistance(0.0f),
|
|
|
|
m_interpolatorDistanceRemain(0.0f),
|
|
|
|
m_sampleCount(0),
|
|
|
|
m_squelchCount(0),
|
|
|
|
m_squelchGate(0),
|
|
|
|
m_squelchLevel(1e-4),
|
|
|
|
m_squelchOpen(false),
|
2018-04-21 07:56:12 +00:00
|
|
|
m_squelchDelayLine(24000),
|
2017-12-20 22:57:06 +00:00
|
|
|
m_audioFifo1(48000),
|
|
|
|
m_audioFifo2(48000),
|
2018-03-12 04:07:51 +00:00
|
|
|
m_scopeXY(0),
|
2017-12-20 22:57:06 +00:00
|
|
|
m_scopeEnabled(true),
|
|
|
|
m_dsdDecoder(),
|
|
|
|
m_settingsMutex(QMutex::Recursive)
|
2016-04-07 11:05:53 +00:00
|
|
|
{
|
2017-11-23 00:19:32 +00:00
|
|
|
setObjectName(m_channelId);
|
2016-04-07 11:05:53 +00:00
|
|
|
|
|
|
|
m_audioBuffer.resize(1<<14);
|
|
|
|
m_audioBufferFill = 0;
|
|
|
|
|
2018-01-24 22:57:36 +00:00
|
|
|
m_sampleBuffer = new FixReal[1<<17]; // 128 kS
|
2016-04-12 01:32:42 +00:00
|
|
|
m_sampleBufferIndex = 0;
|
2018-01-24 22:57:36 +00:00
|
|
|
m_scaleFromShort = SDR_RX_SAMP_SZ < sizeof(short)*8 ? 1 : 1<<(SDR_RX_SAMP_SZ - sizeof(short)*8);
|
2016-04-12 01:32:42 +00:00
|
|
|
|
2016-12-06 18:06:38 +00:00
|
|
|
m_magsq = 0.0f;
|
|
|
|
m_magsqSum = 0.0f;
|
|
|
|
m_magsqPeak = 0.0f;
|
|
|
|
m_magsqCount = 0;
|
2016-04-07 11:05:53 +00:00
|
|
|
|
2018-03-25 09:50:34 +00:00
|
|
|
DSPEngine::instance()->getAudioDeviceManager()->addAudioSink(&m_audioFifo1, getInputMessageQueue());
|
|
|
|
DSPEngine::instance()->getAudioDeviceManager()->addAudioSink(&m_audioFifo2, getInputMessageQueue());
|
2018-03-28 06:00:27 +00:00
|
|
|
m_audioSampleRate = DSPEngine::instance()->getAudioDeviceManager()->getOutputSampleRate();
|
2017-08-24 06:46:14 +00:00
|
|
|
|
2018-03-16 09:24:19 +00:00
|
|
|
applyChannelSettings(m_inputSampleRate, m_inputFrequencyOffset, true);
|
|
|
|
applySettings(m_settings, true);
|
|
|
|
|
2017-10-02 11:56:40 +00:00
|
|
|
m_channelizer = new DownChannelizer(this);
|
|
|
|
m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
|
|
|
|
m_deviceAPI->addThreadedSink(m_threadedChannelizer);
|
2017-11-19 10:36:20 +00:00
|
|
|
m_deviceAPI->addChannelAPI(this);
|
2016-04-07 11:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DSDDemod::~DSDDemod()
|
|
|
|
{
|
2016-04-12 01:32:42 +00:00
|
|
|
delete[] m_sampleBuffer;
|
2018-03-24 02:36:49 +00:00
|
|
|
DSPEngine::instance()->getAudioDeviceManager()->removeAudioSink(&m_audioFifo1);
|
|
|
|
DSPEngine::instance()->getAudioDeviceManager()->removeAudioSink(&m_audioFifo2);
|
2017-10-02 11:56:40 +00:00
|
|
|
|
2017-11-19 10:36:20 +00:00
|
|
|
m_deviceAPI->removeChannelAPI(this);
|
2017-10-02 11:56:40 +00:00
|
|
|
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
|
|
|
|
delete m_threadedChannelizer;
|
|
|
|
delete m_channelizer;
|
2016-04-07 11:05:53 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 15:58:29 +00:00
|
|
|
void DSDDemod::configureMyPosition(MessageQueue* messageQueue, float myLatitude, float myLongitude)
|
|
|
|
{
|
|
|
|
Message* cmd = MsgConfigureMyPosition::create(myLatitude, myLongitude);
|
|
|
|
messageQueue->push(cmd);
|
|
|
|
}
|
|
|
|
|
2017-05-25 18:13:34 +00:00
|
|
|
void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst __attribute__((unused)))
|
2016-04-07 11:05:53 +00:00
|
|
|
{
|
|
|
|
Complex ci;
|
2016-04-23 04:27:28 +00:00
|
|
|
int samplesPerSymbol = m_dsdDecoder.getSamplesPerSymbol();
|
2016-04-07 11:05:53 +00:00
|
|
|
|
|
|
|
m_settingsMutex.lock();
|
|
|
|
m_scopeSampleBuffer.clear();
|
|
|
|
|
2016-05-09 07:24:28 +00:00
|
|
|
m_dsdDecoder.enableMbelib(!DSPEngine::instance()->hasDVSerialSupport()); // disable mbelib if DV serial support is present and activated else enable it
|
|
|
|
|
2016-04-07 11:05:53 +00:00
|
|
|
for (SampleVector::const_iterator it = begin; it != end; ++it)
|
|
|
|
{
|
|
|
|
Complex c(it->real(), it->imag());
|
|
|
|
c *= m_nco.nextIQ();
|
|
|
|
|
2016-10-09 23:53:32 +00:00
|
|
|
if (m_interpolator.decimate(&m_interpolatorDistanceRemain, c, &ci))
|
2016-04-09 17:14:19 +00:00
|
|
|
{
|
2018-01-24 22:57:36 +00:00
|
|
|
FixReal sample, delayedSample;
|
|
|
|
qint16 sampleDSD;
|
2016-04-09 17:14:19 +00:00
|
|
|
|
2018-01-22 07:46:05 +00:00
|
|
|
Real re = ci.real() / SDR_RX_SCALED;
|
|
|
|
Real im = ci.imag() / SDR_RX_SCALED;
|
2018-01-21 09:57:04 +00:00
|
|
|
Real magsq = re*re + im*im;
|
2018-02-03 09:33:02 +00:00
|
|
|
m_movingAverage(magsq);
|
2016-12-06 18:06:38 +00:00
|
|
|
|
|
|
|
m_magsqSum += magsq;
|
|
|
|
|
|
|
|
if (magsq > m_magsqPeak)
|
|
|
|
{
|
|
|
|
m_magsqPeak = magsq;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_magsqCount++;
|
2016-04-09 17:14:19 +00:00
|
|
|
|
2018-01-24 22:57:36 +00:00
|
|
|
Real demod = m_phaseDiscri.phaseDiscriminator(ci) * m_settings.m_demodGain; // [-1.0:1.0]
|
2016-04-09 17:14:19 +00:00
|
|
|
m_sampleCount++;
|
|
|
|
|
|
|
|
// AF processing
|
|
|
|
|
2018-02-03 09:33:02 +00:00
|
|
|
if (m_movingAverage.asDouble() > m_squelchLevel)
|
2016-04-09 17:14:19 +00:00
|
|
|
{
|
2016-04-23 04:58:54 +00:00
|
|
|
if (m_squelchGate > 0)
|
2016-04-09 17:14:19 +00:00
|
|
|
{
|
2018-04-21 15:22:07 +00:00
|
|
|
|
|
|
|
if (m_squelchCount < m_squelchGate*2) {
|
2016-04-23 04:58:54 +00:00
|
|
|
m_squelchCount++;
|
|
|
|
}
|
|
|
|
|
2018-04-21 15:22:07 +00:00
|
|
|
m_squelchDelayLine.write(demod);
|
|
|
|
m_squelchOpen = m_squelchCount > m_squelchGate;
|
2016-04-23 04:58:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_squelchOpen = true;
|
2016-04-09 17:14:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-21 15:22:07 +00:00
|
|
|
if (m_squelchGate > 0)
|
|
|
|
{
|
|
|
|
if (m_squelchCount > 0) {
|
|
|
|
m_squelchCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_squelchDelayLine.write(0);
|
|
|
|
m_squelchOpen = m_squelchCount > m_squelchGate;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_squelchOpen = false;
|
|
|
|
}
|
2016-04-09 17:14:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_squelchOpen)
|
|
|
|
{
|
2018-04-21 15:22:07 +00:00
|
|
|
if (m_squelchGate > 0)
|
|
|
|
{
|
|
|
|
sampleDSD = m_squelchDelayLine.readBack(m_squelchGate) * 32768.0f; // DSD decoder takes int16 samples
|
|
|
|
sample = m_squelchDelayLine.readBack(m_squelchGate) * SDR_RX_SCALEF; // scale to sample size
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sampleDSD = demod * 32768.0f; // DSD decoder takes int16 samples
|
|
|
|
sample = demod * SDR_RX_SCALEF; // scale to sample size
|
|
|
|
}
|
2016-04-09 17:14:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-24 22:57:36 +00:00
|
|
|
sampleDSD = 0;
|
2016-04-09 17:14:19 +00:00
|
|
|
sample = 0;
|
|
|
|
}
|
|
|
|
|
2018-01-24 22:57:36 +00:00
|
|
|
m_dsdDecoder.pushSample(sampleDSD);
|
2016-08-19 17:30:32 +00:00
|
|
|
|
2017-10-03 22:02:59 +00:00
|
|
|
if (m_settings.m_enableCosineFiltering) { // show actual input to FSK demod
|
2018-01-24 22:57:36 +00:00
|
|
|
sample = m_dsdDecoder.getFilteredSample() * m_scaleFromShort;
|
2016-08-19 17:30:32 +00:00
|
|
|
}
|
|
|
|
|
2018-02-17 08:35:17 +00:00
|
|
|
if (m_sampleBufferIndex < (1<<17)-1) {
|
2016-04-12 01:32:42 +00:00
|
|
|
m_sampleBufferIndex++;
|
|
|
|
} else {
|
|
|
|
m_sampleBufferIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sampleBuffer[m_sampleBufferIndex] = sample;
|
|
|
|
|
2016-04-23 04:27:28 +00:00
|
|
|
if (m_sampleBufferIndex < samplesPerSymbol) {
|
|
|
|
delayedSample = m_sampleBuffer[(1<<17) - samplesPerSymbol + m_sampleBufferIndex]; // wrap
|
2016-04-12 01:32:42 +00:00
|
|
|
} else {
|
2016-04-23 04:27:28 +00:00
|
|
|
delayedSample = m_sampleBuffer[m_sampleBufferIndex - samplesPerSymbol];
|
2016-04-12 01:32:42 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 22:02:59 +00:00
|
|
|
if (m_settings.m_syncOrConstellation)
|
2016-08-24 23:06:42 +00:00
|
|
|
{
|
2018-03-12 19:39:16 +00:00
|
|
|
Sample s(sample, m_dsdDecoder.getSymbolSyncSample() * m_scaleFromShort * 0.84);
|
2016-08-24 23:06:42 +00:00
|
|
|
m_scopeSampleBuffer.push_back(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Sample s(sample, delayedSample); // I=signal, Q=signal delayed by 20 samples (2400 baud: lowest rate)
|
|
|
|
m_scopeSampleBuffer.push_back(s);
|
|
|
|
}
|
2016-04-07 11:05:53 +00:00
|
|
|
|
2016-09-03 23:06:10 +00:00
|
|
|
if (DSPEngine::instance()->hasDVSerialSupport())
|
2016-05-09 08:13:11 +00:00
|
|
|
{
|
2017-10-03 22:02:59 +00:00
|
|
|
if ((m_settings.m_slot1On) && m_dsdDecoder.mbeDVReady1())
|
2016-09-03 23:06:10 +00:00
|
|
|
{
|
2017-10-03 22:02:59 +00:00
|
|
|
if (!m_settings.m_audioMute)
|
2016-09-06 22:47:51 +00:00
|
|
|
{
|
|
|
|
DSPEngine::instance()->pushMbeFrame(
|
|
|
|
m_dsdDecoder.getMbeDVFrame1(),
|
|
|
|
m_dsdDecoder.getMbeRateIndex(),
|
2017-10-07 03:06:44 +00:00
|
|
|
m_settings.m_volume * 10.0,
|
2017-10-03 22:02:59 +00:00
|
|
|
m_settings.m_tdmaStereo ? 1 : 3, // left or both channels
|
2017-12-26 19:29:23 +00:00
|
|
|
m_settings.m_highPassFilter,
|
2018-04-22 23:04:47 +00:00
|
|
|
m_audioSampleRate/8000, // upsample from native 8k
|
2016-09-06 22:47:51 +00:00
|
|
|
&m_audioFifo1);
|
2016-09-03 23:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_dsdDecoder.resetMbeDV1();
|
|
|
|
}
|
|
|
|
|
2017-10-03 22:02:59 +00:00
|
|
|
if ((m_settings.m_slot2On) && m_dsdDecoder.mbeDVReady2())
|
2016-09-03 23:06:10 +00:00
|
|
|
{
|
2017-10-03 22:02:59 +00:00
|
|
|
if (!m_settings.m_audioMute)
|
2016-09-06 22:47:51 +00:00
|
|
|
{
|
|
|
|
DSPEngine::instance()->pushMbeFrame(
|
|
|
|
m_dsdDecoder.getMbeDVFrame2(),
|
|
|
|
m_dsdDecoder.getMbeRateIndex(),
|
2017-10-07 03:06:44 +00:00
|
|
|
m_settings.m_volume * 10.0,
|
2017-10-03 22:02:59 +00:00
|
|
|
m_settings.m_tdmaStereo ? 2 : 3, // right or both channels
|
2017-12-26 19:29:23 +00:00
|
|
|
m_settings.m_highPassFilter,
|
2018-04-22 23:04:47 +00:00
|
|
|
m_audioSampleRate/8000, // upsample from native 8k
|
2016-09-06 22:47:51 +00:00
|
|
|
&m_audioFifo2);
|
2016-09-03 23:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_dsdDecoder.resetMbeDV2();
|
2016-05-10 06:27:54 +00:00
|
|
|
}
|
2016-05-09 08:13:11 +00:00
|
|
|
}
|
|
|
|
|
2016-09-03 23:06:10 +00:00
|
|
|
// if (DSPEngine::instance()->hasDVSerialSupport() && m_dsdDecoder.mbeDVReady1())
|
|
|
|
// {
|
2017-10-03 22:02:59 +00:00
|
|
|
// if (!m_settings.m_audioMute)
|
2016-09-03 23:06:10 +00:00
|
|
|
// {
|
2017-10-03 22:02:59 +00:00
|
|
|
// DSPEngine::instance()->pushMbeFrame(m_dsdDecoder.getMbeDVFrame1(), m_dsdDecoder.getMbeRateIndex(), m_settings.m_volume, &m_audioFifo1);
|
2016-09-03 23:06:10 +00:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// m_dsdDecoder.resetMbeDV1();
|
|
|
|
// }
|
|
|
|
|
2016-04-09 17:14:19 +00:00
|
|
|
m_interpolatorDistanceRemain += m_interpolatorDistance;
|
|
|
|
}
|
2016-04-07 11:05:53 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 08:13:11 +00:00
|
|
|
if (!DSPEngine::instance()->hasDVSerialSupport())
|
2016-05-08 04:00:37 +00:00
|
|
|
{
|
2017-10-03 22:02:59 +00:00
|
|
|
if (m_settings.m_slot1On)
|
2016-05-08 04:00:37 +00:00
|
|
|
{
|
2016-09-03 23:06:10 +00:00
|
|
|
int nbAudioSamples;
|
|
|
|
short *dsdAudio = m_dsdDecoder.getAudio1(nbAudioSamples);
|
2016-05-08 04:00:37 +00:00
|
|
|
|
2016-09-03 23:06:10 +00:00
|
|
|
if (nbAudioSamples > 0)
|
|
|
|
{
|
2017-10-03 22:02:59 +00:00
|
|
|
if (!m_settings.m_audioMute) {
|
2017-05-25 18:13:34 +00:00
|
|
|
m_audioFifo1.write((const quint8*) dsdAudio, nbAudioSamples, 10);
|
2016-09-03 23:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_dsdDecoder.resetAudio1();
|
|
|
|
}
|
2016-05-08 04:00:37 +00:00
|
|
|
}
|
2016-09-03 23:06:10 +00:00
|
|
|
|
2017-10-03 22:02:59 +00:00
|
|
|
if (m_settings.m_slot2On)
|
2016-09-03 23:06:10 +00:00
|
|
|
{
|
|
|
|
int nbAudioSamples;
|
|
|
|
short *dsdAudio = m_dsdDecoder.getAudio2(nbAudioSamples);
|
|
|
|
|
|
|
|
if (nbAudioSamples > 0)
|
|
|
|
{
|
2017-10-03 22:02:59 +00:00
|
|
|
if (!m_settings.m_audioMute) {
|
2017-05-25 18:13:34 +00:00
|
|
|
m_audioFifo2.write((const quint8*) dsdAudio, nbAudioSamples, 10);
|
2016-09-03 23:06:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_dsdDecoder.resetAudio2();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// int nbAudioSamples;
|
|
|
|
// short *dsdAudio = m_dsdDecoder.getAudio1(nbAudioSamples);
|
|
|
|
//
|
|
|
|
// if (nbAudioSamples > 0)
|
|
|
|
// {
|
2017-10-03 22:02:59 +00:00
|
|
|
// if (!m_settings.m_audioMute) {
|
2016-09-03 23:06:10 +00:00
|
|
|
// uint res = m_audioFifo1.write((const quint8*) dsdAudio, nbAudioSamples, 10);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// m_dsdDecoder.resetAudio1();
|
|
|
|
// }
|
2016-04-22 01:53:16 +00:00
|
|
|
}
|
2016-04-12 01:32:42 +00:00
|
|
|
|
2018-03-12 04:07:51 +00:00
|
|
|
if ((m_scopeXY != 0) && (m_scopeEnabled))
|
|
|
|
{
|
|
|
|
m_scopeXY->feed(m_scopeSampleBuffer.begin(), m_scopeSampleBuffer.end(), true); // true = real samples for what it's worth
|
|
|
|
}
|
|
|
|
|
2016-04-07 11:05:53 +00:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSDDemod::start()
|
|
|
|
{
|
2016-09-03 23:06:10 +00:00
|
|
|
m_audioFifo1.clear();
|
|
|
|
m_audioFifo2.clear();
|
2016-04-07 11:05:53 +00:00
|
|
|
m_phaseDiscri.reset();
|
2018-01-08 23:59:10 +00:00
|
|
|
applyChannelSettings(m_inputSampleRate, m_inputFrequencyOffset, true);
|
2016-04-07 11:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSDDemod::stop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DSDDemod::handleMessage(const Message& cmd)
|
|
|
|
{
|
|
|
|
qDebug() << "DSDDemod::handleMessage";
|
|
|
|
|
2016-10-02 19:52:39 +00:00
|
|
|
if (DownChannelizer::MsgChannelizerNotification::match(cmd))
|
2016-04-07 11:05:53 +00:00
|
|
|
{
|
2016-10-02 19:52:39 +00:00
|
|
|
DownChannelizer::MsgChannelizerNotification& notif = (DownChannelizer::MsgChannelizerNotification&) cmd;
|
2017-12-29 10:04:47 +00:00
|
|
|
qDebug() << "DSDDemod::handleMessage: MsgChannelizerNotification: inputSampleRate: " << notif.getSampleRate()
|
|
|
|
<< " inputFrequencyOffset: " << notif.getFrequencyOffset();
|
2016-04-07 11:05:53 +00:00
|
|
|
|
2017-12-29 10:04:47 +00:00
|
|
|
applyChannelSettings(notif.getSampleRate(), notif.getFrequencyOffset());
|
2016-04-07 11:05:53 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-02 11:56:40 +00:00
|
|
|
else if (MsgConfigureChannelizer::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureChannelizer& cfg = (MsgConfigureChannelizer&) cmd;
|
2017-12-29 10:04:47 +00:00
|
|
|
qDebug("DSDDemod::handleMessage: MsgConfigureChannelizer");
|
2017-10-02 11:56:40 +00:00
|
|
|
|
|
|
|
m_channelizer->configure(m_channelizer->getInputMessageQueue(),
|
|
|
|
cfg.getSampleRate(),
|
|
|
|
cfg.getCenterFrequency());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-03 22:02:59 +00:00
|
|
|
else if (MsgConfigureDSDDemod::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureDSDDemod& cfg = (MsgConfigureDSDDemod&) cmd;
|
2017-12-29 10:04:47 +00:00
|
|
|
qDebug("DSDDemod::handleMessage: MsgConfigureDSDDemod: m_rfBandwidth");
|
2017-10-03 22:02:59 +00:00
|
|
|
|
2017-12-29 10:04:47 +00:00
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
2017-10-03 22:02:59 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-28 15:58:29 +00:00
|
|
|
else if (MsgConfigureMyPosition::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureMyPosition& cfg = (MsgConfigureMyPosition&) cmd;
|
|
|
|
m_dsdDecoder.setMyPoint(cfg.getMyLatitude(), cfg.getMyLongitude());
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-28 06:00:27 +00:00
|
|
|
else if (DSPConfigureAudio::match(cmd))
|
|
|
|
{
|
|
|
|
DSPConfigureAudio& cfg = (DSPConfigureAudio&) cmd;
|
|
|
|
uint32_t sampleRate = cfg.getSampleRate();
|
|
|
|
|
|
|
|
qDebug() << "DSDDemod::handleMessage: DSPConfigureAudio:"
|
|
|
|
<< " sampleRate: " << sampleRate;
|
|
|
|
|
|
|
|
if (sampleRate != m_audioSampleRate) {
|
|
|
|
applyAudioSampleRate(sampleRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-08 07:59:17 +00:00
|
|
|
else if (BasebandSampleSink::MsgThreadedSink::match(cmd))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-14 19:11:36 +00:00
|
|
|
else if (DSPSignalNotification::match(cmd))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-04-07 11:05:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 06:00:27 +00:00
|
|
|
void DSDDemod::applyAudioSampleRate(int sampleRate)
|
|
|
|
{
|
2018-04-22 23:04:47 +00:00
|
|
|
int upsampling = sampleRate / 8000;
|
2018-03-28 06:00:27 +00:00
|
|
|
|
2018-04-22 23:04:47 +00:00
|
|
|
qDebug("DSDDemod::applyAudioSampleRate: audio rate: %d upsample by %d", sampleRate, upsampling);
|
2018-03-28 06:00:27 +00:00
|
|
|
|
2018-04-22 23:04:47 +00:00
|
|
|
if (sampleRate % 8000 != 0) {
|
|
|
|
qDebug("DSDDemod::applyAudioSampleRate: audio will sound best with sample rates that are integer multiples of 8 kS/s");
|
|
|
|
}
|
2018-03-28 06:43:11 +00:00
|
|
|
|
2018-04-22 23:04:47 +00:00
|
|
|
m_dsdDecoder.setUpsampling(upsampling);
|
2018-03-28 06:00:27 +00:00
|
|
|
m_audioSampleRate = sampleRate;
|
|
|
|
}
|
|
|
|
|
2018-01-08 23:59:10 +00:00
|
|
|
void DSDDemod::applyChannelSettings(int inputSampleRate, int inputFrequencyOffset, bool force)
|
2017-10-03 22:02:59 +00:00
|
|
|
{
|
2017-12-29 10:04:47 +00:00
|
|
|
qDebug() << "DSDDemod::applyChannelSettings:"
|
|
|
|
<< " inputSampleRate: " << inputSampleRate
|
|
|
|
<< " inputFrequencyOffset: " << inputFrequencyOffset;
|
|
|
|
|
|
|
|
if ((inputFrequencyOffset != m_inputFrequencyOffset) ||
|
2018-01-08 23:59:10 +00:00
|
|
|
(inputSampleRate != m_inputSampleRate) || force)
|
2017-12-29 10:04:47 +00:00
|
|
|
{
|
|
|
|
m_nco.setFreq(-inputFrequencyOffset, inputSampleRate);
|
|
|
|
}
|
|
|
|
|
2018-01-08 23:59:10 +00:00
|
|
|
if ((inputSampleRate != m_inputSampleRate) || force)
|
2017-10-03 22:02:59 +00:00
|
|
|
{
|
2017-12-29 10:04:47 +00:00
|
|
|
m_settingsMutex.lock();
|
|
|
|
m_interpolator.create(16, inputSampleRate, (m_settings.m_rfBandwidth) / 2.2);
|
|
|
|
m_interpolatorDistanceRemain = 0;
|
2018-03-28 06:00:27 +00:00
|
|
|
m_interpolatorDistance = (Real) inputSampleRate / (Real) 48000;
|
2017-12-29 10:04:47 +00:00
|
|
|
m_settingsMutex.unlock();
|
2017-10-03 22:02:59 +00:00
|
|
|
}
|
|
|
|
|
2017-12-29 10:04:47 +00:00
|
|
|
m_inputSampleRate = inputSampleRate;
|
|
|
|
m_inputFrequencyOffset = inputFrequencyOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DSDDemod::applySettings(const DSDDemodSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
qDebug() << "DSDDemod::applySettings: "
|
|
|
|
<< " m_inputFrequencyOffset: " << m_settings.m_inputFrequencyOffset
|
|
|
|
<< " m_rfBandwidth: " << m_settings.m_rfBandwidth
|
|
|
|
<< " m_fmDeviation: " << m_settings.m_fmDeviation
|
|
|
|
<< " m_demodGain: " << m_settings.m_demodGain
|
|
|
|
<< " m_volume: " << m_settings.m_volume
|
|
|
|
<< " m_baudRate: " << m_settings.m_baudRate
|
|
|
|
<< " m_squelchGate" << m_settings.m_squelchGate
|
|
|
|
<< " m_squelch: " << m_settings.m_squelch
|
|
|
|
<< " m_audioMute: " << m_settings.m_audioMute
|
|
|
|
<< " m_enableCosineFiltering: " << m_settings.m_enableCosineFiltering
|
|
|
|
<< " m_syncOrConstellation: " << m_settings.m_syncOrConstellation
|
|
|
|
<< " m_slot1On: " << m_settings.m_slot1On
|
|
|
|
<< " m_slot2On: " << m_settings.m_slot2On
|
|
|
|
<< " m_tdmaStereo: " << m_settings.m_tdmaStereo
|
|
|
|
<< " m_pllLock: " << m_settings.m_pllLock
|
|
|
|
<< " m_udpAddress: " << m_settings.m_udpAddress
|
|
|
|
<< " m_udpPort: " << m_settings.m_udpPort
|
|
|
|
<< " m_highPassFilter: "<< m_settings.m_highPassFilter
|
2018-03-28 06:00:27 +00:00
|
|
|
<< " m_audioDeviceName: " << settings.m_audioDeviceName
|
2017-12-29 10:04:47 +00:00
|
|
|
<< " force: " << force;
|
|
|
|
|
|
|
|
if ((settings.m_rfBandwidth != m_settings.m_rfBandwidth) || force)
|
2017-10-03 22:02:59 +00:00
|
|
|
{
|
|
|
|
m_settingsMutex.lock();
|
2017-12-29 10:04:47 +00:00
|
|
|
m_interpolator.create(16, m_inputSampleRate, (settings.m_rfBandwidth) / 2.2);
|
2017-10-03 22:02:59 +00:00
|
|
|
m_interpolatorDistanceRemain = 0;
|
2018-03-28 06:00:27 +00:00
|
|
|
m_interpolatorDistance = (Real) m_inputSampleRate / (Real) 48000;
|
2018-04-01 07:33:08 +00:00
|
|
|
//m_phaseDiscri.setFMScaling((float) settings.m_rfBandwidth / (float) settings.m_fmDeviation);
|
2017-10-03 22:02:59 +00:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_fmDeviation != m_settings.m_fmDeviation) || force)
|
|
|
|
{
|
2018-04-01 07:33:08 +00:00
|
|
|
m_phaseDiscri.setFMScaling(48000.0f / (2.0f*settings.m_fmDeviation));
|
2017-10-03 22:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_squelchGate != m_settings.m_squelchGate) || force)
|
|
|
|
{
|
|
|
|
m_squelchGate = 480 * settings.m_squelchGate; // gate is given in 10s of ms at 48000 Hz audio sample rate
|
|
|
|
m_squelchCount = 0; // reset squelch open counter
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_squelch != m_settings.m_squelch) || force)
|
|
|
|
{
|
|
|
|
// input is a value in dB
|
|
|
|
m_squelchLevel = std::pow(10.0, settings.m_squelch / 10.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_volume != m_settings.m_volume) || force)
|
|
|
|
{
|
|
|
|
m_dsdDecoder.setAudioGain(settings.m_volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_baudRate != m_settings.m_baudRate) || force)
|
|
|
|
{
|
|
|
|
m_dsdDecoder.setBaudRate(settings.m_baudRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_enableCosineFiltering != m_settings.m_enableCosineFiltering) || force)
|
|
|
|
{
|
|
|
|
m_dsdDecoder.enableCosineFiltering(settings.m_enableCosineFiltering);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_tdmaStereo != m_settings.m_tdmaStereo) || force)
|
|
|
|
{
|
|
|
|
m_dsdDecoder.setTDMAStereo(settings.m_tdmaStereo);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_pllLock != m_settings.m_pllLock) || force)
|
|
|
|
{
|
|
|
|
m_dsdDecoder.setSymbolPLLLock(settings.m_pllLock);
|
|
|
|
}
|
|
|
|
|
2017-12-26 19:29:23 +00:00
|
|
|
if ((settings.m_highPassFilter != m_settings.m_highPassFilter) || force)
|
|
|
|
{
|
|
|
|
m_dsdDecoder.useHPMbelib(settings.m_highPassFilter);
|
|
|
|
}
|
|
|
|
|
2018-03-28 06:00:27 +00:00
|
|
|
if ((settings.m_audioDeviceName != m_settings.m_audioDeviceName) || force)
|
|
|
|
{
|
|
|
|
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_audioFifo1, getInputMessageQueue(), audioDeviceIndex);
|
|
|
|
audioDeviceManager->addAudioSink(&m_audioFifo2, getInputMessageQueue(), audioDeviceIndex);
|
|
|
|
uint32_t audioSampleRate = audioDeviceManager->getOutputSampleRate(audioDeviceIndex);
|
|
|
|
|
|
|
|
if (m_audioSampleRate != audioSampleRate) {
|
|
|
|
applyAudioSampleRate(audioSampleRate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-03 22:02:59 +00:00
|
|
|
m_settings = settings;
|
|
|
|
}
|
2017-12-17 22:15:42 +00:00
|
|
|
|
|
|
|
QByteArray DSDDemod::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DSDDemod::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
MsgConfigureDSDDemod *msg = MsgConfigureDSDDemod::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
MsgConfigureDSDDemod *msg = MsgConfigureDSDDemod::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|