2020-09-20 00:19:39 +02:00
|
|
|
#include <signal_path/dsp.h>
|
2020-06-10 18:52:07 +02:00
|
|
|
|
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-08-11 18:33:42 +02:00
|
|
|
inputBlockSize = sampleRate / 200.0f;
|
2020-06-15 15:53:45 +02:00
|
|
|
|
|
|
|
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-08-11 18:33:42 +02:00
|
|
|
dynSplit.init(&split.output_b, 32000);
|
2020-07-19 15:59:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SignalPath::setSampleRate(float sampleRate) {
|
2020-08-11 18:33:42 +02:00
|
|
|
this->sampleRate = sampleRate;
|
|
|
|
inputBlockSize = sampleRate / 200.0f;
|
|
|
|
|
2020-07-19 15:59:44 +02:00
|
|
|
dcBiasRemover.stop();
|
|
|
|
split.stop();
|
|
|
|
fftBlockDec.stop();
|
|
|
|
fftHandlerSink.stop();
|
2020-08-11 18:33:42 +02:00
|
|
|
dynSplit.stop();
|
2020-07-19 15:59:44 +02:00
|
|
|
|
2020-08-11 18:33:42 +02:00
|
|
|
for (auto const& [name, vfo] : vfos) {
|
|
|
|
vfo.vfo->stop();
|
|
|
|
}
|
2020-07-19 15:59:44 +02:00
|
|
|
|
|
|
|
dcBiasRemover.setBlockSize(inputBlockSize);
|
|
|
|
split.setBlockSize(inputBlockSize);
|
2020-07-21 01:58:47 +02:00
|
|
|
int skip = (sampleRate / fftRate) - fftSize;
|
|
|
|
fftBlockDec.setSkip(skip);
|
2020-08-11 18:33:42 +02:00
|
|
|
dynSplit.setBlockSize(inputBlockSize);
|
2020-06-22 16:45:57 +02:00
|
|
|
|
2020-08-11 18:33:42 +02:00
|
|
|
mod::broadcastEvent(mod::EVENT_STREAM_PARAM_CHANGED);
|
|
|
|
|
|
|
|
for (auto const& [name, vfo] : vfos) {
|
|
|
|
vfo.vfo->setInputSampleRate(sampleRate, inputBlockSize);
|
|
|
|
vfo.vfo->start();
|
|
|
|
}
|
2020-07-19 15:59:44 +02:00
|
|
|
|
|
|
|
fftHandlerSink.start();
|
|
|
|
fftBlockDec.start();
|
|
|
|
split.start();
|
|
|
|
dcBiasRemover.start();
|
2020-08-11 18:33:42 +02:00
|
|
|
dynSplit.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();
|
|
|
|
|
2020-08-11 18:33:42 +02:00
|
|
|
dynSplit.start();
|
2020-07-19 21:26:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SignalPath::setDCBiasCorrection(bool enabled) {
|
|
|
|
dcBiasRemover.bypass = !enabled;
|
2020-08-11 18:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
dsp::VFO* SignalPath::addVFO(std::string name, float outSampleRate, float bandwidth, float offset) {
|
|
|
|
if (vfos.find(name) != vfos.end()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
dynSplit.stop();
|
|
|
|
VFO_t vfo;
|
|
|
|
vfo.inputStream = new dsp::stream<dsp::complex_t>(inputBlockSize * 2);
|
|
|
|
dynSplit.bind(vfo.inputStream);
|
|
|
|
vfo.vfo = new dsp::VFO();
|
|
|
|
vfo.vfo->init(vfo.inputStream, sampleRate, outSampleRate, bandwidth, offset, inputBlockSize);
|
|
|
|
vfo.vfo->start();
|
|
|
|
vfos[name] = vfo;
|
|
|
|
dynSplit.start();
|
|
|
|
return vfo.vfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SignalPath::removeVFO(std::string name) {
|
|
|
|
if (vfos.find(name) == vfos.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dynSplit.stop();
|
|
|
|
VFO_t vfo = vfos[name];
|
|
|
|
vfo.vfo->stop();
|
|
|
|
dynSplit.unbind(vfo.inputStream);
|
|
|
|
delete vfo.vfo;
|
|
|
|
delete vfo.inputStream;
|
|
|
|
dynSplit.start();
|
|
|
|
vfos.erase(name);
|
2020-06-10 18:52:07 +02:00
|
|
|
}
|