2020-06-10 18:52:07 +02:00
|
|
|
#include <signal_path.h>
|
|
|
|
|
2020-06-15 15:53:45 +02:00
|
|
|
SignalPath::SignalPath() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-22 16:45:57 +02:00
|
|
|
void SignalPath::init(uint64_t sampleRate, int fftRate, int fftSize, dsp::stream<dsp::complex_t>* input, dsp::complex_t* fftBuffer, void fftHandler(dsp::complex_t*)) {
|
2020-06-10 18:52:07 +02:00
|
|
|
this->sampleRate = sampleRate;
|
|
|
|
this->fftRate = fftRate;
|
|
|
|
this->fftSize = fftSize;
|
2020-06-15 15:53:45 +02:00
|
|
|
|
|
|
|
_demod = DEMOD_FM;
|
|
|
|
|
|
|
|
dcBiasRemover.init(input, 32000);
|
|
|
|
dcBiasRemover.bypass = true;
|
|
|
|
split.init(&dcBiasRemover.output, 32000);
|
|
|
|
|
|
|
|
fftBlockDec.init(&split.output_a, (sampleRate / fftRate) - fftSize, fftSize);
|
|
|
|
fftHandlerSink.init(&fftBlockDec.output, fftBuffer, fftSize, fftHandler);
|
|
|
|
|
2020-06-22 16:45:57 +02:00
|
|
|
mainVFO.init(&split.output_b, sampleRate, 200000, 200000, 0, 32000);
|
2020-06-15 15:53:45 +02:00
|
|
|
|
|
|
|
demod.init(mainVFO.output, 100000, 200000, 800);
|
2020-06-22 16:45:57 +02:00
|
|
|
amDemod.init(mainVFO.output, 50);
|
2020-07-19 15:59:44 +02:00
|
|
|
ssbDemod.init(mainVFO.output, 6000, 3000, 22);
|
2020-06-15 15:53:45 +02:00
|
|
|
|
2020-07-19 15:59:44 +02:00
|
|
|
audioResamp.init(&demod.output, 200000, 48000, 800);
|
2020-07-20 13:45:05 +02:00
|
|
|
audio.init(&audioResamp.output, 64);
|
2020-07-19 15:59:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SignalPath::setSampleRate(float sampleRate) {
|
|
|
|
dcBiasRemover.stop();
|
|
|
|
split.stop();
|
|
|
|
fftBlockDec.stop();
|
|
|
|
fftHandlerSink.stop();
|
|
|
|
|
|
|
|
demod.stop();
|
|
|
|
amDemod.stop();
|
|
|
|
audioResamp.stop();
|
|
|
|
|
|
|
|
int inputBlockSize = sampleRate / 200.0f;
|
|
|
|
|
|
|
|
dcBiasRemover.setBlockSize(inputBlockSize);
|
|
|
|
split.setBlockSize(inputBlockSize);
|
2020-07-21 01:58:47 +02:00
|
|
|
int skip = (sampleRate / fftRate) - fftSize;
|
|
|
|
fftBlockDec.setSkip(skip);
|
2020-07-19 15:59:44 +02:00
|
|
|
mainVFO.setInputSampleRate(sampleRate, inputBlockSize);
|
2020-06-22 16:45:57 +02:00
|
|
|
|
2020-07-19 15:59:44 +02:00
|
|
|
// // Reset the modulator and audio systems
|
|
|
|
setDemodulator(_demod);
|
|
|
|
|
|
|
|
fftHandlerSink.start();
|
|
|
|
fftBlockDec.start();
|
|
|
|
split.start();
|
|
|
|
dcBiasRemover.start();
|
2020-06-15 15:53:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SignalPath::setVFOFrequency(long frequency) {
|
|
|
|
mainVFO.setOffset(frequency);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SignalPath::setVolume(float volume) {
|
|
|
|
audio.setVolume(volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SignalPath::setDemodulator(int demId) {
|
|
|
|
if (demId < 0 || demId >= _DEMOD_COUNT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
audioResamp.stop();
|
|
|
|
|
|
|
|
// Stop current demodulator
|
2020-07-11 21:15:10 +02:00
|
|
|
if (_demod == DEMOD_FM) {
|
|
|
|
demod.stop();
|
|
|
|
}
|
2020-07-19 15:59:44 +02:00
|
|
|
else if (_demod == DEMOD_NFM) {
|
|
|
|
demod.stop();
|
|
|
|
}
|
2020-07-11 21:15:10 +02:00
|
|
|
else if (_demod == DEMOD_AM) {
|
|
|
|
amDemod.stop();
|
|
|
|
}
|
2020-07-19 15:59:44 +02:00
|
|
|
else if (_demod == DEMOD_USB) {
|
|
|
|
ssbDemod.stop();
|
|
|
|
}
|
|
|
|
else if (_demod == DEMOD_LSB) {
|
|
|
|
ssbDemod.stop();
|
|
|
|
}
|
2020-07-11 21:15:10 +02:00
|
|
|
_demod = demId;
|
|
|
|
|
|
|
|
// Set input of the audio resampler
|
|
|
|
if (demId == DEMOD_FM) {
|
|
|
|
mainVFO.setOutputSampleRate(200000, 200000);
|
2020-07-19 15:59:44 +02:00
|
|
|
demod.setBlockSize(mainVFO.getOutputBlockSize());
|
|
|
|
demod.setSampleRate(200000);
|
|
|
|
demod.setDeviation(100000);
|
|
|
|
audioResamp.setInput(&demod.output);
|
|
|
|
audioResamp.setInputSampleRate(200000, mainVFO.getOutputBlockSize());
|
|
|
|
demod.start();
|
|
|
|
}
|
|
|
|
if (demId == DEMOD_NFM) {
|
|
|
|
mainVFO.setOutputSampleRate(12500, 12500);
|
|
|
|
demod.setBlockSize(mainVFO.getOutputBlockSize());
|
|
|
|
demod.setSampleRate(12500);
|
|
|
|
demod.setDeviation(6250);
|
2020-07-11 21:15:10 +02:00
|
|
|
audioResamp.setInput(&demod.output);
|
2020-07-19 15:59:44 +02:00
|
|
|
audioResamp.setInputSampleRate(12500, mainVFO.getOutputBlockSize());
|
2020-07-11 21:15:10 +02:00
|
|
|
demod.start();
|
|
|
|
}
|
|
|
|
else if (demId == DEMOD_AM) {
|
|
|
|
mainVFO.setOutputSampleRate(12500, 12500);
|
2020-07-19 15:59:44 +02:00
|
|
|
amDemod.setBlockSize(mainVFO.getOutputBlockSize());
|
2020-07-11 21:15:10 +02:00
|
|
|
audioResamp.setInput(&amDemod.output);
|
2020-07-19 15:59:44 +02:00
|
|
|
audioResamp.setInputSampleRate(12500, mainVFO.getOutputBlockSize());
|
2020-07-11 21:15:10 +02:00
|
|
|
amDemod.start();
|
|
|
|
}
|
2020-07-19 15:59:44 +02:00
|
|
|
else if (demId == DEMOD_USB) {
|
|
|
|
mainVFO.setOutputSampleRate(6000, 3000);
|
|
|
|
ssbDemod.setBlockSize(mainVFO.getOutputBlockSize());
|
|
|
|
ssbDemod.setMode(dsp::SSBDemod::MODE_USB);
|
|
|
|
audioResamp.setInput(&ssbDemod.output);
|
|
|
|
audioResamp.setInputSampleRate(6000, mainVFO.getOutputBlockSize());
|
|
|
|
ssbDemod.start();
|
|
|
|
}
|
|
|
|
else if (demId == DEMOD_LSB) {
|
|
|
|
mainVFO.setOutputSampleRate(6000, 3000);
|
|
|
|
ssbDemod.setBlockSize(mainVFO.getOutputBlockSize());
|
|
|
|
ssbDemod.setMode(dsp::SSBDemod::MODE_LSB);
|
|
|
|
audioResamp.setInput(&ssbDemod.output);
|
|
|
|
audioResamp.setInputSampleRate(6000, mainVFO.getOutputBlockSize());
|
|
|
|
ssbDemod.start();
|
|
|
|
}
|
2020-06-15 15:53:45 +02:00
|
|
|
|
|
|
|
audioResamp.start();
|
2020-06-10 18:52:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SignalPath::start() {
|
|
|
|
dcBiasRemover.start();
|
2020-06-15 15:53:45 +02:00
|
|
|
split.start();
|
|
|
|
|
2020-06-10 18:52:07 +02:00
|
|
|
fftBlockDec.start();
|
2020-06-15 15:53:45 +02:00
|
|
|
fftHandlerSink.start();
|
|
|
|
|
|
|
|
mainVFO.start();
|
|
|
|
demod.start();
|
2020-08-04 21:34:56 +02:00
|
|
|
|
2020-06-15 15:53:45 +02:00
|
|
|
audioResamp.start();
|
|
|
|
audio.start();
|
2020-07-19 21:26:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SignalPath::setDCBiasCorrection(bool enabled) {
|
|
|
|
dcBiasRemover.bypass = !enabled;
|
2020-06-10 18:52:07 +02:00
|
|
|
}
|