2016-12-11 18:48:27 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2016 Edouard Griffiths, F4EXB //
|
|
|
|
// //
|
|
|
|
// 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 //
|
2019-04-11 00:39:30 -04:00
|
|
|
// (at your option) any later version. //
|
2016-12-11 18:48:27 -05:00
|
|
|
// //
|
|
|
|
// 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 "ssbmod.h"
|
|
|
|
|
|
|
|
#include <QTime>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QMutexLocker>
|
2018-12-20 20:02:16 -05:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QBuffer>
|
2018-02-14 14:11:36 -05:00
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <complex.h>
|
2018-09-02 13:49:53 -04:00
|
|
|
#include <algorithm>
|
2018-02-14 14:11:36 -05:00
|
|
|
|
2018-04-14 15:46:53 -04:00
|
|
|
#include "SWGChannelSettings.h"
|
|
|
|
#include "SWGChannelReport.h"
|
|
|
|
#include "SWGSSBModReport.h"
|
|
|
|
|
2018-02-14 14:11:36 -05:00
|
|
|
#include "dsp/upchannelizer.h"
|
2016-12-11 18:48:27 -05:00
|
|
|
#include "dsp/dspengine.h"
|
2017-10-21 10:01:16 -04:00
|
|
|
#include "dsp/threadedbasebandsamplesource.h"
|
2018-02-14 14:11:36 -05:00
|
|
|
#include "dsp/dspcommands.h"
|
2019-05-08 16:11:53 -04:00
|
|
|
#include "device/deviceapi.h"
|
2017-08-05 13:08:33 -04:00
|
|
|
#include "util/db.h"
|
2016-12-11 18:48:27 -05:00
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgConfigureSSBMod, Message)
|
2017-10-21 06:17:11 -04:00
|
|
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgConfigureChannelizer, Message)
|
2016-12-11 18:48:27 -05:00
|
|
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgConfigureFileSourceName, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgConfigureFileSourceSeek, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgConfigureFileSourceStreamTiming, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgReportFileSourceStreamData, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgReportFileSourceStreamTiming, Message)
|
|
|
|
|
2017-11-22 19:19:32 -05:00
|
|
|
const QString SSBMod::m_channelIdURI = "sdrangel.channeltx.modssb";
|
|
|
|
const QString SSBMod::m_channelId = "SSBMod";
|
2016-12-11 18:48:27 -05:00
|
|
|
const int SSBMod::m_levelNbSamples = 480; // every 10ms
|
2016-12-12 18:43:59 -05:00
|
|
|
const int SSBMod::m_ssbFftLen = 1024;
|
2016-12-11 18:48:27 -05:00
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
SSBMod::SSBMod(DeviceAPI *deviceAPI) :
|
2019-05-09 11:27:12 -04:00
|
|
|
ChannelAPI(m_channelIdURI, ChannelAPI::StreamSingleSource),
|
2017-10-21 10:01:16 -04:00
|
|
|
m_deviceAPI(deviceAPI),
|
2017-12-29 18:18:51 -05:00
|
|
|
m_basebandSampleRate(48000),
|
|
|
|
m_outputSampleRate(48000),
|
|
|
|
m_inputFrequencyOffset(0),
|
2016-12-12 18:43:59 -05:00
|
|
|
m_SSBFilter(0),
|
|
|
|
m_DSBFilter(0),
|
2016-12-13 13:57:07 -05:00
|
|
|
m_SSBFilterBuffer(0),
|
|
|
|
m_DSBFilterBuffer(0),
|
|
|
|
m_SSBFilterBufferIndex(0),
|
|
|
|
m_DSBFilterBufferIndex(0),
|
2017-11-08 11:09:25 -05:00
|
|
|
m_sampleSink(0),
|
2017-08-24 18:02:49 -04:00
|
|
|
m_audioFifo(4800),
|
2016-12-11 18:48:27 -05:00
|
|
|
m_settingsMutex(QMutex::Recursive),
|
|
|
|
m_fileSize(0),
|
|
|
|
m_recordLength(0),
|
|
|
|
m_sampleRate(48000),
|
|
|
|
m_levelCalcCount(0),
|
|
|
|
m_peakLevel(0.0f),
|
2017-08-05 13:08:33 -04:00
|
|
|
m_levelSum(0.0f),
|
2018-05-05 20:39:39 -04:00
|
|
|
m_agcStepLength(2400)
|
2016-12-11 18:48:27 -05:00
|
|
|
{
|
2017-11-22 19:19:32 -05:00
|
|
|
setObjectName(m_channelId);
|
2016-12-11 18:48:27 -05:00
|
|
|
|
2018-03-29 10:57:42 -04:00
|
|
|
DSPEngine::instance()->getAudioDeviceManager()->addAudioSource(&m_audioFifo, getInputMessageQueue());
|
|
|
|
m_audioSampleRate = DSPEngine::instance()->getAudioDeviceManager()->getInputSampleRate();
|
|
|
|
|
|
|
|
m_SSBFilter = new fftfilt(m_settings.m_lowCutoff / m_audioSampleRate, m_settings.m_bandwidth / m_audioSampleRate, m_ssbFftLen);
|
|
|
|
m_DSBFilter = new fftfilt((2.0f * m_settings.m_bandwidth) / m_audioSampleRate, 2 * m_ssbFftLen);
|
2016-12-13 17:00:09 -05:00
|
|
|
m_SSBFilterBuffer = new Complex[m_ssbFftLen>>1]; // filter returns data exactly half of its size
|
|
|
|
m_DSBFilterBuffer = new Complex[m_ssbFftLen];
|
2018-09-02 13:49:53 -04:00
|
|
|
std::fill(m_SSBFilterBuffer, m_SSBFilterBuffer+(m_ssbFftLen>>1), Complex{0,0});
|
|
|
|
std::fill(m_DSBFilterBuffer, m_DSBFilterBuffer+m_ssbFftLen, Complex{0,0});
|
|
|
|
// memset(m_SSBFilterBuffer, 0, sizeof(Complex)*(m_ssbFftLen>>1));
|
|
|
|
// memset(m_DSBFilterBuffer, 0, sizeof(Complex)*(m_ssbFftLen));
|
2016-12-13 17:00:09 -05:00
|
|
|
|
2016-12-25 19:39:34 -05:00
|
|
|
m_audioBuffer.resize(1<<14);
|
|
|
|
m_audioBufferFill = 0;
|
2016-12-11 18:48:27 -05:00
|
|
|
|
2016-12-13 18:14:52 -05:00
|
|
|
m_sum.real(0.0f);
|
|
|
|
m_sum.imag(0.0f);
|
|
|
|
m_undersampleCount = 0;
|
|
|
|
m_sumCount = 0;
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
m_magsq = 0.0;
|
|
|
|
|
2018-03-29 10:57:42 -04:00
|
|
|
m_toneNco.setFreq(1000.0, m_audioSampleRate);
|
|
|
|
m_cwKeyer.setSampleRate(48000);
|
2019-07-29 19:31:46 -04:00
|
|
|
m_cwKeyer.reset();
|
2019-07-17 19:48:07 -04:00
|
|
|
|
|
|
|
m_audioCompressor.initSimple(
|
2019-07-18 16:07:45 -04:00
|
|
|
m_audioSampleRate,
|
2019-07-17 19:48:07 -04:00
|
|
|
50, // pregain (dB)
|
|
|
|
-30, // threshold (dB)
|
|
|
|
20, // knee (dB)
|
|
|
|
12, // ratio (dB)
|
|
|
|
0.003, // attack (s)
|
|
|
|
0.25 // release (s)
|
|
|
|
);
|
2017-11-05 19:39:44 -05:00
|
|
|
|
2018-03-16 05:26:49 -04:00
|
|
|
applyChannelSettings(m_basebandSampleRate, m_outputSampleRate, m_inputFrequencyOffset, true);
|
|
|
|
applySettings(m_settings, true);
|
|
|
|
|
2017-11-05 19:39:44 -05:00
|
|
|
m_channelizer = new UpChannelizer(this);
|
|
|
|
m_threadedChannelizer = new ThreadedBasebandSampleSource(m_channelizer, this);
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->addChannelSource(m_threadedChannelizer);
|
|
|
|
m_deviceAPI->addChannelSourceAPI(this);
|
2018-12-20 20:02:16 -05:00
|
|
|
|
|
|
|
m_networkManager = new QNetworkAccessManager();
|
|
|
|
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SSBMod::~SSBMod()
|
|
|
|
{
|
2018-12-20 20:02:16 -05:00
|
|
|
disconnect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*)));
|
|
|
|
delete m_networkManager;
|
|
|
|
|
2018-03-23 22:36:49 -04:00
|
|
|
DSPEngine::instance()->getAudioDeviceManager()->removeAudioSource(&m_audioFifo);
|
2017-10-21 10:01:16 -04:00
|
|
|
|
2019-05-08 16:11:53 -04:00
|
|
|
m_deviceAPI->removeChannelSourceAPI(this);
|
|
|
|
m_deviceAPI->removeChannelSource(m_threadedChannelizer);
|
2017-10-21 10:01:16 -04:00
|
|
|
delete m_threadedChannelizer;
|
|
|
|
delete m_channelizer;
|
2018-04-18 16:20:47 -04:00
|
|
|
|
|
|
|
delete m_SSBFilter;
|
|
|
|
delete m_DSBFilter;
|
|
|
|
delete[] m_SSBFilterBuffer;
|
|
|
|
delete[] m_DSBFilterBuffer;
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SSBMod::pull(Sample& sample)
|
|
|
|
{
|
|
|
|
Complex ci;
|
|
|
|
|
|
|
|
m_settingsMutex.lock();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-12-13 19:16:23 -05:00
|
|
|
ci *= m_carrierNco.nextIQ(); // shift to carrier frequency
|
2018-01-22 02:46:05 -05:00
|
|
|
ci *= 0.891235351562f * SDR_TX_SCALEF; //scaling at -1 dB to account for possible filter overshoot
|
2016-12-11 18:48:27 -05:00
|
|
|
|
|
|
|
m_settingsMutex.unlock();
|
|
|
|
|
2018-01-21 04:57:04 -05:00
|
|
|
double magsq = ci.real() * ci.real() + ci.imag() * ci.imag();
|
2018-01-22 02:46:05 -05:00
|
|
|
magsq /= (SDR_TX_SCALED*SDR_TX_SCALED);
|
2018-02-03 04:33:02 -05:00
|
|
|
m_movingAverage(magsq);
|
|
|
|
m_magsq = m_movingAverage.asDouble();
|
2016-12-11 18:48:27 -05:00
|
|
|
|
|
|
|
sample.m_real = (FixReal) ci.real();
|
|
|
|
sample.m_imag = (FixReal) ci.imag();
|
|
|
|
}
|
|
|
|
|
2016-12-25 19:39:34 -05:00
|
|
|
void SSBMod::pullAudio(int nbSamples)
|
|
|
|
{
|
2018-03-29 10:57:42 -04:00
|
|
|
unsigned int nbSamplesAudio = nbSamples * ((Real) m_audioSampleRate / (Real) m_basebandSampleRate);
|
2016-12-25 20:15:24 -05:00
|
|
|
|
|
|
|
if (nbSamplesAudio > m_audioBuffer.size())
|
2016-12-25 19:39:34 -05:00
|
|
|
{
|
2016-12-25 20:15:24 -05:00
|
|
|
m_audioBuffer.resize(nbSamplesAudio);
|
2016-12-25 19:39:34 -05:00
|
|
|
}
|
|
|
|
|
2018-09-12 09:30:53 -04:00
|
|
|
m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioBuffer[0]), nbSamplesAudio);
|
2016-12-25 19:39:34 -05:00
|
|
|
m_audioBufferFill = 0;
|
|
|
|
}
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
void SSBMod::modulateSample()
|
|
|
|
{
|
2016-12-13 19:16:23 -05:00
|
|
|
pullAF(m_modSample);
|
|
|
|
calculateLevel(m_modSample);
|
2016-12-25 20:15:24 -05:00
|
|
|
m_audioBufferFill++;
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
|
|
|
|
2016-12-12 18:43:59 -05:00
|
|
|
void SSBMod::pullAF(Complex& sample)
|
2016-12-11 18:48:27 -05:00
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_audioMute)
|
2016-12-14 07:52:46 -05:00
|
|
|
{
|
|
|
|
sample.real(0.0f);
|
|
|
|
sample.imag(0.0f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-13 13:57:07 -05:00
|
|
|
Complex ci;
|
|
|
|
fftfilt::cmplx *filtered;
|
2016-12-13 18:14:52 -05:00
|
|
|
int n_out = 0;
|
|
|
|
|
2017-10-21 06:17:11 -04:00
|
|
|
int decim = 1<<(m_settings.m_spanLog2 - 1);
|
2016-12-13 18:14:52 -05:00
|
|
|
unsigned char decim_mask = decim - 1; // counter LSB bit mask for decimation by 2^(m_scaleLog2 - 1)
|
2016-12-11 18:48:27 -05:00
|
|
|
|
2018-04-13 02:41:34 -04:00
|
|
|
switch (m_settings.m_modAFInput)
|
2016-12-11 18:48:27 -05:00
|
|
|
{
|
2018-04-13 02:41:34 -04:00
|
|
|
case SSBModSettings::SSBModInputTone:
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_dsb)
|
2016-12-13 13:57:07 -05:00
|
|
|
{
|
2017-10-12 13:35:57 -04:00
|
|
|
Real t = m_toneNco.next()/1.25;
|
2016-12-13 13:57:07 -05:00
|
|
|
sample.real(t);
|
|
|
|
sample.imag(t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_usb) {
|
2016-12-13 13:57:07 -05:00
|
|
|
sample = m_toneNco.nextIQ();
|
|
|
|
} else {
|
|
|
|
sample = m_toneNco.nextQI();
|
|
|
|
}
|
|
|
|
}
|
2016-12-11 18:48:27 -05:00
|
|
|
break;
|
2018-04-13 02:41:34 -04:00
|
|
|
case SSBModSettings::SSBModInputFile:
|
2016-12-14 07:52:46 -05:00
|
|
|
// Monaural (mono):
|
2016-12-11 18:48:27 -05:00
|
|
|
// sox f4exb_call.wav --encoding float --endian little f4exb_call.raw
|
|
|
|
// ffplay -f f32le -ar 48k -ac 1 f4exb_call.raw
|
2016-12-14 07:52:46 -05:00
|
|
|
// Binaural (stereo):
|
|
|
|
// sox f4exb_call.wav --encoding float --endian little f4exb_call.raw
|
|
|
|
// ffplay -f f32le -ar 48k -ac 2 f4exb_call.raw
|
2016-12-11 18:48:27 -05:00
|
|
|
if (m_ifstream.is_open())
|
|
|
|
{
|
2016-12-13 20:57:47 -05:00
|
|
|
if (m_ifstream.eof())
|
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_playLoop)
|
2016-12-13 20:57:47 -05:00
|
|
|
{
|
|
|
|
m_ifstream.clear();
|
|
|
|
m_ifstream.seekg(0, std::ios::beg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
if (m_ifstream.eof())
|
|
|
|
{
|
2016-12-13 13:57:07 -05:00
|
|
|
ci.real(0.0f);
|
|
|
|
ci.imag(0.0f);
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_audioBinaural)
|
2016-12-14 07:52:46 -05:00
|
|
|
{
|
|
|
|
Complex c;
|
|
|
|
m_ifstream.read(reinterpret_cast<char*>(&c), sizeof(Complex));
|
|
|
|
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_audioFlipChannels)
|
2016-12-14 07:52:46 -05:00
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
ci.real(c.imag() * m_settings.m_volumeFactor);
|
|
|
|
ci.imag(c.real() * m_settings.m_volumeFactor);
|
2016-12-14 07:52:46 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
ci = c * m_settings.m_volumeFactor;
|
2016-12-14 07:52:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Real real;
|
|
|
|
m_ifstream.read(reinterpret_cast<char*>(&real), sizeof(Real));
|
2017-08-05 13:08:33 -04:00
|
|
|
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_agc)
|
2017-08-05 13:08:33 -04:00
|
|
|
{
|
2019-07-17 19:48:07 -04:00
|
|
|
real = m_audioCompressor.compress(real);
|
2017-08-05 13:08:33 -04:00
|
|
|
ci.real(real);
|
|
|
|
ci.imag(0.0f);
|
2017-10-21 06:17:11 -04:00
|
|
|
ci *= m_settings.m_volumeFactor;
|
2017-08-05 13:08:33 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
ci.real(real * m_settings.m_volumeFactor);
|
2017-08-05 13:08:33 -04:00
|
|
|
ci.imag(0.0f);
|
|
|
|
}
|
2016-12-14 07:52:46 -05:00
|
|
|
}
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-13 13:57:07 -05:00
|
|
|
ci.real(0.0f);
|
|
|
|
ci.imag(0.0f);
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
|
|
|
break;
|
2018-04-13 02:41:34 -04:00
|
|
|
case SSBModSettings::SSBModInputAudio:
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_audioBinaural)
|
2016-12-14 07:52:46 -05:00
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_audioFlipChannels)
|
2016-12-14 07:52:46 -05:00
|
|
|
{
|
2018-01-22 02:46:05 -05:00
|
|
|
ci.real((m_audioBuffer[m_audioBufferFill].r / SDR_TX_SCALEF) * m_settings.m_volumeFactor);
|
|
|
|
ci.imag((m_audioBuffer[m_audioBufferFill].l / SDR_TX_SCALEF) * m_settings.m_volumeFactor);
|
2016-12-14 07:52:46 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-22 02:46:05 -05:00
|
|
|
ci.real((m_audioBuffer[m_audioBufferFill].l / SDR_TX_SCALEF) * m_settings.m_volumeFactor);
|
|
|
|
ci.imag((m_audioBuffer[m_audioBufferFill].r / SDR_TX_SCALEF) * m_settings.m_volumeFactor);
|
2016-12-14 07:52:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_agc)
|
2017-08-05 13:08:33 -04:00
|
|
|
{
|
|
|
|
ci.real(((m_audioBuffer[m_audioBufferFill].l + m_audioBuffer[m_audioBufferFill].r) / 65536.0f));
|
2019-07-17 19:48:07 -04:00
|
|
|
ci.real(m_audioCompressor.compress(ci.real()));
|
2017-08-05 13:08:33 -04:00
|
|
|
ci.imag(0.0f);
|
2017-10-21 06:17:11 -04:00
|
|
|
ci *= m_settings.m_volumeFactor;
|
2017-08-05 13:08:33 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
ci.real(((m_audioBuffer[m_audioBufferFill].l + m_audioBuffer[m_audioBufferFill].r) / 65536.0f) * m_settings.m_volumeFactor);
|
2017-08-05 13:08:33 -04:00
|
|
|
ci.imag(0.0f);
|
|
|
|
}
|
2016-12-14 07:52:46 -05:00
|
|
|
}
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
break;
|
2018-04-13 02:41:34 -04:00
|
|
|
case SSBModSettings::SSBModInputCWTone:
|
2016-12-14 13:08:05 -05:00
|
|
|
Real fadeFactor;
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
if (m_cwKeyer.getSample())
|
|
|
|
{
|
2017-10-20 23:01:47 -04:00
|
|
|
m_cwKeyer.getCWSmoother().getFadeSample(true, fadeFactor);
|
2016-12-14 13:08:05 -05:00
|
|
|
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_dsb)
|
2016-12-13 13:57:07 -05:00
|
|
|
{
|
2016-12-14 13:08:05 -05:00
|
|
|
Real t = m_toneNco.next() * fadeFactor;
|
2016-12-13 13:57:07 -05:00
|
|
|
sample.real(t);
|
|
|
|
sample.imag(t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_usb) {
|
2016-12-14 13:08:05 -05:00
|
|
|
sample = m_toneNco.nextIQ() * fadeFactor;
|
2016-12-13 13:57:07 -05:00
|
|
|
} else {
|
2016-12-14 13:08:05 -05:00
|
|
|
sample = m_toneNco.nextQI() * fadeFactor;
|
2016-12-13 13:57:07 -05:00
|
|
|
}
|
|
|
|
}
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-20 23:01:47 -04:00
|
|
|
if (m_cwKeyer.getCWSmoother().getFadeSample(false, fadeFactor))
|
2016-12-14 13:08:05 -05:00
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_dsb)
|
2016-12-14 13:08:05 -05:00
|
|
|
{
|
2017-10-12 13:35:57 -04:00
|
|
|
Real t = (m_toneNco.next() * fadeFactor)/1.25;
|
2016-12-14 13:08:05 -05:00
|
|
|
sample.real(t);
|
|
|
|
sample.imag(t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_usb) {
|
2016-12-14 13:08:05 -05:00
|
|
|
sample = m_toneNco.nextIQ() * fadeFactor;
|
|
|
|
} else {
|
|
|
|
sample = m_toneNco.nextQI() * fadeFactor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sample.real(0.0f);
|
|
|
|
sample.imag(0.0f);
|
|
|
|
m_toneNco.setPhase(0);
|
|
|
|
}
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
2016-12-14 13:08:05 -05:00
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
break;
|
2018-04-13 02:41:34 -04:00
|
|
|
case SSBModSettings::SSBModInputNone:
|
2016-12-11 18:48:27 -05:00
|
|
|
default:
|
2018-08-05 06:48:02 -04:00
|
|
|
sample.real(0.0f);
|
|
|
|
sample.imag(0.0f);
|
2016-12-11 18:48:27 -05:00
|
|
|
break;
|
|
|
|
}
|
2016-12-13 13:57:07 -05:00
|
|
|
|
2018-04-13 02:41:34 -04:00
|
|
|
if ((m_settings.m_modAFInput == SSBModSettings::SSBModInputFile)
|
|
|
|
|| (m_settings.m_modAFInput == SSBModSettings::SSBModInputAudio)) // real audio
|
2016-12-13 13:57:07 -05:00
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_settings.m_dsb)
|
2016-12-13 13:57:07 -05:00
|
|
|
{
|
|
|
|
n_out = m_DSBFilter->runDSB(ci, &filtered);
|
|
|
|
|
|
|
|
if (n_out > 0)
|
|
|
|
{
|
|
|
|
memcpy((void *) m_DSBFilterBuffer, (const void *) filtered, n_out*sizeof(Complex));
|
|
|
|
m_DSBFilterBufferIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sample = m_DSBFilterBuffer[m_DSBFilterBufferIndex];
|
|
|
|
m_DSBFilterBufferIndex++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
n_out = m_SSBFilter->runSSB(ci, &filtered, m_settings.m_usb);
|
2016-12-13 13:57:07 -05:00
|
|
|
|
|
|
|
if (n_out > 0)
|
|
|
|
{
|
|
|
|
memcpy((void *) m_SSBFilterBuffer, (const void *) filtered, n_out*sizeof(Complex));
|
|
|
|
m_SSBFilterBufferIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sample = m_SSBFilterBuffer[m_SSBFilterBufferIndex];
|
|
|
|
m_SSBFilterBufferIndex++;
|
|
|
|
}
|
2016-12-13 18:14:52 -05:00
|
|
|
|
|
|
|
if (n_out > 0)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < n_out; i++)
|
|
|
|
{
|
|
|
|
// Downsample by 2^(m_scaleLog2 - 1) for SSB band spectrum display
|
|
|
|
// smart decimation with bit gain using float arithmetic (23 bits significand)
|
|
|
|
|
|
|
|
m_sum += filtered[i];
|
|
|
|
|
|
|
|
if (!(m_undersampleCount++ & decim_mask))
|
|
|
|
{
|
2018-01-22 02:46:05 -05:00
|
|
|
Real avgr = (m_sum.real() / decim) * 0.891235351562f * SDR_TX_SCALEF; //scaling at -1 dB to account for possible filter overshoot
|
|
|
|
Real avgi = (m_sum.imag() / decim) * 0.891235351562f * SDR_TX_SCALEF;
|
2016-12-13 18:14:52 -05:00
|
|
|
|
2017-10-21 06:17:11 -04:00
|
|
|
if (!m_settings.m_dsb & !m_settings.m_usb)
|
2016-12-13 18:14:52 -05:00
|
|
|
{ // invert spectrum for LSB
|
|
|
|
m_sampleBuffer.push_back(Sample(avgi, avgr));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_sampleBuffer.push_back(Sample(avgr, avgi));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sum.real(0.0);
|
|
|
|
m_sum.imag(0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // Real audio
|
2018-04-13 02:41:34 -04:00
|
|
|
else if ((m_settings.m_modAFInput == SSBModSettings::SSBModInputTone)
|
|
|
|
|| (m_settings.m_modAFInput == SSBModSettings::SSBModInputCWTone)) // tone
|
2016-12-13 18:14:52 -05:00
|
|
|
{
|
|
|
|
m_sum += sample;
|
|
|
|
|
|
|
|
if (!(m_undersampleCount++ & decim_mask))
|
|
|
|
{
|
2018-01-22 02:46:05 -05:00
|
|
|
Real avgr = (m_sum.real() / decim) * 0.891235351562f * SDR_TX_SCALEF; //scaling at -1 dB to account for possible filter overshoot
|
|
|
|
Real avgi = (m_sum.imag() / decim) * 0.891235351562f * SDR_TX_SCALEF;
|
2016-12-13 18:14:52 -05:00
|
|
|
|
2017-10-21 06:17:11 -04:00
|
|
|
if (!m_settings.m_dsb & !m_settings.m_usb)
|
2016-12-13 18:14:52 -05:00
|
|
|
{ // invert spectrum for LSB
|
|
|
|
m_sampleBuffer.push_back(Sample(avgi, avgr));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_sampleBuffer.push_back(Sample(avgr, avgi));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sum.real(0.0);
|
|
|
|
m_sum.imag(0.0);
|
|
|
|
}
|
|
|
|
|
2017-10-21 06:17:11 -04:00
|
|
|
if (m_sumCount < (m_settings.m_dsb ? m_ssbFftLen : m_ssbFftLen>>1))
|
2016-12-13 18:14:52 -05:00
|
|
|
{
|
|
|
|
n_out = 0;
|
|
|
|
m_sumCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n_out = m_sumCount;
|
|
|
|
m_sumCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_out > 0)
|
|
|
|
{
|
|
|
|
if (m_sampleSink != 0)
|
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), !m_settings.m_dsb);
|
2016-12-13 18:14:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
m_sampleBuffer.clear();
|
2016-12-13 13:57:07 -05:00
|
|
|
}
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
|
|
|
|
2016-12-12 18:43:59 -05:00
|
|
|
void SSBMod::calculateLevel(Complex& sample)
|
2016-12-11 18:48:27 -05:00
|
|
|
{
|
2016-12-12 18:43:59 -05:00
|
|
|
Real t = sample.real(); // TODO: possibly adjust depending on sample type
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
if (m_levelCalcCount < m_levelNbSamples)
|
|
|
|
{
|
2016-12-12 18:43:59 -05:00
|
|
|
m_peakLevel = std::max(std::fabs(m_peakLevel), t);
|
|
|
|
m_levelSum += t * t;
|
2016-12-11 18:48:27 -05:00
|
|
|
m_levelCalcCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qreal rmsLevel = sqrt(m_levelSum / m_levelNbSamples);
|
|
|
|
//qDebug("NFMMod::calculateLevel: %f %f", rmsLevel, m_peakLevel);
|
|
|
|
emit levelChanged(rmsLevel, m_peakLevel, m_levelNbSamples);
|
|
|
|
m_peakLevel = 0.0f;
|
|
|
|
m_levelSum = 0.0f;
|
|
|
|
m_levelCalcCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSBMod::start()
|
|
|
|
{
|
2017-12-29 18:18:51 -05:00
|
|
|
qDebug() << "SSBMod::start: m_outputSampleRate: " << m_outputSampleRate
|
2017-10-21 06:17:11 -04:00
|
|
|
<< " m_inputFrequencyOffset: " << m_settings.m_inputFrequencyOffset;
|
2016-12-11 18:48:27 -05:00
|
|
|
|
|
|
|
m_audioFifo.clear();
|
2018-01-08 19:10:49 -05:00
|
|
|
applyChannelSettings(m_basebandSampleRate, m_outputSampleRate, m_inputFrequencyOffset, true);
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SSBMod::stop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SSBMod::handleMessage(const Message& cmd)
|
|
|
|
{
|
|
|
|
if (UpChannelizer::MsgChannelizerNotification::match(cmd))
|
|
|
|
{
|
|
|
|
UpChannelizer::MsgChannelizerNotification& notif = (UpChannelizer::MsgChannelizerNotification&) cmd;
|
2017-12-29 18:18:51 -05:00
|
|
|
qDebug() << "SSBMod::handleMessage: MsgChannelizerNotification";
|
2016-12-11 18:48:27 -05:00
|
|
|
|
2017-12-29 18:18:51 -05:00
|
|
|
applyChannelSettings(notif.getBasebandSampleRate(), notif.getSampleRate(), notif.getFrequencyOffset());
|
2016-12-11 18:48:27 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-21 10:01:16 -04:00
|
|
|
else if (MsgConfigureChannelizer::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureChannelizer& cfg = (MsgConfigureChannelizer&) cmd;
|
2017-12-29 18:18:51 -05:00
|
|
|
qDebug() << "SSBMod::handleMessage: MsgConfigureChannelizer: sampleRate: " << cfg.getSampleRate()
|
|
|
|
<< " centerFrequency: " << cfg.getCenterFrequency();
|
2017-10-21 10:01:16 -04:00
|
|
|
|
|
|
|
m_channelizer->configure(m_channelizer->getInputMessageQueue(),
|
|
|
|
cfg.getSampleRate(),
|
|
|
|
cfg.getCenterFrequency());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-21 06:17:11 -04:00
|
|
|
else if (MsgConfigureSSBMod::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureSSBMod& cfg = (MsgConfigureSSBMod&) cmd;
|
2017-12-29 18:18:51 -05:00
|
|
|
qDebug() << "SSBMod::handleMessage: MsgConfigureSSBMod";
|
2016-12-11 18:48:27 -05:00
|
|
|
|
2017-12-29 18:18:51 -05:00
|
|
|
applySettings(cfg.getSettings(), cfg.getForce());
|
2017-10-21 06:17:11 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-12-11 18:48:27 -05:00
|
|
|
else if (MsgConfigureFileSourceName::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureFileSourceName& conf = (MsgConfigureFileSourceName&) cmd;
|
|
|
|
m_fileName = conf.getFileName();
|
|
|
|
openFileStream();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgConfigureFileSourceSeek::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureFileSourceSeek& conf = (MsgConfigureFileSourceSeek&) cmd;
|
|
|
|
int seekPercentage = conf.getPercentage();
|
|
|
|
seekFileStream(seekPercentage);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgConfigureFileSourceStreamTiming::match(cmd))
|
|
|
|
{
|
|
|
|
std::size_t samplesCount;
|
|
|
|
|
|
|
|
if (m_ifstream.eof()) {
|
|
|
|
samplesCount = m_fileSize / sizeof(Real);
|
|
|
|
} else {
|
|
|
|
samplesCount = m_ifstream.tellg() / sizeof(Real);
|
|
|
|
}
|
|
|
|
|
2018-03-29 10:57:42 -04:00
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
MsgReportFileSourceStreamTiming *report;
|
|
|
|
report = MsgReportFileSourceStreamTiming::create(samplesCount);
|
|
|
|
getMessageQueueToGUI()->push(report);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-20 20:02:16 -05:00
|
|
|
else if (CWKeyer::MsgConfigureCWKeyer::match(cmd))
|
|
|
|
{
|
|
|
|
const CWKeyer::MsgConfigureCWKeyer& cfg = (CWKeyer::MsgConfigureCWKeyer&) cmd;
|
|
|
|
|
|
|
|
if (m_settings.m_useReverseAPI) {
|
|
|
|
webapiReverseSendCWSettings(cfg.getSettings());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-29 10:57:42 -04:00
|
|
|
else if (DSPConfigureAudio::match(cmd))
|
|
|
|
{
|
|
|
|
DSPConfigureAudio& cfg = (DSPConfigureAudio&) cmd;
|
|
|
|
uint32_t sampleRate = cfg.getSampleRate();
|
|
|
|
|
|
|
|
qDebug() << "SSBMod::handleMessage: DSPConfigureAudio:"
|
|
|
|
<< " sampleRate: " << sampleRate;
|
|
|
|
|
|
|
|
if (sampleRate != m_audioSampleRate) {
|
|
|
|
applyAudioSampleRate(sampleRate);
|
|
|
|
}
|
2016-12-11 18:48:27 -05:00
|
|
|
|
|
|
|
return true;
|
2018-02-14 14:11:36 -05:00
|
|
|
}
|
|
|
|
else if (DSPSignalNotification::match(cmd))
|
|
|
|
{
|
|
|
|
return true;
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-21 06:17:11 -04:00
|
|
|
void SSBMod::openFileStream()
|
|
|
|
{
|
|
|
|
if (m_ifstream.is_open()) {
|
|
|
|
m_ifstream.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ifstream.open(m_fileName.toStdString().c_str(), std::ios::binary | std::ios::ate);
|
|
|
|
m_fileSize = m_ifstream.tellg();
|
|
|
|
m_ifstream.seekg(0,std::ios_base::beg);
|
|
|
|
|
|
|
|
m_sampleRate = 48000; // fixed rate
|
|
|
|
m_recordLength = m_fileSize / (sizeof(Real) * m_sampleRate);
|
|
|
|
|
|
|
|
qDebug() << "SSBMod::openFileStream: " << m_fileName.toStdString().c_str()
|
|
|
|
<< " fileSize: " << m_fileSize << "bytes"
|
|
|
|
<< " length: " << m_recordLength << " seconds";
|
|
|
|
|
2018-03-29 10:57:42 -04:00
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
MsgReportFileSourceStreamData *report;
|
|
|
|
report = MsgReportFileSourceStreamData::create(m_sampleRate, m_recordLength);
|
|
|
|
getMessageQueueToGUI()->push(report);
|
|
|
|
}
|
2017-10-21 06:17:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SSBMod::seekFileStream(int seekPercentage)
|
|
|
|
{
|
|
|
|
QMutexLocker mutexLocker(&m_settingsMutex);
|
|
|
|
|
|
|
|
if (m_ifstream.is_open())
|
|
|
|
{
|
|
|
|
int seekPoint = ((m_recordLength * seekPercentage) / 100) * m_sampleRate;
|
|
|
|
seekPoint *= sizeof(Real);
|
|
|
|
m_ifstream.clear();
|
|
|
|
m_ifstream.seekg(seekPoint, std::ios::beg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-29 10:57:42 -04:00
|
|
|
void SSBMod::applyAudioSampleRate(int sampleRate)
|
|
|
|
{
|
|
|
|
qDebug("SSBMod::applyAudioSampleRate: %d", sampleRate);
|
|
|
|
|
|
|
|
|
|
|
|
MsgConfigureChannelizer* channelConfigMsg = MsgConfigureChannelizer::create(
|
|
|
|
sampleRate, m_settings.m_inputFrequencyOffset);
|
|
|
|
m_inputMessageQueue.push(channelConfigMsg);
|
|
|
|
|
|
|
|
m_settingsMutex.lock();
|
|
|
|
|
|
|
|
m_interpolatorDistanceRemain = 0;
|
|
|
|
m_interpolatorConsumed = false;
|
|
|
|
m_interpolatorDistance = (Real) sampleRate / (Real) m_outputSampleRate;
|
|
|
|
m_interpolator.create(48, sampleRate, m_settings.m_bandwidth, 3.0);
|
|
|
|
|
|
|
|
float band = m_settings.m_bandwidth;
|
|
|
|
float lowCutoff = m_settings.m_lowCutoff;
|
|
|
|
bool usb = m_settings.m_usb;
|
|
|
|
|
|
|
|
if (band < 100.0f) // at least 100 Hz
|
|
|
|
{
|
|
|
|
band = 100.0f;
|
|
|
|
lowCutoff = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (band - lowCutoff < 100.0f) {
|
|
|
|
lowCutoff = band - 100.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_SSBFilter->create_filter(lowCutoff / sampleRate, band / sampleRate);
|
|
|
|
m_DSBFilter->create_dsb_filter((2.0f * band) / sampleRate);
|
|
|
|
|
|
|
|
m_settings.m_bandwidth = band;
|
|
|
|
m_settings.m_lowCutoff = lowCutoff;
|
|
|
|
m_settings.m_usb = usb;
|
|
|
|
|
|
|
|
m_toneNco.setFreq(m_settings.m_toneFrequency, sampleRate);
|
|
|
|
m_cwKeyer.setSampleRate(sampleRate);
|
|
|
|
|
2019-07-18 16:07:45 -04:00
|
|
|
m_audioCompressor.m_rate = sampleRate;
|
|
|
|
m_audioCompressor.initState();
|
|
|
|
|
2018-03-29 10:57:42 -04:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
|
|
|
|
m_audioSampleRate = sampleRate;
|
|
|
|
|
|
|
|
if (getMessageQueueToGUI())
|
|
|
|
{
|
|
|
|
DSPConfigureAudio *cfg = new DSPConfigureAudio(m_audioSampleRate);
|
|
|
|
getMessageQueueToGUI()->push(cfg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-08 19:10:49 -05:00
|
|
|
void SSBMod::applyChannelSettings(int basebandSampleRate, int outputSampleRate, int inputFrequencyOffset, bool force)
|
2016-12-11 18:48:27 -05:00
|
|
|
{
|
2017-12-29 18:18:51 -05:00
|
|
|
qDebug() << "SSBMod::applyChannelSettings:"
|
|
|
|
<< " basebandSampleRate: " << basebandSampleRate
|
|
|
|
<< " outputSampleRate: " << outputSampleRate
|
|
|
|
<< " inputFrequencyOffset: " << inputFrequencyOffset;
|
|
|
|
|
|
|
|
if ((inputFrequencyOffset != m_inputFrequencyOffset) ||
|
2018-01-08 19:10:49 -05:00
|
|
|
(outputSampleRate != m_outputSampleRate) || force)
|
2016-12-12 18:43:59 -05:00
|
|
|
{
|
2016-12-13 19:16:23 -05:00
|
|
|
m_settingsMutex.lock();
|
2017-12-29 18:18:51 -05:00
|
|
|
m_carrierNco.setFreq(inputFrequencyOffset, outputSampleRate);
|
2016-12-13 19:16:23 -05:00
|
|
|
m_settingsMutex.unlock();
|
2016-12-12 18:43:59 -05:00
|
|
|
}
|
2016-12-11 18:48:27 -05:00
|
|
|
|
2018-01-08 19:10:49 -05:00
|
|
|
if ((outputSampleRate != m_outputSampleRate) || force)
|
2017-10-21 06:17:11 -04:00
|
|
|
{
|
2016-12-11 18:48:27 -05:00
|
|
|
m_settingsMutex.lock();
|
2017-12-29 18:18:51 -05:00
|
|
|
m_interpolatorDistanceRemain = 0;
|
|
|
|
m_interpolatorConsumed = false;
|
2018-03-29 10:57:42 -04:00
|
|
|
m_interpolatorDistance = (Real) m_audioSampleRate / (Real) outputSampleRate;
|
|
|
|
m_interpolator.create(48, m_audioSampleRate, m_settings.m_bandwidth, 3.0);
|
2016-12-11 18:48:27 -05:00
|
|
|
m_settingsMutex.unlock();
|
2017-10-21 06:17:11 -04:00
|
|
|
}
|
2016-12-11 18:48:27 -05:00
|
|
|
|
2017-12-29 18:18:51 -05:00
|
|
|
m_basebandSampleRate = basebandSampleRate;
|
|
|
|
m_outputSampleRate = outputSampleRate;
|
|
|
|
m_inputFrequencyOffset = inputFrequencyOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSBMod::applySettings(const SSBModSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
float band = settings.m_bandwidth;
|
|
|
|
float lowCutoff = settings.m_lowCutoff;
|
|
|
|
bool usb = settings.m_usb;
|
2018-12-20 20:02:16 -05:00
|
|
|
QList<QString> reverseAPIKeys;
|
|
|
|
|
|
|
|
if ((settings.m_inputFrequencyOffset != m_settings.m_inputFrequencyOffset) || force) {
|
|
|
|
reverseAPIKeys.append("inputFrequencyOffset");
|
|
|
|
}
|
|
|
|
if ((settings.m_bandwidth != m_settings.m_bandwidth) || force) {
|
|
|
|
reverseAPIKeys.append("bandwidth");
|
|
|
|
}
|
|
|
|
if ((settings.m_lowCutoff != m_settings.m_lowCutoff) || force) {
|
|
|
|
reverseAPIKeys.append("lowCutoff");
|
|
|
|
}
|
|
|
|
if ((settings.m_usb != m_settings.m_usb) || force) {
|
|
|
|
reverseAPIKeys.append("usb");
|
|
|
|
}
|
|
|
|
if ((settings.m_toneFrequency != m_settings.m_toneFrequency) || force) {
|
|
|
|
reverseAPIKeys.append("toneFrequency");
|
|
|
|
}
|
|
|
|
if ((settings.m_volumeFactor != m_settings.m_volumeFactor) || force) {
|
|
|
|
reverseAPIKeys.append("volumeFactor");
|
|
|
|
}
|
|
|
|
if ((settings.m_spanLog2 != m_settings.m_spanLog2) || force) {
|
|
|
|
reverseAPIKeys.append("spanLog2");
|
|
|
|
}
|
|
|
|
if ((settings.m_audioBinaural != m_settings.m_audioBinaural) || force) {
|
|
|
|
reverseAPIKeys.append("audioBinaural");
|
|
|
|
}
|
|
|
|
if ((settings.m_audioFlipChannels != m_settings.m_audioFlipChannels) || force) {
|
|
|
|
reverseAPIKeys.append("audioFlipChannels");
|
|
|
|
}
|
|
|
|
if ((settings.m_dsb != m_settings.m_dsb) || force) {
|
|
|
|
reverseAPIKeys.append("dsb");
|
|
|
|
}
|
|
|
|
if ((settings.m_audioMute != m_settings.m_audioMute) || force) {
|
|
|
|
reverseAPIKeys.append("audioMute");
|
|
|
|
}
|
|
|
|
if ((settings.m_playLoop != m_settings.m_playLoop) || force) {
|
|
|
|
reverseAPIKeys.append("playLoop");
|
|
|
|
}
|
|
|
|
if ((settings.m_agc != m_settings.m_agc) || force) {
|
|
|
|
reverseAPIKeys.append("agc");
|
|
|
|
}
|
|
|
|
if ((settings.m_rgbColor != m_settings.m_rgbColor) || force) {
|
|
|
|
reverseAPIKeys.append("rgbColor");
|
|
|
|
}
|
|
|
|
if ((settings.m_title != m_settings.m_title) || force) {
|
|
|
|
reverseAPIKeys.append("title");
|
|
|
|
}
|
|
|
|
if ((settings.m_modAFInput != m_settings.m_modAFInput) || force) {
|
|
|
|
reverseAPIKeys.append("modAFInput");
|
|
|
|
}
|
|
|
|
if ((settings.m_audioDeviceName != m_settings.m_audioDeviceName) || force) {
|
|
|
|
reverseAPIKeys.append("audioDeviceName");
|
|
|
|
}
|
2017-12-29 18:18:51 -05:00
|
|
|
|
|
|
|
if ((settings.m_bandwidth != m_settings.m_bandwidth) ||
|
2018-03-29 10:57:42 -04:00
|
|
|
(settings.m_lowCutoff != m_settings.m_lowCutoff) || force)
|
2017-10-21 06:17:11 -04:00
|
|
|
{
|
2017-12-29 18:18:51 -05:00
|
|
|
if (band < 100.0f) // at least 100 Hz
|
|
|
|
{
|
|
|
|
band = 100.0f;
|
|
|
|
lowCutoff = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (band - lowCutoff < 100.0f) {
|
|
|
|
lowCutoff = band - 100.0f;
|
|
|
|
}
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
m_settingsMutex.lock();
|
2017-10-21 06:17:11 -04:00
|
|
|
m_interpolatorDistanceRemain = 0;
|
|
|
|
m_interpolatorConsumed = false;
|
2018-03-29 10:57:42 -04:00
|
|
|
m_interpolatorDistance = (Real) m_audioSampleRate / (Real) m_outputSampleRate;
|
|
|
|
m_interpolator.create(48, m_audioSampleRate, band, 3.0);
|
|
|
|
m_SSBFilter->create_filter(lowCutoff / m_audioSampleRate, band / m_audioSampleRate);
|
|
|
|
m_DSBFilter->create_dsb_filter((2.0f * band) / m_audioSampleRate);
|
2016-12-14 13:08:05 -05:00
|
|
|
m_settingsMutex.unlock();
|
2017-10-21 06:17:11 -04:00
|
|
|
}
|
2016-12-13 13:57:07 -05:00
|
|
|
|
2018-03-29 10:57:42 -04:00
|
|
|
if ((settings.m_toneFrequency != m_settings.m_toneFrequency) || force)
|
2017-08-05 13:08:33 -04:00
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
m_settingsMutex.lock();
|
2018-03-29 10:57:42 -04:00
|
|
|
m_toneNco.setFreq(settings.m_toneFrequency, m_audioSampleRate);
|
2017-10-21 06:17:11 -04:00
|
|
|
m_settingsMutex.unlock();
|
2017-08-05 13:08:33 -04:00
|
|
|
}
|
|
|
|
|
2017-10-21 06:17:11 -04:00
|
|
|
if ((settings.m_dsb != m_settings.m_dsb) || force)
|
2017-08-05 13:08:33 -04:00
|
|
|
{
|
2017-10-21 06:17:11 -04:00
|
|
|
if (settings.m_dsb)
|
|
|
|
{
|
2018-09-02 13:49:53 -04:00
|
|
|
std::fill(m_DSBFilterBuffer, m_DSBFilterBuffer+m_ssbFftLen, Complex{0,0});
|
|
|
|
//memset(m_DSBFilterBuffer, 0, sizeof(Complex)*(m_ssbFftLen));
|
2017-10-21 06:17:11 -04:00
|
|
|
m_DSBFilterBufferIndex = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-02 13:49:53 -04:00
|
|
|
std::fill(m_SSBFilterBuffer, m_SSBFilterBuffer+(m_ssbFftLen>>1), Complex{0,0});
|
|
|
|
//memset(m_SSBFilterBuffer, 0, sizeof(Complex)*(m_ssbFftLen>>1));
|
2017-10-21 06:17:11 -04:00
|
|
|
m_SSBFilterBufferIndex = 0;
|
|
|
|
}
|
2017-08-05 13:08:33 -04:00
|
|
|
}
|
|
|
|
|
2018-03-29 10:57:42 -04:00
|
|
|
if ((settings.m_audioDeviceName != m_settings.m_audioDeviceName) || force)
|
|
|
|
{
|
|
|
|
AudioDeviceManager *audioDeviceManager = DSPEngine::instance()->getAudioDeviceManager();
|
|
|
|
int audioDeviceIndex = audioDeviceManager->getInputDeviceIndex(settings.m_audioDeviceName);
|
|
|
|
audioDeviceManager->addAudioSource(&m_audioFifo, getInputMessageQueue(), audioDeviceIndex);
|
|
|
|
uint32_t audioSampleRate = audioDeviceManager->getInputSampleRate(audioDeviceIndex);
|
|
|
|
|
|
|
|
if (m_audioSampleRate != audioSampleRate) {
|
|
|
|
applyAudioSampleRate(audioSampleRate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 20:02:16 -05:00
|
|
|
if (settings.m_useReverseAPI)
|
|
|
|
{
|
|
|
|
bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
|
|
|
|
(m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) ||
|
|
|
|
(m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) ||
|
|
|
|
(m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex) ||
|
|
|
|
(m_settings.m_reverseAPIChannelIndex != settings.m_reverseAPIChannelIndex);
|
|
|
|
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
|
|
|
|
}
|
|
|
|
|
2017-10-21 06:17:11 -04:00
|
|
|
m_settings = settings;
|
2017-12-29 18:18:51 -05:00
|
|
|
m_settings.m_bandwidth = band;
|
|
|
|
m_settings.m_lowCutoff = lowCutoff;
|
|
|
|
m_settings.m_usb = usb;
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
2017-12-17 17:15:42 -05:00
|
|
|
|
|
|
|
QByteArray SSBMod::serialize() const
|
|
|
|
{
|
|
|
|
return m_settings.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SSBMod::deserialize(const QByteArray& data)
|
|
|
|
{
|
|
|
|
if (m_settings.deserialize(data))
|
|
|
|
{
|
|
|
|
MsgConfigureSSBMod *msg = MsgConfigureSSBMod::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings.resetToDefaults();
|
|
|
|
MsgConfigureSSBMod *msg = MsgConfigureSSBMod::create(m_settings, true);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-04-14 15:46:53 -04:00
|
|
|
|
|
|
|
int SSBMod::webapiSettingsGet(
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
2018-11-12 18:45:03 -05:00
|
|
|
QString& errorMessage)
|
2018-04-14 15:46:53 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) errorMessage;
|
2018-04-14 15:46:53 -04:00
|
|
|
response.setSsbModSettings(new SWGSDRangel::SWGSSBModSettings());
|
|
|
|
response.getSsbModSettings()->init();
|
|
|
|
webapiFormatChannelSettings(response, m_settings);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SSBMod::webapiSettingsPutPatch(
|
|
|
|
bool force,
|
|
|
|
const QStringList& channelSettingsKeys,
|
|
|
|
SWGSDRangel::SWGChannelSettings& response,
|
2018-11-12 18:45:03 -05:00
|
|
|
QString& errorMessage)
|
2018-04-14 15:46:53 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) errorMessage;
|
2018-08-08 03:17:25 -04:00
|
|
|
SSBModSettings settings = m_settings;
|
2018-04-14 15:46:53 -04:00
|
|
|
bool frequencyOffsetChanged = false;
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("inputFrequencyOffset"))
|
|
|
|
{
|
|
|
|
settings.m_inputFrequencyOffset = response.getSsbModSettings()->getInputFrequencyOffset();
|
|
|
|
frequencyOffsetChanged = true;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("bandwidth")) {
|
|
|
|
settings.m_bandwidth = response.getSsbModSettings()->getBandwidth();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("lowCutoff")) {
|
|
|
|
settings.m_lowCutoff = response.getSsbModSettings()->getLowCutoff();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("usb")) {
|
|
|
|
settings.m_usb = response.getSsbModSettings()->getUsb() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("toneFrequency")) {
|
|
|
|
settings.m_toneFrequency = response.getSsbModSettings()->getToneFrequency();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("volumeFactor")) {
|
|
|
|
settings.m_volumeFactor = response.getSsbModSettings()->getVolumeFactor();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("spanLog2")) {
|
|
|
|
settings.m_spanLog2 = response.getSsbModSettings()->getSpanLog2();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioBinaural")) {
|
|
|
|
settings.m_audioBinaural = response.getSsbModSettings()->getAudioBinaural() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioFlipChannels")) {
|
|
|
|
settings.m_audioFlipChannels = response.getSsbModSettings()->getAudioFlipChannels() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("dsb")) {
|
|
|
|
settings.m_dsb = response.getSsbModSettings()->getDsb() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioMute")) {
|
|
|
|
settings.m_audioMute = response.getSsbModSettings()->getAudioMute() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("playLoop")) {
|
|
|
|
settings.m_playLoop = response.getSsbModSettings()->getPlayLoop() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("agc")) {
|
|
|
|
settings.m_agc = response.getSsbModSettings()->getAgc() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rgbColor")) {
|
|
|
|
settings.m_rgbColor = response.getSsbModSettings()->getRgbColor();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("title")) {
|
|
|
|
settings.m_title = *response.getSsbModSettings()->getTitle();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("modAFInput")) {
|
|
|
|
settings.m_modAFInput = (SSBModSettings::SSBModInputAF) response.getSsbModSettings()->getModAfInput();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioDeviceName")) {
|
|
|
|
settings.m_audioDeviceName = *response.getSsbModSettings()->getAudioDeviceName();
|
|
|
|
}
|
2018-12-20 20:02:16 -05:00
|
|
|
if (channelSettingsKeys.contains("useReverseAPI")) {
|
|
|
|
settings.m_useReverseAPI = response.getSsbModSettings()->getUseReverseApi() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIAddress")) {
|
2019-04-20 13:53:16 -04:00
|
|
|
settings.m_reverseAPIAddress = *response.getSsbModSettings()->getReverseApiAddress();
|
2018-12-20 20:02:16 -05:00
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIPort")) {
|
|
|
|
settings.m_reverseAPIPort = response.getSsbModSettings()->getReverseApiPort();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIDeviceIndex")) {
|
|
|
|
settings.m_reverseAPIDeviceIndex = response.getSsbModSettings()->getReverseApiDeviceIndex();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("reverseAPIChannelIndex")) {
|
|
|
|
settings.m_reverseAPIChannelIndex = response.getSsbModSettings()->getReverseApiChannelIndex();
|
|
|
|
}
|
2018-04-14 15:46:53 -04:00
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("cwKeyer"))
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getSsbModSettings()->getCwKeyer();
|
|
|
|
CWKeyerSettings cwKeyerSettings = m_cwKeyer.getSettings();
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("cwKeyer.loop")) {
|
|
|
|
cwKeyerSettings.m_loop = apiCwKeyerSettings->getLoop() != 0;
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("cwKeyer.mode")) {
|
|
|
|
cwKeyerSettings.m_mode = (CWKeyerSettings::CWMode) apiCwKeyerSettings->getMode();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("cwKeyer.text")) {
|
|
|
|
cwKeyerSettings.m_text = *apiCwKeyerSettings->getText();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("cwKeyer.sampleRate")) {
|
|
|
|
cwKeyerSettings.m_sampleRate = apiCwKeyerSettings->getSampleRate();
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("cwKeyer.wpm")) {
|
|
|
|
cwKeyerSettings.m_wpm = apiCwKeyerSettings->getWpm();
|
|
|
|
}
|
|
|
|
|
2019-07-29 19:31:46 -04:00
|
|
|
CWKeyer::MsgConfigureCWKeyer *msgCwKeyer = CWKeyer::MsgConfigureCWKeyer::create(cwKeyerSettings, force);
|
|
|
|
m_cwKeyer.getInputMessageQueue()->push(msgCwKeyer);
|
2018-04-14 15:46:53 -04:00
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
2019-07-29 19:31:46 -04:00
|
|
|
CWKeyer::MsgConfigureCWKeyer *msgCwKeyerToGUI = CWKeyer::MsgConfigureCWKeyer::create(cwKeyerSettings, force);
|
|
|
|
m_guiMessageQueue->push(msgCwKeyerToGUI);
|
2018-04-14 15:46:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frequencyOffsetChanged)
|
|
|
|
{
|
|
|
|
SSBMod::MsgConfigureChannelizer *msgChan = SSBMod::MsgConfigureChannelizer::create(
|
|
|
|
m_audioSampleRate, settings.m_inputFrequencyOffset);
|
|
|
|
m_inputMessageQueue.push(msgChan);
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgConfigureSSBMod *msg = MsgConfigureSSBMod::create(settings, force);
|
|
|
|
m_inputMessageQueue.push(msg);
|
|
|
|
|
|
|
|
if (m_guiMessageQueue) // forward to GUI if any
|
|
|
|
{
|
|
|
|
MsgConfigureSSBMod *msgToGUI = MsgConfigureSSBMod::create(settings, force);
|
|
|
|
m_guiMessageQueue->push(msgToGUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
webapiFormatChannelSettings(response, settings);
|
|
|
|
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SSBMod::webapiReportGet(
|
|
|
|
SWGSDRangel::SWGChannelReport& response,
|
2018-11-12 18:45:03 -05:00
|
|
|
QString& errorMessage)
|
2018-04-14 15:46:53 -04:00
|
|
|
{
|
2018-11-12 18:45:03 -05:00
|
|
|
(void) errorMessage;
|
2018-04-14 15:46:53 -04:00
|
|
|
response.setSsbModReport(new SWGSDRangel::SWGSSBModReport());
|
|
|
|
response.getSsbModReport()->init();
|
|
|
|
webapiFormatChannelReport(response);
|
|
|
|
return 200;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSBMod::webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings& response, const SSBModSettings& settings)
|
|
|
|
{
|
|
|
|
response.getSsbModSettings()->setInputFrequencyOffset(settings.m_inputFrequencyOffset);
|
|
|
|
response.getSsbModSettings()->setBandwidth(settings.m_bandwidth);
|
|
|
|
response.getSsbModSettings()->setLowCutoff(settings.m_lowCutoff);
|
|
|
|
response.getSsbModSettings()->setUsb(settings.m_usb ? 1 : 0);
|
|
|
|
response.getSsbModSettings()->setToneFrequency(settings.m_toneFrequency);
|
|
|
|
response.getSsbModSettings()->setVolumeFactor(settings.m_volumeFactor);
|
|
|
|
response.getSsbModSettings()->setSpanLog2(settings.m_spanLog2);
|
|
|
|
response.getSsbModSettings()->setAudioBinaural(settings.m_audioBinaural ? 1 : 0);
|
|
|
|
response.getSsbModSettings()->setAudioFlipChannels(settings.m_audioFlipChannels ? 1 : 0);
|
|
|
|
response.getSsbModSettings()->setDsb(settings.m_dsb ? 1 : 0);
|
|
|
|
response.getSsbModSettings()->setAudioMute(settings.m_audioMute ? 1 : 0);
|
|
|
|
response.getSsbModSettings()->setPlayLoop(settings.m_playLoop ? 1 : 0);
|
|
|
|
response.getSsbModSettings()->setAgc(settings.m_agc ? 1 : 0);
|
|
|
|
response.getSsbModSettings()->setRgbColor(settings.m_rgbColor);
|
|
|
|
|
|
|
|
if (response.getSsbModSettings()->getTitle()) {
|
|
|
|
*response.getSsbModSettings()->getTitle() = settings.m_title;
|
|
|
|
} else {
|
|
|
|
response.getSsbModSettings()->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
|
|
|
|
response.getSsbModSettings()->setModAfInput((int) settings.m_modAFInput);
|
|
|
|
|
|
|
|
if (response.getSsbModSettings()->getAudioDeviceName()) {
|
|
|
|
*response.getSsbModSettings()->getAudioDeviceName() = settings.m_audioDeviceName;
|
|
|
|
} else {
|
|
|
|
response.getSsbModSettings()->setAudioDeviceName(new QString(settings.m_audioDeviceName));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!response.getSsbModSettings()->getCwKeyer()) {
|
|
|
|
response.getSsbModSettings()->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = response.getSsbModSettings()->getCwKeyer();
|
|
|
|
const CWKeyerSettings& cwKeyerSettings = m_cwKeyer.getSettings();
|
|
|
|
apiCwKeyerSettings->setLoop(cwKeyerSettings.m_loop ? 1 : 0);
|
|
|
|
apiCwKeyerSettings->setMode((int) cwKeyerSettings.m_mode);
|
|
|
|
apiCwKeyerSettings->setSampleRate(cwKeyerSettings.m_sampleRate);
|
|
|
|
|
|
|
|
if (apiCwKeyerSettings->getText()) {
|
|
|
|
*apiCwKeyerSettings->getText() = cwKeyerSettings.m_text;
|
|
|
|
} else {
|
|
|
|
apiCwKeyerSettings->setText(new QString(cwKeyerSettings.m_text));
|
|
|
|
}
|
|
|
|
|
|
|
|
apiCwKeyerSettings->setWpm(cwKeyerSettings.m_wpm);
|
2018-12-20 20:02:16 -05:00
|
|
|
|
2019-02-24 08:57:06 -05:00
|
|
|
response.getSsbModSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
|
2018-12-20 20:02:16 -05:00
|
|
|
|
2019-02-24 08:57:06 -05:00
|
|
|
if (response.getSsbModSettings()->getReverseApiAddress()) {
|
|
|
|
*response.getSsbModSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
|
2018-12-20 20:02:16 -05:00
|
|
|
} else {
|
2019-02-24 08:57:06 -05:00
|
|
|
response.getSsbModSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
|
2018-12-20 20:02:16 -05:00
|
|
|
}
|
|
|
|
|
2019-02-24 08:57:06 -05:00
|
|
|
response.getSsbModSettings()->setReverseApiPort(settings.m_reverseAPIPort);
|
|
|
|
response.getSsbModSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
|
|
|
response.getSsbModSettings()->setReverseApiChannelIndex(settings.m_reverseAPIChannelIndex);
|
2018-04-14 15:46:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SSBMod::webapiFormatChannelReport(SWGSDRangel::SWGChannelReport& response)
|
|
|
|
{
|
|
|
|
response.getSsbModReport()->setChannelPowerDb(CalcDb::dbPower(getMagSq()));
|
|
|
|
response.getSsbModReport()->setAudioSampleRate(m_audioSampleRate);
|
|
|
|
response.getSsbModReport()->setChannelSampleRate(m_outputSampleRate);
|
|
|
|
}
|
|
|
|
|
2018-12-20 20:02:16 -05:00
|
|
|
void SSBMod::webapiReverseSendSettings(QList<QString>& channelSettingsKeys, const SSBModSettings& settings, bool force)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings();
|
2019-05-07 08:43:38 -04:00
|
|
|
swgChannelSettings->setDirection(1); // single source (Tx)
|
2019-03-25 08:57:59 -04:00
|
|
|
swgChannelSettings->setOriginatorChannelIndex(getIndexInDeviceSet());
|
|
|
|
swgChannelSettings->setOriginatorDeviceSetIndex(getDeviceSetIndex());
|
2018-12-20 20:02:16 -05:00
|
|
|
swgChannelSettings->setChannelType(new QString("SSBMod"));
|
|
|
|
swgChannelSettings->setSsbModSettings(new SWGSDRangel::SWGSSBModSettings());
|
|
|
|
SWGSDRangel::SWGSSBModSettings *swgSSBModSettings = swgChannelSettings->getSsbModSettings();
|
|
|
|
|
|
|
|
// transfer data that has been modified. When force is on transfer all data except reverse API data
|
|
|
|
|
|
|
|
if (channelSettingsKeys.contains("inputFrequencyOffset") || force) {
|
|
|
|
swgSSBModSettings->setInputFrequencyOffset(settings.m_inputFrequencyOffset);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("bandwidth") || force) {
|
|
|
|
swgSSBModSettings->setBandwidth(settings.m_bandwidth);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("lowCutoff") || force) {
|
|
|
|
swgSSBModSettings->setLowCutoff(settings.m_lowCutoff);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("usb") || force) {
|
|
|
|
swgSSBModSettings->setUsb(settings.m_usb ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("toneFrequency") || force) {
|
|
|
|
swgSSBModSettings->setToneFrequency(settings.m_toneFrequency);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("volumeFactor") || force) {
|
|
|
|
swgSSBModSettings->setVolumeFactor(settings.m_volumeFactor);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("spanLog2") || force) {
|
|
|
|
swgSSBModSettings->setSpanLog2(settings.m_spanLog2);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioBinaural") || force) {
|
|
|
|
swgSSBModSettings->setAudioBinaural(settings.m_audioBinaural ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioFlipChannels") || force) {
|
|
|
|
swgSSBModSettings->setAudioFlipChannels(settings.m_audioFlipChannels ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("dsb") || force) {
|
|
|
|
swgSSBModSettings->setDsb(settings.m_dsb ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioMute") || force) {
|
|
|
|
swgSSBModSettings->setAudioMute(settings.m_audioMute ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("playLoop") || force) {
|
|
|
|
swgSSBModSettings->setPlayLoop(settings.m_playLoop ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("agc") || force) {
|
|
|
|
swgSSBModSettings->setAgc(settings.m_agc ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("rgbColor") || force) {
|
|
|
|
swgSSBModSettings->setRgbColor(settings.m_rgbColor);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("title") || force) {
|
|
|
|
swgSSBModSettings->setTitle(new QString(settings.m_title));
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("modAFInput") || force) {
|
|
|
|
swgSSBModSettings->setModAfInput((int) settings.m_modAFInput);
|
|
|
|
}
|
|
|
|
if (channelSettingsKeys.contains("audioDeviceName") || force) {
|
|
|
|
swgSSBModSettings->setAudioDeviceName(new QString(settings.m_audioDeviceName));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (force)
|
|
|
|
{
|
|
|
|
const CWKeyerSettings& cwKeyerSettings = m_cwKeyer.getSettings();
|
|
|
|
swgSSBModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings());
|
|
|
|
SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgSSBModSettings->getCwKeyer();
|
|
|
|
apiCwKeyerSettings->setLoop(cwKeyerSettings.m_loop ? 1 : 0);
|
|
|
|
apiCwKeyerSettings->setMode(cwKeyerSettings.m_mode);
|
|
|
|
apiCwKeyerSettings->setSampleRate(cwKeyerSettings.m_sampleRate);
|
|
|
|
apiCwKeyerSettings->setText(new QString(cwKeyerSettings.m_text));
|
|
|
|
apiCwKeyerSettings->setWpm(cwKeyerSettings.m_wpm);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings")
|
|
|
|
.arg(settings.m_reverseAPIAddress)
|
|
|
|
.arg(settings.m_reverseAPIPort)
|
|
|
|
.arg(settings.m_reverseAPIDeviceIndex)
|
|
|
|
.arg(settings.m_reverseAPIChannelIndex);
|
|
|
|
m_networkRequest.setUrl(QUrl(channelSettingsURL));
|
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
|
|
|
|
QBuffer *buffer=new QBuffer();
|
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgChannelSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
|
|
|
|
|
|
|
// Always use PATCH to avoid passing reverse API settings
|
|
|
|
m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
|
|
|
|
|
|
|
|
delete swgChannelSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSBMod::webapiReverseSendCWSettings(const CWKeyerSettings& cwKeyerSettings)
|
|
|
|
{
|
|
|
|
SWGSDRangel::SWGChannelSettings *swgChannelSettings = new SWGSDRangel::SWGChannelSettings();
|
2019-05-07 08:43:38 -04:00
|
|
|
swgChannelSettings->setDirection(1); // single source (Tx)
|
2018-12-21 10:25:22 -05:00
|
|
|
swgChannelSettings->setChannelType(new QString("SSBMod"));
|
2018-12-20 20:02:16 -05:00
|
|
|
swgChannelSettings->setSsbModSettings(new SWGSDRangel::SWGSSBModSettings());
|
|
|
|
SWGSDRangel::SWGSSBModSettings *swgSSBModSettings = swgChannelSettings->getSsbModSettings();
|
|
|
|
|
|
|
|
swgSSBModSettings->setCwKeyer(new SWGSDRangel::SWGCWKeyerSettings());
|
|
|
|
SWGSDRangel::SWGCWKeyerSettings *apiCwKeyerSettings = swgSSBModSettings->getCwKeyer();
|
|
|
|
apiCwKeyerSettings->setLoop(cwKeyerSettings.m_loop ? 1 : 0);
|
|
|
|
apiCwKeyerSettings->setMode(cwKeyerSettings.m_mode);
|
|
|
|
apiCwKeyerSettings->setSampleRate(cwKeyerSettings.m_sampleRate);
|
|
|
|
apiCwKeyerSettings->setText(new QString(cwKeyerSettings.m_text));
|
|
|
|
apiCwKeyerSettings->setWpm(cwKeyerSettings.m_wpm);
|
|
|
|
|
|
|
|
QString channelSettingsURL = QString("http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings")
|
|
|
|
.arg(m_settings.m_reverseAPIAddress)
|
|
|
|
.arg(m_settings.m_reverseAPIPort)
|
|
|
|
.arg(m_settings.m_reverseAPIDeviceIndex)
|
|
|
|
.arg(m_settings.m_reverseAPIChannelIndex);
|
|
|
|
m_networkRequest.setUrl(QUrl(channelSettingsURL));
|
|
|
|
m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
|
|
|
|
|
|
|
QBuffer *buffer=new QBuffer();
|
|
|
|
buffer->open((QBuffer::ReadWrite));
|
|
|
|
buffer->write(swgChannelSettings->asJson().toUtf8());
|
|
|
|
buffer->seek(0);
|
|
|
|
|
|
|
|
// Always use PATCH to avoid passing reverse API settings
|
|
|
|
m_networkManager->sendCustomRequest(m_networkRequest, "PATCH", buffer);
|
|
|
|
|
|
|
|
delete swgChannelSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSBMod::networkManagerFinished(QNetworkReply *reply)
|
|
|
|
{
|
|
|
|
QNetworkReply::NetworkError replyError = reply->error();
|
|
|
|
|
|
|
|
if (replyError)
|
|
|
|
{
|
|
|
|
qWarning() << "SSBMod::networkManagerFinished:"
|
|
|
|
<< " error(" << (int) replyError
|
|
|
|
<< "): " << replyError
|
|
|
|
<< ": " << reply->errorString();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString answer = reply->readAll();
|
|
|
|
answer.chop(1); // remove last \n
|
|
|
|
qDebug("SSBMod::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
|
|
|
|
}
|