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 //
|
|
|
|
// //
|
|
|
|
// 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>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <complex.h>
|
|
|
|
#include <dsp/upchannelizer.h>
|
|
|
|
#include "dsp/dspengine.h"
|
|
|
|
#include "dsp/pidcontroller.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)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgConfigureFileSourceName, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgConfigureFileSourceSeek, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgConfigureAFInput, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgConfigureFileSourceStreamTiming, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgReportFileSourceStreamData, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(SSBMod::MsgReportFileSourceStreamTiming, Message)
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-12-13 18:14:52 -05:00
|
|
|
SSBMod::SSBMod(BasebandSampleSink* sampleSink) :
|
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-05-25 14:13:34 -04:00
|
|
|
m_sampleSink(sampleSink),
|
|
|
|
m_movingAverage(40, 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_afInput(SSBModInputNone),
|
|
|
|
m_levelCalcCount(0),
|
|
|
|
m_peakLevel(0.0f),
|
2017-08-05 13:08:33 -04:00
|
|
|
m_levelSum(0.0f),
|
|
|
|
m_inAGC(9600, 0.2, 1e-4)
|
2016-12-11 18:48:27 -05:00
|
|
|
{
|
|
|
|
setObjectName("SSBMod");
|
|
|
|
|
2016-12-13 17:00:09 -05:00
|
|
|
m_SSBFilter = new fftfilt(m_config.m_lowCutoff / m_config.m_audioSampleRate, m_config.m_bandwidth / m_config.m_audioSampleRate, m_ssbFftLen);
|
|
|
|
m_DSBFilter = new fftfilt((2.0f * m_config.m_bandwidth) / m_config.m_audioSampleRate, 2 * m_ssbFftLen);
|
|
|
|
m_SSBFilterBuffer = new Complex[m_ssbFftLen>>1]; // filter returns data exactly half of its size
|
|
|
|
m_DSBFilterBuffer = new Complex[m_ssbFftLen];
|
|
|
|
memset(m_SSBFilterBuffer, 0, sizeof(Complex)*(m_ssbFftLen>>1));
|
|
|
|
memset(m_DSBFilterBuffer, 0, sizeof(Complex)*(m_ssbFftLen));
|
|
|
|
|
|
|
|
m_config.m_outputSampleRate = 48000;
|
2016-12-11 18:48:27 -05:00
|
|
|
m_config.m_inputFrequencyOffset = 0;
|
2016-12-12 16:02:24 -05:00
|
|
|
m_config.m_bandwidth = 12500;
|
2016-12-11 18:48:27 -05:00
|
|
|
m_config.m_toneFrequency = 1000.0f;
|
|
|
|
m_config.m_audioSampleRate = DSPEngine::instance()->getAudioSampleRate();
|
|
|
|
|
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_magsqSpectrum = 0.0f;
|
|
|
|
// m_magsqSum = 0.0f;
|
|
|
|
// m_magsqPeak = 0.0f;
|
|
|
|
// m_magsqCount = 0;
|
|
|
|
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_movingAverage.resize(16, 0);
|
|
|
|
m_magsq = 0.0;
|
|
|
|
|
|
|
|
m_toneNco.setFreq(1000.0, m_config.m_audioSampleRate);
|
|
|
|
DSPEngine::instance()->addAudioSource(&m_audioFifo);
|
|
|
|
|
|
|
|
// CW keyer
|
|
|
|
m_cwKeyer.setSampleRate(m_config.m_audioSampleRate);
|
|
|
|
m_cwKeyer.setWPM(13);
|
|
|
|
m_cwKeyer.setMode(CWKeyer::CWNone);
|
2016-12-12 18:43:59 -05:00
|
|
|
|
2016-12-15 18:02:37 -05:00
|
|
|
m_cwSmoother.setNbFadeSamples(192); // 4 ms at 48 kHz
|
2017-08-05 13:08:33 -04:00
|
|
|
m_inAGC.setGate(m_config.m_agcThresholdGate);
|
|
|
|
m_inAGC.setStepDownDelay(m_config.m_agcThresholdDelay);
|
|
|
|
m_inAGC.setClamping(true);
|
2016-12-13 17:00:09 -05:00
|
|
|
apply();
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SSBMod::~SSBMod()
|
|
|
|
{
|
2016-12-12 18:43:59 -05:00
|
|
|
if (m_SSBFilter) {
|
|
|
|
delete m_SSBFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_DSBFilter) {
|
|
|
|
delete m_DSBFilter;
|
|
|
|
}
|
|
|
|
|
2016-12-13 13:57:07 -05:00
|
|
|
if (m_SSBFilterBuffer) {
|
|
|
|
delete m_SSBFilterBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_DSBFilterBuffer) {
|
|
|
|
delete m_DSBFilterBuffer;
|
|
|
|
}
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
DSPEngine::instance()->removeAudioSource(&m_audioFifo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSBMod::configure(MessageQueue* messageQueue,
|
2016-12-12 16:02:24 -05:00
|
|
|
Real bandwidth,
|
|
|
|
Real lowCutoff,
|
2016-12-11 18:48:27 -05:00
|
|
|
float toneFrequency,
|
|
|
|
float volumeFactor,
|
2016-12-12 16:02:24 -05:00
|
|
|
int spanLog2,
|
|
|
|
bool audioBinaural,
|
|
|
|
bool audioFlipChannels,
|
|
|
|
bool dsb,
|
2016-12-13 20:57:47 -05:00
|
|
|
bool audioMute,
|
2017-08-05 13:08:33 -04:00
|
|
|
bool playLoop,
|
|
|
|
bool agc,
|
2017-08-05 17:11:05 -04:00
|
|
|
float agcOrder,
|
2017-08-05 13:08:33 -04:00
|
|
|
int agcTime,
|
|
|
|
int agcThreshold,
|
|
|
|
int agcThresholdGate,
|
|
|
|
int agcThresholdDelay)
|
2016-12-11 18:48:27 -05:00
|
|
|
{
|
2016-12-12 16:02:24 -05:00
|
|
|
Message* cmd = MsgConfigureSSBMod::create(bandwidth,
|
|
|
|
lowCutoff,
|
|
|
|
toneFrequency,
|
|
|
|
volumeFactor,
|
|
|
|
spanLog2,
|
|
|
|
audioBinaural,
|
|
|
|
audioFlipChannels,
|
|
|
|
dsb,
|
2016-12-13 20:57:47 -05:00
|
|
|
audioMute,
|
2017-08-05 13:08:33 -04:00
|
|
|
playLoop,
|
|
|
|
agc,
|
2017-08-05 17:11:05 -04:00
|
|
|
agcOrder,
|
2017-08-05 13:08:33 -04:00
|
|
|
agcTime,
|
|
|
|
agcThreshold,
|
|
|
|
agcThresholdGate,
|
|
|
|
agcThresholdDelay);
|
2016-12-11 18:48:27 -05:00
|
|
|
messageQueue->push(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
ci *= 29204.0f; //scaling at -1 dB to account for possible filter overshoot
|
2016-12-11 18:48:27 -05:00
|
|
|
|
|
|
|
m_settingsMutex.unlock();
|
|
|
|
|
|
|
|
Real magsq = ci.real() * ci.real() + ci.imag() * ci.imag();
|
|
|
|
magsq /= (1<<30);
|
|
|
|
m_movingAverage.feed(magsq);
|
|
|
|
m_magsq = m_movingAverage.average();
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2017-08-06 11:10:29 -04:00
|
|
|
unsigned int nbSamplesAudio = nbSamples * ((Real) m_config.m_audioSampleRate / (Real) m_config.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
|
|
|
}
|
|
|
|
|
2016-12-26 05:16:12 -05:00
|
|
|
m_audioFifo.read(reinterpret_cast<quint8*>(&m_audioBuffer[0]), nbSamplesAudio, 10);
|
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
|
|
|
{
|
2016-12-14 07:52:46 -05:00
|
|
|
if (m_running.m_audioMute)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
int decim = 1<<(m_running.m_spanLog2 - 1);
|
|
|
|
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
|
|
|
|
|
|
|
switch (m_afInput)
|
|
|
|
{
|
|
|
|
case SSBModInputTone:
|
2016-12-13 13:57:07 -05:00
|
|
|
if (m_running.m_dsb)
|
|
|
|
{
|
|
|
|
Real t = m_toneNco.next();
|
|
|
|
sample.real(t);
|
|
|
|
sample.imag(t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_running.m_usb) {
|
|
|
|
sample = m_toneNco.nextIQ();
|
|
|
|
} else {
|
|
|
|
sample = m_toneNco.nextQI();
|
|
|
|
}
|
|
|
|
}
|
2016-12-11 18:48:27 -05:00
|
|
|
break;
|
|
|
|
case 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())
|
|
|
|
{
|
|
|
|
if (m_running.m_playLoop)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2016-12-14 07:52:46 -05:00
|
|
|
if (m_running.m_audioBinaural)
|
|
|
|
{
|
|
|
|
Complex c;
|
|
|
|
m_ifstream.read(reinterpret_cast<char*>(&c), sizeof(Complex));
|
|
|
|
|
|
|
|
if (m_running.m_audioFlipChannels)
|
|
|
|
{
|
|
|
|
ci.real(c.imag() * m_running.m_volumeFactor);
|
|
|
|
ci.imag(c.real() * m_running.m_volumeFactor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ci = c * m_running.m_volumeFactor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Real real;
|
|
|
|
m_ifstream.read(reinterpret_cast<char*>(&real), sizeof(Real));
|
2017-08-05 13:08:33 -04:00
|
|
|
|
|
|
|
if (m_running.m_agc)
|
|
|
|
{
|
|
|
|
ci.real(real);
|
|
|
|
ci.imag(0.0f);
|
|
|
|
m_inAGC.feed(ci);
|
|
|
|
ci *= m_running.m_volumeFactor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ci.real(real * m_running.m_volumeFactor);
|
|
|
|
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;
|
|
|
|
case SSBModInputAudio:
|
2016-12-14 07:52:46 -05:00
|
|
|
if (m_running.m_audioBinaural)
|
|
|
|
{
|
|
|
|
if (m_running.m_audioFlipChannels)
|
|
|
|
{
|
2016-12-25 19:39:34 -05:00
|
|
|
ci.real((m_audioBuffer[m_audioBufferFill].r / 32768.0f) * m_running.m_volumeFactor);
|
|
|
|
ci.imag((m_audioBuffer[m_audioBufferFill].l / 32768.0f) * m_running.m_volumeFactor);
|
2016-12-14 07:52:46 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-25 19:39:34 -05:00
|
|
|
ci.real((m_audioBuffer[m_audioBufferFill].l / 32768.0f) * m_running.m_volumeFactor);
|
|
|
|
ci.imag((m_audioBuffer[m_audioBufferFill].r / 32768.0f) * m_running.m_volumeFactor);
|
2016-12-14 07:52:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-05 13:08:33 -04:00
|
|
|
if (m_running.m_agc)
|
|
|
|
{
|
|
|
|
ci.real(((m_audioBuffer[m_audioBufferFill].l + m_audioBuffer[m_audioBufferFill].r) / 65536.0f));
|
|
|
|
ci.imag(0.0f);
|
|
|
|
m_inAGC.feed(ci);
|
|
|
|
ci *= m_running.m_volumeFactor;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ci.real(((m_audioBuffer[m_audioBufferFill].l + m_audioBuffer[m_audioBufferFill].r) / 65536.0f) * m_running.m_volumeFactor);
|
|
|
|
ci.imag(0.0f);
|
|
|
|
}
|
2016-12-14 07:52:46 -05:00
|
|
|
}
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
break;
|
|
|
|
case SSBModInputCWTone:
|
2016-12-14 13:08:05 -05:00
|
|
|
Real fadeFactor;
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
if (m_cwKeyer.getSample())
|
|
|
|
{
|
2016-12-14 16:48:39 -05:00
|
|
|
m_cwSmoother.getFadeSample(true, fadeFactor);
|
2016-12-14 13:08:05 -05:00
|
|
|
|
2016-12-13 13:57:07 -05:00
|
|
|
if (m_running.m_dsb)
|
|
|
|
{
|
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
|
|
|
|
{
|
|
|
|
if (m_running.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
|
|
|
|
{
|
2016-12-14 16:48:39 -05:00
|
|
|
if (m_cwSmoother.getFadeSample(false, fadeFactor))
|
2016-12-14 13:08:05 -05:00
|
|
|
{
|
|
|
|
if (m_running.m_dsb)
|
|
|
|
{
|
|
|
|
Real t = m_toneNco.next() * fadeFactor;
|
|
|
|
sample.real(t);
|
|
|
|
sample.imag(t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_running.m_usb) {
|
|
|
|
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;
|
|
|
|
case SSBModInputNone:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-12-13 13:57:07 -05:00
|
|
|
|
|
|
|
if ((m_afInput == SSBModInputFile) || (m_afInput == SSBModInputAudio)) // real audio
|
|
|
|
{
|
|
|
|
if (m_running.m_dsb)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
n_out = m_SSBFilter->runSSB(ci, &filtered, m_running.m_usb);
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2016-12-13 19:16:23 -05:00
|
|
|
Real avgr = (m_sum.real() / decim) * 29204.0f; //scaling at -1 dB to account for possible filter overshoot
|
|
|
|
Real avgi = (m_sum.imag() / decim) * 29204.0f;
|
2016-12-13 18:14:52 -05:00
|
|
|
// m_magsqSpectrum = (avgr * avgr + avgi * avgi) / (1<<30);
|
|
|
|
//
|
|
|
|
// m_magsqSum += m_magsqSpectrum;
|
|
|
|
//
|
|
|
|
// if (m_magsqSpectrum > m_magsqPeak)
|
|
|
|
// {
|
|
|
|
// m_magsqPeak = m_magsqSpectrum;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// m_magsqCount++;
|
|
|
|
|
|
|
|
if (!m_running.m_dsb & !m_running.m_usb)
|
|
|
|
{ // 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
|
|
|
|
else if ((m_afInput == SSBModInputTone) || (m_afInput == SSBModInputCWTone)) // tone
|
|
|
|
{
|
|
|
|
m_sum += sample;
|
|
|
|
|
|
|
|
if (!(m_undersampleCount++ & decim_mask))
|
|
|
|
{
|
2016-12-13 19:16:23 -05:00
|
|
|
Real avgr = (m_sum.real() / decim) * 29204.0f; //scaling at -1 dB to account for possible filter overshoot
|
|
|
|
Real avgi = (m_sum.imag() / decim) * 29204.0f;
|
2016-12-13 18:14:52 -05:00
|
|
|
// m_magsqSpectrum = (avgr * avgr + avgi * avgi) / (1<<30);
|
|
|
|
//
|
|
|
|
// m_magsqSum += m_magsqSpectrum;
|
|
|
|
//
|
|
|
|
// if (m_magsqSpectrum > m_magsqPeak)
|
|
|
|
// {
|
|
|
|
// m_magsqPeak = m_magsqSpectrum;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// m_magsqCount++;
|
|
|
|
|
|
|
|
if (!m_running.m_dsb & !m_running.m_usb)
|
|
|
|
{ // 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_sumCount < (m_running.m_dsb ? m_ssbFftLen : m_ssbFftLen>>1))
|
|
|
|
{
|
|
|
|
n_out = 0;
|
|
|
|
m_sumCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n_out = m_sumCount;
|
|
|
|
m_sumCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_out > 0)
|
|
|
|
{
|
|
|
|
if (m_sampleSink != 0)
|
|
|
|
{
|
|
|
|
m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), !m_running.m_dsb);
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
qDebug() << "SSBMod::start: m_outputSampleRate: " << m_config.m_outputSampleRate
|
|
|
|
<< " m_inputFrequencyOffset: " << m_config.m_inputFrequencyOffset;
|
|
|
|
|
|
|
|
m_audioFifo.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSBMod::stop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SSBMod::handleMessage(const Message& cmd)
|
|
|
|
{
|
|
|
|
if (UpChannelizer::MsgChannelizerNotification::match(cmd))
|
|
|
|
{
|
|
|
|
UpChannelizer::MsgChannelizerNotification& notif = (UpChannelizer::MsgChannelizerNotification&) cmd;
|
|
|
|
|
2017-08-06 11:10:29 -04:00
|
|
|
m_config.m_basebandSampleRate = notif.getBasebandSampleRate();
|
2016-12-11 18:48:27 -05:00
|
|
|
m_config.m_outputSampleRate = notif.getSampleRate();
|
|
|
|
m_config.m_inputFrequencyOffset = notif.getFrequencyOffset();
|
|
|
|
|
|
|
|
apply();
|
|
|
|
|
|
|
|
qDebug() << "SSBMod::handleMessage: MsgChannelizerNotification:"
|
2017-08-06 11:10:29 -04:00
|
|
|
<< " m_basebandSampleRate: " << m_config.m_basebandSampleRate
|
|
|
|
<< " m_outputSampleRate: " << m_config.m_outputSampleRate
|
2016-12-11 18:48:27 -05:00
|
|
|
<< " m_inputFrequencyOffset: " << m_config.m_inputFrequencyOffset;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (MsgConfigureSSBMod::match(cmd))
|
|
|
|
{
|
2016-12-12 16:02:24 -05:00
|
|
|
float band, lowCutoff;
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
MsgConfigureSSBMod& cfg = (MsgConfigureSSBMod&) cmd;
|
2016-12-12 16:02:24 -05:00
|
|
|
m_settingsMutex.lock();
|
|
|
|
|
|
|
|
band = cfg.getBandwidth();
|
2016-12-12 18:43:59 -05:00
|
|
|
lowCutoff = cfg.getLowCutoff();
|
2016-12-12 16:02:24 -05:00
|
|
|
|
|
|
|
if (band < 0) // negative means LSB
|
|
|
|
{
|
|
|
|
band = -band; // turn to positive
|
|
|
|
lowCutoff = -lowCutoff;
|
|
|
|
m_config.m_usb = false; // and take note of side band
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_config.m_usb = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (band < 100.0f) // at least 100 Hz
|
|
|
|
{
|
|
|
|
band = 100.0f;
|
|
|
|
lowCutoff = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_config.m_bandwidth = band;
|
|
|
|
m_config.m_lowCutoff = lowCutoff;
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
m_config.m_toneFrequency = cfg.getToneFrequency();
|
|
|
|
m_config.m_volumeFactor = cfg.getVolumeFactor();
|
2016-12-12 16:02:24 -05:00
|
|
|
m_config.m_spanLog2 = cfg.getSpanLog2();
|
|
|
|
m_config.m_audioBinaural = cfg.getAudioBinaural();
|
|
|
|
m_config.m_audioFlipChannels = cfg.getAudioFlipChannels();
|
|
|
|
m_config.m_dsb = cfg.getDSB();
|
2016-12-11 18:48:27 -05:00
|
|
|
m_config.m_audioMute = cfg.getAudioMute();
|
2016-12-13 20:57:47 -05:00
|
|
|
m_config.m_playLoop = cfg.getPlayLoop();
|
2017-08-05 13:08:33 -04:00
|
|
|
m_config.m_agc = cfg.getAGC();
|
|
|
|
|
|
|
|
m_config.m_agcTime = 48 * cfg.getAGCTime(); // ms
|
2017-08-05 17:11:05 -04:00
|
|
|
m_config.m_agcOrder = cfg.getAGCOrder();
|
2017-08-05 13:08:33 -04:00
|
|
|
m_config.m_agcThresholdEnable = cfg.getAGCThreshold() != -99;
|
|
|
|
m_config.m_agcThreshold = CalcDb::powerFromdB(cfg.getAGCThreshold()); // power dB
|
|
|
|
m_config.m_agcThresholdGate = 48 * cfg.getAGCThresholdGate(); // ms
|
|
|
|
m_config.m_agcThresholdDelay = 48 * cfg.getAGCThresholdDelay(); // ms
|
2016-12-11 18:48:27 -05:00
|
|
|
|
|
|
|
apply();
|
|
|
|
|
2016-12-12 16:02:24 -05:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
qDebug() << "SSBMod::handleMessage: MsgConfigureSSBMod:"
|
2016-12-12 16:02:24 -05:00
|
|
|
<< " m_bandwidth: " << m_config.m_bandwidth
|
|
|
|
<< " m_lowCutoff: " << m_config.m_lowCutoff
|
2016-12-11 18:48:27 -05:00
|
|
|
<< " m_toneFrequency: " << m_config.m_toneFrequency
|
|
|
|
<< " m_volumeFactor: " << m_config.m_volumeFactor
|
2016-12-12 16:02:24 -05:00
|
|
|
<< " m_spanLog2: " << m_config.m_spanLog2
|
|
|
|
<< " m_audioBinaural: " << m_config.m_audioBinaural
|
|
|
|
<< " m_audioFlipChannels: " << m_config.m_audioFlipChannels
|
|
|
|
<< " m_dsb: " << m_config.m_dsb
|
2016-12-13 20:57:47 -05:00
|
|
|
<< " m_audioMute: " << m_config.m_audioMute
|
2017-08-05 13:08:33 -04:00
|
|
|
<< " m_playLoop: " << m_config.m_playLoop
|
|
|
|
<< " m_agc: " << m_config.m_agc
|
|
|
|
<< " m_agcTime: " << m_config.m_agcTime
|
|
|
|
<< " m_agcThresholdEnable: " << m_config.m_agcThresholdEnable
|
|
|
|
<< " m_agcThreshold: " << m_config.m_agcThreshold
|
|
|
|
<< " m_agcThresholdGate: " << m_config.m_agcThresholdGate
|
|
|
|
<< " m_agcThresholdDelay: " << m_config.m_agcThresholdDelay;
|
2016-12-11 18:48:27 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
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 (MsgConfigureAFInput::match(cmd))
|
|
|
|
{
|
|
|
|
MsgConfigureAFInput& conf = (MsgConfigureAFInput&) cmd;
|
|
|
|
m_afInput = conf.getAFInput();
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgReportFileSourceStreamTiming *report;
|
|
|
|
report = MsgReportFileSourceStreamTiming::create(samplesCount);
|
|
|
|
getOutputMessageQueue()->push(report);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SSBMod::apply()
|
|
|
|
{
|
2016-12-12 18:43:59 -05:00
|
|
|
if ((m_config.m_bandwidth != m_running.m_bandwidth) ||
|
|
|
|
(m_config.m_lowCutoff != m_running.m_lowCutoff) ||
|
|
|
|
(m_config.m_audioSampleRate != m_running.m_audioSampleRate))
|
|
|
|
{
|
2016-12-13 19:16:23 -05:00
|
|
|
m_settingsMutex.lock();
|
|
|
|
m_SSBFilter->create_filter(m_config.m_lowCutoff / m_config.m_audioSampleRate, m_config.m_bandwidth / m_config.m_audioSampleRate);
|
|
|
|
m_DSBFilter->create_dsb_filter((2.0f * m_config.m_bandwidth) / m_config.m_audioSampleRate);
|
|
|
|
m_settingsMutex.unlock();
|
2016-12-12 18:43:59 -05:00
|
|
|
}
|
2016-12-11 18:48:27 -05:00
|
|
|
|
|
|
|
if ((m_config.m_inputFrequencyOffset != m_running.m_inputFrequencyOffset) ||
|
|
|
|
(m_config.m_outputSampleRate != m_running.m_outputSampleRate))
|
|
|
|
{
|
|
|
|
m_settingsMutex.lock();
|
|
|
|
m_carrierNco.setFreq(m_config.m_inputFrequencyOffset, m_config.m_outputSampleRate);
|
|
|
|
m_settingsMutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
if((m_config.m_outputSampleRate != m_running.m_outputSampleRate) ||
|
2016-12-12 16:02:24 -05:00
|
|
|
(m_config.m_bandwidth != m_running.m_bandwidth) ||
|
2016-12-11 18:48:27 -05:00
|
|
|
(m_config.m_audioSampleRate != m_running.m_audioSampleRate))
|
|
|
|
{
|
|
|
|
m_settingsMutex.lock();
|
|
|
|
m_interpolatorDistanceRemain = 0;
|
|
|
|
m_interpolatorConsumed = false;
|
|
|
|
m_interpolatorDistance = (Real) m_config.m_audioSampleRate / (Real) m_config.m_outputSampleRate;
|
2016-12-13 19:16:23 -05:00
|
|
|
m_interpolator.create(48, m_config.m_audioSampleRate, m_config.m_bandwidth, 3.0);
|
2016-12-11 18:48:27 -05:00
|
|
|
m_settingsMutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((m_config.m_toneFrequency != m_running.m_toneFrequency) ||
|
|
|
|
(m_config.m_audioSampleRate != m_running.m_audioSampleRate))
|
|
|
|
{
|
|
|
|
m_settingsMutex.lock();
|
|
|
|
m_toneNco.setFreq(m_config.m_toneFrequency, m_config.m_audioSampleRate);
|
|
|
|
m_settingsMutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_config.m_audioSampleRate != m_running.m_audioSampleRate)
|
|
|
|
{
|
2016-12-14 13:08:05 -05:00
|
|
|
m_settingsMutex.lock();
|
2016-12-11 18:48:27 -05:00
|
|
|
m_cwKeyer.setSampleRate(m_config.m_audioSampleRate);
|
2016-12-15 18:02:37 -05:00
|
|
|
m_cwSmoother.setNbFadeSamples(m_config.m_audioSampleRate / 250); // 4 ms
|
2016-12-14 13:08:05 -05:00
|
|
|
m_settingsMutex.unlock();
|
2016-12-11 18:48:27 -05:00
|
|
|
}
|
|
|
|
|
2016-12-13 13:57:07 -05:00
|
|
|
if (m_config.m_dsb != m_running.m_dsb)
|
|
|
|
{
|
|
|
|
if (m_config.m_dsb)
|
|
|
|
{
|
|
|
|
memset(m_DSBFilterBuffer, 0, sizeof(Complex)*(m_ssbFftLen));
|
|
|
|
m_DSBFilterBufferIndex = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset(m_SSBFilterBuffer, 0, sizeof(Complex)*(m_ssbFftLen>>1));
|
|
|
|
m_SSBFilterBufferIndex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-05 17:11:05 -04:00
|
|
|
if ((m_config.m_agcTime != m_running.m_agcTime) || (m_config.m_agcOrder != m_running.m_agcOrder))
|
2017-08-05 13:08:33 -04:00
|
|
|
{
|
2017-08-05 17:11:05 -04:00
|
|
|
m_inAGC.resize(m_config.m_agcTime, m_config.m_agcOrder);
|
2017-08-05 13:08:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_config.m_agcThresholdEnable != m_running.m_agcThresholdEnable)
|
|
|
|
{
|
|
|
|
m_inAGC.setThresholdEnable(m_config.m_agcThresholdEnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_config.m_agcThreshold != m_running.m_agcThreshold)
|
|
|
|
{
|
|
|
|
m_inAGC.setThreshold(m_config.m_agcThreshold);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_config.m_agcThresholdGate != m_running.m_agcThresholdGate)
|
|
|
|
{
|
|
|
|
m_inAGC.setGate(m_config.m_agcThresholdGate);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_config.m_agcThresholdDelay != m_running.m_agcThresholdDelay)
|
|
|
|
{
|
|
|
|
m_inAGC.setStepDownDelay(m_config.m_agcThresholdDelay);
|
|
|
|
}
|
|
|
|
|
2016-12-11 18:48:27 -05:00
|
|
|
m_running.m_outputSampleRate = m_config.m_outputSampleRate;
|
|
|
|
m_running.m_inputFrequencyOffset = m_config.m_inputFrequencyOffset;
|
2016-12-12 16:02:24 -05:00
|
|
|
m_running.m_bandwidth = m_config.m_bandwidth;
|
|
|
|
m_running.m_lowCutoff = m_config.m_lowCutoff;
|
2016-12-12 18:43:59 -05:00
|
|
|
m_running.m_usb = m_config.m_usb;
|
2016-12-11 18:48:27 -05:00
|
|
|
m_running.m_toneFrequency = m_config.m_toneFrequency;
|
|
|
|
m_running.m_volumeFactor = m_config.m_volumeFactor;
|
|
|
|
m_running.m_audioSampleRate = m_config.m_audioSampleRate;
|
2016-12-12 16:02:24 -05:00
|
|
|
m_running.m_spanLog2 = m_config.m_spanLog2;
|
|
|
|
m_running.m_audioBinaural = m_config.m_audioBinaural;
|
|
|
|
m_running.m_audioFlipChannels = m_config.m_audioFlipChannels;
|
|
|
|
m_running.m_dsb = m_config.m_dsb;
|
2016-12-11 18:48:27 -05:00
|
|
|
m_running.m_audioMute = m_config.m_audioMute;
|
2016-12-13 20:57:47 -05:00
|
|
|
m_running.m_playLoop = m_config.m_playLoop;
|
2017-08-05 13:08:33 -04:00
|
|
|
m_running.m_agc = m_config.m_agc;
|
2017-08-05 17:11:05 -04:00
|
|
|
m_running.m_agcOrder = m_config.m_agcOrder;
|
2017-08-05 13:08:33 -04:00
|
|
|
m_running.m_agcTime = m_config.m_agcTime;
|
|
|
|
m_running.m_agcThresholdEnable = m_config.m_agcThresholdEnable;
|
|
|
|
m_running.m_agcThreshold = m_config.m_agcThreshold;
|
|
|
|
m_running.m_agcThresholdGate = m_config.m_agcThresholdGate;
|
|
|
|
m_running.m_agcThresholdDelay = m_config.m_agcThresholdDelay;
|
2016-12-11 18:48:27 -05: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);
|
|
|
|
|
2016-12-13 18:14:52 -05:00
|
|
|
qDebug() << "SSBMod::openFileStream: " << m_fileName.toStdString().c_str()
|
2016-12-11 18:48:27 -05:00
|
|
|
<< " fileSize: " << m_fileSize << "bytes"
|
|
|
|
<< " length: " << m_recordLength << " seconds";
|
|
|
|
|
|
|
|
MsgReportFileSourceStreamData *report;
|
|
|
|
report = MsgReportFileSourceStreamData::create(m_sampleRate, m_recordLength);
|
|
|
|
getOutputMessageQueue()->push(report);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|