2019-11-14 19:04:24 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2023-11-18 00:36:53 -05:00
|
|
|
// Copyright (C) 2019-2022 Edouard Griffiths, F4EXB <f4exb06@gmail.com> //
|
|
|
|
// Copyright (C) 2022 Jiří Pinkava <jiri.pinkava@rossum.ai> //
|
2019-11-14 19:04:24 -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 //
|
|
|
|
// (at your option) any later version. //
|
|
|
|
// //
|
|
|
|
// 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 <QDebug>
|
|
|
|
|
2020-12-20 20:30:29 -05:00
|
|
|
#include "dsp/datafifo.h"
|
2024-04-20 05:51:29 -04:00
|
|
|
#include "dsp/misc.h"
|
2024-08-17 16:33:30 -04:00
|
|
|
#include "dsp/cwkeyer.h"
|
2020-12-20 20:30:29 -05:00
|
|
|
#include "util/messagequeue.h"
|
|
|
|
#include "maincore.h"
|
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
#include "nfmmodsource.h"
|
|
|
|
|
|
|
|
const int NFMModSource::m_levelNbSamples = 480; // every 10ms
|
2024-08-24 07:17:02 -04:00
|
|
|
const float NFMModSource::m_preemphasis = 120.0e-6f; // 120us
|
2019-11-14 19:04:24 -05:00
|
|
|
|
|
|
|
NFMModSource::NFMModSource() :
|
2020-11-13 23:51:19 -05:00
|
|
|
m_preemphasisFilter(m_preemphasis*48000),
|
2020-11-22 12:33:52 -05:00
|
|
|
m_audioFifo(12000),
|
2024-08-24 07:17:02 -04:00
|
|
|
m_feedbackAudioFifo(48000)
|
2019-11-14 19:04:24 -05:00
|
|
|
{
|
2022-05-17 13:55:40 -04:00
|
|
|
m_audioFifo.setLabel("NFMModSource.m_audioFifo");
|
|
|
|
m_feedbackAudioFifo.setLabel("NFMModSource.m_feedbackAudioFifo");
|
2020-11-22 12:33:52 -05:00
|
|
|
m_audioBuffer.resize(24000);
|
2019-11-14 19:04:24 -05:00
|
|
|
m_audioBufferFill = 0;
|
2020-11-22 12:33:52 -05:00
|
|
|
m_audioReadBuffer.resize(24000);
|
|
|
|
m_audioReadBufferFill = 0;
|
2019-11-14 19:04:24 -05:00
|
|
|
|
|
|
|
m_feedbackAudioBuffer.resize(1<<14);
|
|
|
|
m_feedbackAudioBufferFill = 0;
|
|
|
|
|
2020-12-20 20:30:29 -05:00
|
|
|
m_demodBuffer.resize(1<<12);
|
|
|
|
m_demodBufferFill = 0;
|
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
m_magsq = 0.0;
|
|
|
|
|
2022-08-15 07:09:49 -04:00
|
|
|
m_audioCompressor.initSimple(
|
|
|
|
m_audioSampleRate,
|
|
|
|
-8, // pregain (dB)
|
|
|
|
-20, // threshold (dB)
|
|
|
|
20, // knee (dB)
|
|
|
|
15, // ratio (dB)
|
2024-08-24 07:17:02 -04:00
|
|
|
0.003f,// attack (s)
|
2022-08-15 07:09:49 -04:00
|
|
|
0.25 // release (s)
|
|
|
|
);
|
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
applySettings(m_settings, true);
|
|
|
|
applyChannelSettings(m_channelSampleRate, m_channelFrequencyOffset, true);
|
|
|
|
}
|
|
|
|
|
2024-08-24 07:17:02 -04:00
|
|
|
NFMModSource::~NFMModSource() = default;
|
2019-11-14 19:04:24 -05:00
|
|
|
|
|
|
|
void NFMModSource::pull(SampleVector::iterator begin, unsigned int nbSamples)
|
|
|
|
{
|
|
|
|
std::for_each(
|
|
|
|
begin,
|
|
|
|
begin + nbSamples,
|
|
|
|
[this](Sample& s) {
|
|
|
|
pullOne(s);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NFMModSource::pullOne(Sample& sample)
|
|
|
|
{
|
|
|
|
if (m_settings.m_channelMute)
|
|
|
|
{
|
|
|
|
sample.m_real = 0.0f;
|
|
|
|
sample.m_imag = 0.0f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Complex ci;
|
|
|
|
|
|
|
|
if (m_interpolatorDistance > 1.0f) // decimate
|
|
|
|
{
|
|
|
|
modulateSample();
|
|
|
|
|
|
|
|
while (!m_interpolator.decimate(&m_interpolatorDistanceRemain, m_modSample, &ci))
|
|
|
|
{
|
|
|
|
modulateSample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_interpolator.interpolate(&m_interpolatorDistanceRemain, m_modSample, &ci))
|
|
|
|
{
|
|
|
|
modulateSample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_interpolatorDistanceRemain += m_interpolatorDistance;
|
|
|
|
|
|
|
|
ci *= m_carrierNco.nextIQ(); // shift to carrier frequency
|
|
|
|
|
|
|
|
double magsq = ci.real() * ci.real() + ci.imag() * ci.imag();
|
|
|
|
magsq /= (SDR_TX_SCALED*SDR_TX_SCALED);
|
|
|
|
m_movingAverage(magsq);
|
|
|
|
m_magsq = m_movingAverage.asDouble();
|
|
|
|
|
|
|
|
sample.m_real = (FixReal) ci.real();
|
|
|
|
sample.m_imag = (FixReal) ci.imag();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NFMModSource::prefetch(unsigned int nbSamples)
|
|
|
|
{
|
2024-08-24 07:17:02 -04:00
|
|
|
unsigned int nbSamplesAudio = (nbSamples * (unsigned int) ((Real) m_audioSampleRate / (Real) m_channelSampleRate));
|
2019-11-14 19:04:24 -05:00
|
|
|
pullAudio(nbSamplesAudio);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NFMModSource::pullAudio(unsigned int nbSamplesAudio)
|
|
|
|
{
|
2020-11-22 12:33:52 -05:00
|
|
|
QMutexLocker mlock(&m_mutex);
|
|
|
|
|
|
|
|
if (nbSamplesAudio > m_audioBuffer.size()) {
|
2019-11-14 19:04:24 -05:00
|
|
|
m_audioBuffer.resize(nbSamplesAudio);
|
|
|
|
}
|
|
|
|
|
2020-11-22 12:33:52 -05:00
|
|
|
std::copy(&m_audioReadBuffer[0], &m_audioReadBuffer[nbSamplesAudio], &m_audioBuffer[0]);
|
2019-11-14 19:04:24 -05:00
|
|
|
m_audioBufferFill = 0;
|
2020-11-22 12:33:52 -05:00
|
|
|
|
|
|
|
if (m_audioReadBufferFill > nbSamplesAudio) // copy back remaining samples at the start of the read buffer
|
|
|
|
{
|
|
|
|
std::copy(&m_audioReadBuffer[nbSamplesAudio], &m_audioReadBuffer[m_audioReadBufferFill], &m_audioReadBuffer[0]);
|
|
|
|
m_audioReadBufferFill = m_audioReadBufferFill - nbSamplesAudio; // adjust current read buffer fill pointer
|
|
|
|
}
|
2019-11-14 19:04:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void NFMModSource::modulateSample()
|
|
|
|
{
|
2024-08-24 07:17:02 -04:00
|
|
|
Real t0 = 0.0f;
|
|
|
|
Real t1 = 0.0f;
|
|
|
|
Real t = 0.0f;
|
2019-11-14 19:04:24 -05:00
|
|
|
|
|
|
|
pullAF(t0);
|
2022-06-04 02:47:10 -04:00
|
|
|
|
|
|
|
if (m_settings.m_preEmphasisOn) {
|
|
|
|
m_preemphasisFilter.process(t0, t);
|
|
|
|
} else {
|
|
|
|
t = t0;
|
|
|
|
}
|
2019-11-14 19:04:24 -05:00
|
|
|
|
|
|
|
if (m_settings.m_feedbackAudioEnable) {
|
|
|
|
pushFeedback(t * m_settings.m_feedbackVolumeFactor * 16384.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
calculateLevel(t);
|
|
|
|
|
2020-09-21 17:51:45 -04:00
|
|
|
if (m_settings.m_ctcssOn) {
|
2023-11-26 05:37:55 -05:00
|
|
|
t1 = 0.85f * m_bandpass.filter(t) + 0.15f * 0.625f * m_ctcssNco.next();
|
2021-04-12 06:03:33 -04:00
|
|
|
} else if (m_settings.m_dcsOn) {
|
2024-08-24 07:17:02 -04:00
|
|
|
t1 = 0.9f * m_bandpass.filter(t) + 0.1f * 0.625f * (float) m_dcsMod.next();
|
2022-06-04 02:47:10 -04:00
|
|
|
} else if (m_settings.m_bpfOn) {
|
2023-11-26 05:37:55 -05:00
|
|
|
t1 = m_bandpass.filter(t);
|
2022-06-04 02:47:10 -04:00
|
|
|
} else {
|
2023-11-26 05:37:55 -05:00
|
|
|
t1 = m_lowpass.filter(t);
|
2019-11-14 19:04:24 -05:00
|
|
|
}
|
|
|
|
|
2024-08-24 07:17:02 -04:00
|
|
|
m_modPhasor += (float) ((M_PI * m_settings.m_fmDeviation / (float) m_audioSampleRate) * t1);
|
2020-12-20 20:30:29 -05:00
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
// limit phasor range to ]-pi,pi]
|
|
|
|
if (m_modPhasor > M_PI) {
|
2024-08-24 07:17:02 -04:00
|
|
|
m_modPhasor -= (float) (2.0 * M_PI);
|
2019-11-14 19:04:24 -05:00
|
|
|
}
|
|
|
|
|
2024-08-24 07:17:02 -04:00
|
|
|
m_modSample.real((float) (cos(m_modPhasor) * 0.891235351562f * SDR_TX_SCALEF)); // -1 dB
|
|
|
|
m_modSample.imag((float) (sin(m_modPhasor) * 0.891235351562f * SDR_TX_SCALEF));
|
2020-12-20 20:30:29 -05:00
|
|
|
|
2024-08-24 07:17:02 -04:00
|
|
|
m_demodBuffer[m_demodBufferFill] = (qint16) (t1 * std::numeric_limits<int16_t>::max());
|
2020-12-20 20:30:29 -05:00
|
|
|
++m_demodBufferFill;
|
|
|
|
|
|
|
|
if (m_demodBufferFill >= m_demodBuffer.size())
|
|
|
|
{
|
2022-02-20 16:08:49 -05:00
|
|
|
QList<ObjectPipe*> dataPipes;
|
|
|
|
MainCore::instance()->getDataPipes().getDataPipes(m_channel, "demod", dataPipes);
|
2020-12-20 20:30:29 -05:00
|
|
|
|
2024-08-24 07:17:02 -04:00
|
|
|
if (!dataPipes.empty())
|
2020-12-20 20:30:29 -05:00
|
|
|
{
|
2024-08-24 07:17:02 -04:00
|
|
|
for (auto& dataPipe : dataPipes)
|
2022-02-20 16:08:49 -05:00
|
|
|
{
|
2024-08-24 07:17:02 -04:00
|
|
|
DataFifo *fifo = qobject_cast<DataFifo*>(dataPipe->m_element);
|
2022-02-20 16:08:49 -05:00
|
|
|
|
|
|
|
if (fifo) {
|
|
|
|
fifo->write((quint8*) &m_demodBuffer[0], m_demodBuffer.size() * sizeof(qint16), DataFifo::DataTypeI16);
|
|
|
|
}
|
2020-12-20 20:30:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_demodBufferFill = 0;
|
|
|
|
}
|
2019-11-14 19:04:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void NFMModSource::pullAF(Real& sample)
|
|
|
|
{
|
|
|
|
switch (m_settings.m_modAFInput)
|
|
|
|
{
|
|
|
|
case NFMModSettings::NFMModInputTone:
|
|
|
|
sample = m_toneNco.next();
|
|
|
|
break;
|
|
|
|
case NFMModSettings::NFMModInputFile:
|
|
|
|
if (m_ifstream && m_ifstream->is_open())
|
|
|
|
{
|
2024-08-24 07:17:02 -04:00
|
|
|
if (m_ifstream->eof() && m_settings.m_playLoop)
|
2019-11-14 19:04:24 -05:00
|
|
|
{
|
2024-08-24 07:17:02 -04:00
|
|
|
m_ifstream->clear();
|
|
|
|
m_ifstream->seekg(0, std::ios::beg);
|
2019-11-14 19:04:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_ifstream->eof())
|
|
|
|
{
|
|
|
|
sample = 0.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_ifstream->read(reinterpret_cast<char*>(&sample), sizeof(Real));
|
|
|
|
sample *= m_settings.m_volumeFactor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sample = 0.0f;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NFMModSettings::NFMModInputAudio:
|
2020-11-22 12:33:52 -05:00
|
|
|
if (m_audioBufferFill < m_audioBuffer.size())
|
|
|
|
{
|
2022-08-15 07:09:49 -04:00
|
|
|
if (m_settings.m_compressorEnable)
|
|
|
|
{
|
|
|
|
sample = ((m_audioBuffer[m_audioBufferFill].l + m_audioBuffer[m_audioBufferFill].r) / 3276.8f);
|
|
|
|
sample = clamp<float>(m_audioCompressor.compress(sample), -1.0f, 1.0f) * m_settings.m_volumeFactor * 3.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sample = ((m_audioBuffer[m_audioBufferFill].l + m_audioBuffer[m_audioBufferFill].r) / 3276.8f) * m_settings.m_volumeFactor;
|
|
|
|
}
|
|
|
|
|
2020-11-22 12:33:52 -05:00
|
|
|
m_audioBufferFill++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-08-24 07:17:02 -04:00
|
|
|
std::size_t size = m_audioBuffer.size();
|
|
|
|
qDebug("NFMModSource::pullAF: starve audio samples: size: %lu", size);
|
2020-11-22 12:33:52 -05:00
|
|
|
sample = ((m_audioBuffer[size-1].l + m_audioBuffer[size-1].r) / 65536.0f) * m_settings.m_volumeFactor;
|
|
|
|
}
|
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
break;
|
|
|
|
case NFMModSettings::NFMModInputCWTone:
|
|
|
|
Real fadeFactor;
|
|
|
|
|
2024-08-17 16:33:30 -04:00
|
|
|
if (!m_cwKeyer) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_cwKeyer->getSample())
|
2019-11-14 19:04:24 -05:00
|
|
|
{
|
2024-08-17 16:33:30 -04:00
|
|
|
m_cwKeyer->getCWSmoother().getFadeSample(true, fadeFactor);
|
2019-11-14 19:04:24 -05:00
|
|
|
sample = m_toneNco.next() * fadeFactor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-08-17 16:33:30 -04:00
|
|
|
if (m_cwKeyer->getCWSmoother().getFadeSample(false, fadeFactor))
|
2019-11-14 19:04:24 -05:00
|
|
|
{
|
|
|
|
sample = m_toneNco.next() * fadeFactor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sample = 0.0f;
|
|
|
|
m_toneNco.setPhase(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sample = 0.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NFMModSource::pushFeedback(Real sample)
|
|
|
|
{
|
|
|
|
Complex c(sample, sample);
|
|
|
|
Complex ci;
|
|
|
|
|
|
|
|
if (m_feedbackInterpolatorDistance < 1.0f) // interpolate
|
|
|
|
{
|
|
|
|
while (!m_feedbackInterpolator.interpolate(&m_feedbackInterpolatorDistanceRemain, c, &ci))
|
|
|
|
{
|
|
|
|
processOneSample(ci);
|
|
|
|
m_feedbackInterpolatorDistanceRemain += m_feedbackInterpolatorDistance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // decimate
|
|
|
|
{
|
|
|
|
if (m_feedbackInterpolator.decimate(&m_feedbackInterpolatorDistanceRemain, c, &ci))
|
|
|
|
{
|
|
|
|
processOneSample(ci);
|
|
|
|
m_feedbackInterpolatorDistanceRemain += m_feedbackInterpolatorDistance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-24 07:17:02 -04:00
|
|
|
void NFMModSource::processOneSample(const Complex& ci)
|
2019-11-14 19:04:24 -05:00
|
|
|
{
|
2024-08-24 07:17:02 -04:00
|
|
|
m_feedbackAudioBuffer[m_feedbackAudioBufferFill].l = (qint16) ci.real();
|
|
|
|
m_feedbackAudioBuffer[m_feedbackAudioBufferFill].r = (qint16) ci.imag();
|
2019-11-14 19:04:24 -05:00
|
|
|
++m_feedbackAudioBufferFill;
|
|
|
|
|
|
|
|
if (m_feedbackAudioBufferFill >= m_feedbackAudioBuffer.size())
|
|
|
|
{
|
|
|
|
uint res = m_feedbackAudioFifo.write((const quint8*)&m_feedbackAudioBuffer[0], m_feedbackAudioBufferFill);
|
|
|
|
|
|
|
|
if (res != m_feedbackAudioBufferFill)
|
|
|
|
{
|
|
|
|
qDebug("NFMModSource::pushFeedback: %u/%u audio samples written m_feedbackInterpolatorDistance: %f",
|
|
|
|
res, m_feedbackAudioBufferFill, m_feedbackInterpolatorDistance);
|
|
|
|
m_feedbackAudioFifo.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_feedbackAudioBufferFill = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-24 07:17:02 -04:00
|
|
|
void NFMModSource::calculateLevel(const Real& sample)
|
2019-11-14 19:04:24 -05:00
|
|
|
{
|
|
|
|
if (m_levelCalcCount < m_levelNbSamples)
|
|
|
|
{
|
|
|
|
m_peakLevel = std::max(std::fabs(m_peakLevel), sample);
|
|
|
|
m_levelSum += sample * sample;
|
|
|
|
m_levelCalcCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-07 05:47:52 -05:00
|
|
|
m_rmsLevel = sqrt(m_levelSum / m_levelNbSamples);
|
2019-11-14 19:04:24 -05:00
|
|
|
m_peakLevelOut = m_peakLevel;
|
|
|
|
m_peakLevel = 0.0f;
|
|
|
|
m_levelSum = 0.0f;
|
|
|
|
m_levelCalcCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-02 04:11:41 -04:00
|
|
|
void NFMModSource::applyAudioSampleRate(int sampleRate)
|
2019-11-14 19:04:24 -05:00
|
|
|
{
|
2020-08-02 04:11:41 -04:00
|
|
|
if (sampleRate < 0)
|
|
|
|
{
|
|
|
|
qWarning("NFMModSource::applyAudioSampleRate: invalid sample rate %d", sampleRate);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug("NFMModSource::applyAudioSampleRate: %d", sampleRate);
|
2019-11-14 19:04:24 -05:00
|
|
|
|
|
|
|
m_interpolatorDistanceRemain = 0;
|
|
|
|
m_interpolatorConsumed = false;
|
|
|
|
m_interpolatorDistance = (Real) sampleRate / (Real) m_channelSampleRate;
|
|
|
|
m_interpolator.create(48, sampleRate, m_settings.m_rfBandwidth / 2.2, 3.0);
|
2022-06-04 02:47:10 -04:00
|
|
|
m_lowpass.create(301, sampleRate, m_settings.m_afBandwidth);
|
2019-11-14 19:04:24 -05:00
|
|
|
m_bandpass.create(301, sampleRate, 300.0, m_settings.m_afBandwidth);
|
2024-08-24 07:17:02 -04:00
|
|
|
m_toneNco.setFreq(m_settings.m_toneFrequency, (float) sampleRate);
|
|
|
|
m_ctcssNco.setFreq(NFMModSettings::getCTCSSFreq(m_settings.m_ctcssIndex), (float) sampleRate);
|
2021-04-12 06:03:33 -04:00
|
|
|
m_dcsMod.setSampleRate(sampleRate);
|
2024-08-17 16:33:30 -04:00
|
|
|
|
|
|
|
if (m_cwKeyer)
|
|
|
|
{
|
|
|
|
m_cwKeyer->setSampleRate(sampleRate);
|
|
|
|
m_cwKeyer->reset();
|
|
|
|
}
|
|
|
|
|
2024-08-24 07:17:02 -04:00
|
|
|
m_preemphasisFilter.configure(m_preemphasis * (float) sampleRate);
|
|
|
|
m_audioCompressor.m_rate = (float) sampleRate;
|
2022-08-15 07:09:49 -04:00
|
|
|
m_audioCompressor.initState();
|
2019-11-14 19:04:24 -05:00
|
|
|
m_audioSampleRate = sampleRate;
|
|
|
|
applyFeedbackAudioSampleRate(m_feedbackAudioSampleRate);
|
2020-12-20 20:30:29 -05:00
|
|
|
|
2022-02-25 17:43:50 -05:00
|
|
|
QList<ObjectPipe*> pipes;
|
2022-03-02 17:57:35 -05:00
|
|
|
MainCore::instance()->getMessagePipes().getMessagePipes(m_channel, "reportdemod", pipes);
|
2020-12-20 20:30:29 -05:00
|
|
|
|
2024-08-24 07:17:02 -04:00
|
|
|
if (!pipes.empty())
|
2020-12-20 20:30:29 -05:00
|
|
|
{
|
2022-02-25 17:43:50 -05:00
|
|
|
for (const auto& pipe : pipes)
|
2020-12-20 20:30:29 -05:00
|
|
|
{
|
2022-02-25 17:43:50 -05:00
|
|
|
MessageQueue* messageQueue = qobject_cast<MessageQueue*>(pipe->m_element);
|
2020-12-20 20:30:29 -05:00
|
|
|
MainCore::MsgChannelDemodReport *msg = MainCore::MsgChannelDemodReport::create(m_channel, sampleRate);
|
2022-02-25 17:43:50 -05:00
|
|
|
messageQueue->push(msg);
|
2020-12-20 20:30:29 -05:00
|
|
|
}
|
|
|
|
}
|
2019-11-14 19:04:24 -05:00
|
|
|
}
|
|
|
|
|
2020-08-02 04:11:41 -04:00
|
|
|
void NFMModSource::applyFeedbackAudioSampleRate(int sampleRate)
|
2019-11-14 19:04:24 -05:00
|
|
|
{
|
2020-08-02 04:11:41 -04:00
|
|
|
if (sampleRate < 0)
|
|
|
|
{
|
|
|
|
qWarning("NFMModSource::applyFeedbackAudioSampleRate: invalid sample rate %d", sampleRate);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug("NFMModSource::applyFeedbackAudioSampleRate: %d", sampleRate);
|
2019-11-14 19:04:24 -05:00
|
|
|
|
|
|
|
m_feedbackInterpolatorDistanceRemain = 0;
|
|
|
|
m_feedbackInterpolatorConsumed = false;
|
|
|
|
m_feedbackInterpolatorDistance = (Real) sampleRate / (Real) m_audioSampleRate;
|
2024-08-24 07:17:02 -04:00
|
|
|
Real cutoff = (float) std::min(sampleRate, m_audioSampleRate) / 2.2f;
|
2019-11-14 19:04:24 -05:00
|
|
|
m_feedbackInterpolator.create(48, sampleRate, cutoff, 3.0);
|
|
|
|
m_feedbackAudioSampleRate = sampleRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NFMModSource::applySettings(const NFMModSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
if ((settings.m_rfBandwidth != m_settings.m_rfBandwidth)
|
|
|
|
|| (settings.m_afBandwidth != m_settings.m_afBandwidth) || force)
|
|
|
|
{
|
|
|
|
m_settings.m_rfBandwidth = settings.m_rfBandwidth;
|
|
|
|
m_settings.m_afBandwidth = settings.m_afBandwidth;
|
|
|
|
applyAudioSampleRate(m_audioSampleRate);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_toneFrequency != m_settings.m_toneFrequency) || force) {
|
2024-08-24 07:17:02 -04:00
|
|
|
m_toneNco.setFreq(settings.m_toneFrequency, (float) m_audioSampleRate);
|
2019-11-14 19:04:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_ctcssIndex != m_settings.m_ctcssIndex) || force) {
|
2024-08-24 07:17:02 -04:00
|
|
|
m_ctcssNco.setFreq(NFMModSettings::getCTCSSFreq(settings.m_ctcssIndex), (float) m_audioSampleRate);
|
2019-11-14 19:04:24 -05:00
|
|
|
}
|
|
|
|
|
2021-04-12 06:03:33 -04:00
|
|
|
if ((settings.m_dcsCode != m_settings.m_dcsCode) || force) {
|
|
|
|
m_dcsMod.setDCS(settings.m_dcsCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings.m_dcsPositive != m_settings.m_dcsPositive) || force) {
|
|
|
|
m_dcsMod.setPositive(settings.m_dcsPositive);
|
|
|
|
}
|
|
|
|
|
2020-11-22 12:33:52 -05:00
|
|
|
if ((settings.m_modAFInput != m_settings.m_modAFInput) || force)
|
|
|
|
{
|
|
|
|
if (settings.m_modAFInput == NFMModSettings::NFMModInputAudio) {
|
|
|
|
connect(&m_audioFifo, SIGNAL(dataReady()), this, SLOT(handleAudio()));
|
|
|
|
} else {
|
|
|
|
disconnect(&m_audioFifo, SIGNAL(dataReady()), this, SLOT(handleAudio()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-14 19:04:24 -05:00
|
|
|
m_settings = settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NFMModSource::applyChannelSettings(int channelSampleRate, int channelFrequencyOffset, bool force)
|
|
|
|
{
|
|
|
|
qDebug() << "NFMModSource::applyChannelSettings:"
|
|
|
|
<< " channelSampleRate: " << channelSampleRate
|
|
|
|
<< " channelFrequencyOffset: " << channelFrequencyOffset;
|
|
|
|
|
|
|
|
if ((channelFrequencyOffset != m_channelFrequencyOffset)
|
|
|
|
|| (channelSampleRate != m_channelSampleRate) || force)
|
|
|
|
{
|
2024-08-24 07:17:02 -04:00
|
|
|
m_carrierNco.setFreq((float) channelFrequencyOffset, (float) channelSampleRate);
|
2019-11-14 19:04:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((channelSampleRate != m_channelSampleRate) || force)
|
|
|
|
{
|
|
|
|
m_interpolatorDistanceRemain = 0;
|
|
|
|
m_interpolatorConsumed = false;
|
|
|
|
m_interpolatorDistance = (Real) m_audioSampleRate / (Real) channelSampleRate;
|
|
|
|
m_interpolator.create(48, m_audioSampleRate, m_settings.m_rfBandwidth / 2.2, 3.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_channelSampleRate = channelSampleRate;
|
|
|
|
m_channelFrequencyOffset = channelFrequencyOffset;
|
2020-09-21 17:51:45 -04:00
|
|
|
}
|
2020-11-22 12:33:52 -05:00
|
|
|
|
|
|
|
void NFMModSource::handleAudio()
|
|
|
|
{
|
|
|
|
unsigned int nbRead;
|
|
|
|
|
|
|
|
while ((nbRead = m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioReadBuffer[m_audioReadBufferFill]), 4096)) != 0)
|
|
|
|
{
|
|
|
|
if (m_audioReadBufferFill + nbRead + 4096 < m_audioReadBuffer.size()) {
|
|
|
|
m_audioReadBufferFill += nbRead;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|