Push before merge

This commit is contained in:
Ryzerth
2021-04-16 19:53:47 +02:00
parent 098f09844b
commit b16ab3f0c0
9 changed files with 70 additions and 246 deletions

View File

@ -7,6 +7,7 @@
#include <spdlog/spdlog.h>
#include <dsp/pll.h>
#include <dsp/clock_recovery.h>
#include <dsp/math.h>
#define FAST_ATAN2_COEF1 FL_M_PI / 4.0f
#define FAST_ATAN2_COEF2 3.0f * FAST_ATAN2_COEF1
@ -186,149 +187,6 @@ namespace dsp {
};
class StereoFMDemod : public generic_block<StereoFMDemod> {
public:
StereoFMDemod() {}
StereoFMDemod(stream<complex_t>* in, float sampleRate, float deviation) { init(in, sampleRate, deviation); }
~StereoFMDemod() {
generic_block<StereoFMDemod>::stop();
delete[] doubledPilot;
delete[] a_minus_b;
delete[] a_out;
delete[] b_out;
}
void init(stream<complex_t>* in, float sampleRate, float deviation) {
_sampleRate = sampleRate;
doubledPilot = new float[STREAM_BUFFER_SIZE];
a_minus_b = new float[STREAM_BUFFER_SIZE];
a_out = new float[STREAM_BUFFER_SIZE];
b_out = new float[STREAM_BUFFER_SIZE];
fmDemod.init(in, sampleRate, deviation);
split.init(&fmDemod.out);
split.bindStream(&filterInput);
split.bindStream(&decodeInput);
// Filter init
win.init(1000, 1000, 19000, sampleRate);
filter.init(&filterInput, &win);
agc.init(&filter.out, 20.0f, sampleRate);
generic_block<StereoFMDemod>::registerInput(&decodeInput);
generic_block<StereoFMDemod>::registerOutput(&out);
}
void setInput(stream<complex_t>* in) {
std::lock_guard<std::mutex> lck(generic_block<StereoFMDemod>::ctrlMtx);
generic_block<StereoFMDemod>::tempStop();
fmDemod.setInput(in);
generic_block<StereoFMDemod>::tempStart();
}
void setSampleRate(float sampleRate) {
std::lock_guard<std::mutex> lck(generic_block<StereoFMDemod>::ctrlMtx);
generic_block<StereoFMDemod>::tempStop();
_sampleRate = sampleRate;
fmDemod.setSampleRate(sampleRate);
win.setSampleRate(_sampleRate);
filter.updateWindow(&win);
generic_block<StereoFMDemod>::tempStart();
}
float getSampleRate() {
return _sampleRate;
}
void setDeviation(float deviation) {
std::lock_guard<std::mutex> lck(generic_block<StereoFMDemod>::ctrlMtx);
generic_block<StereoFMDemod>::tempStop();
fmDemod.setDeviation(deviation);
generic_block<StereoFMDemod>::tempStart();
}
float getDeviation() {
return fmDemod.getDeviation();
}
int run() {
count = decodeInput.read();
if (count < 0) { return -1; }
countFilter = agc.out.read();
if (countFilter < 0) { return -1; }
volk_32f_x2_multiply_32f(doubledPilot, agc.out.readBuf, agc.out.readBuf, count);
volk_32f_x2_multiply_32f(a_minus_b, decodeInput.readBuf, doubledPilot, count);
volk_32f_x2_add_32f(a_out, decodeInput.readBuf, a_minus_b, count);
volk_32f_x2_subtract_32f(b_out, decodeInput.readBuf, a_minus_b, count);
decodeInput.flush();
agc.out.flush();
volk_32f_x2_interleave_32fc((lv_32fc_t*)out.writeBuf, a_out, b_out, count);
if (!out.swap(count)) { return -1; }
return count;
}
void start() {
std::lock_guard<std::mutex> lck(generic_block<StereoFMDemod>::ctrlMtx);
if (generic_block<StereoFMDemod>::running) {
return;
}
generic_block<StereoFMDemod>::running = true;
generic_block<StereoFMDemod>::doStart();
fmDemod.start();
split.start();
filter.start();
agc.start();
}
void stop() {
std::lock_guard<std::mutex> lck(generic_block<StereoFMDemod>::ctrlMtx);
if (!generic_block<StereoFMDemod>::running) {
return;
}
fmDemod.stop();
split.stop();
filter.stop();
agc.stop();
generic_block<StereoFMDemod>::doStop();
generic_block<StereoFMDemod>::running = false;
}
stream<stereo_t> out;
private:
int count;
int countFilter;
float _sampleRate;
FloatFMDemod fmDemod;
Splitter<float> split;
// Pilot tone filtering
stream<float> filterInput;
FIR<float> filter;
filter_window::BlackmanBandpassWindow win;
AGC agc;
stream<float> decodeInput;
// Buffers
float* doubledPilot;
float* a_minus_b;
float* a_out;
float* b_out;
};
class AMDemod : public generic_block<AMDemod> {
public:
AMDemod() {}