mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Refactor IIRBiquadFilter to separate configuration structure.
This commit is contained in:
parent
76df4f0369
commit
caef87fe90
@ -26,16 +26,19 @@
|
||||
|
||||
#include "dsp_types.hpp"
|
||||
|
||||
struct iir_biquad_config_t {
|
||||
const std::array<float, 3> b;
|
||||
const std::array<float, 3> a;
|
||||
};
|
||||
|
||||
class IIRBiquadFilter {
|
||||
public:
|
||||
// http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
|
||||
|
||||
// Assume all coefficients are normalized so that a0=1.0
|
||||
constexpr IIRBiquadFilter(
|
||||
std::array<float, 3> b,
|
||||
std::array<float, 3> a
|
||||
) : b(b),
|
||||
a(a)
|
||||
const iir_biquad_config_t& config
|
||||
) : config(config)
|
||||
{
|
||||
}
|
||||
|
||||
@ -51,8 +54,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const std::array<float, 3> b;
|
||||
const std::array<float, 3> a;
|
||||
const iir_biquad_config_t config;
|
||||
std::array<float, 3> x { { 0.0f, 0.0f, 0.0f } };
|
||||
std::array<float, 3> y { { 0.0f, 0.0f, 0.0f } };
|
||||
|
||||
@ -63,8 +65,8 @@ private:
|
||||
|
||||
y[0] = y[1];
|
||||
y[1] = y[2];
|
||||
y[2] = b[0] * x[2] + b[1] * x[1] + b[2] * x[0]
|
||||
- a[1] * y[1] - a[2] * y[0];
|
||||
y[2] = config.b[0] * x[2] + config.b[1] * x[1] + config.b[2] * x[0]
|
||||
- config.a[1] * y[1] - config.a[2] * y[0];
|
||||
|
||||
return y[2];
|
||||
}
|
||||
|
@ -175,6 +175,16 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr iir_biquad_config_t audio_hpf_config {
|
||||
{ 0.93346032f, -1.86687724f, 0.93346032f },
|
||||
{ 1.0f , -1.97730264f, 0.97773668f }
|
||||
};
|
||||
|
||||
static constexpr iir_biquad_config_t non_audio_hpf_config {
|
||||
{ 0.51891061f, -0.95714180f, 0.51891061f },
|
||||
{ 1.0f , -0.79878302f, 0.43960231f }
|
||||
};
|
||||
|
||||
class FMSquelch {
|
||||
public:
|
||||
bool execute(buffer_s16_t audio) {
|
||||
@ -203,10 +213,7 @@ private:
|
||||
|
||||
// nyquist = 48000 / 2.0
|
||||
// scipy.signal.iirdesign(wp=8000 / nyquist, ws= 4000 / nyquist, gpass=1, gstop=18, ftype='ellip')
|
||||
IIRBiquadFilter non_audio_hpf {
|
||||
{ 0.51891061f, -0.95714180f, 0.51891061f },
|
||||
{ 1.0f , -0.79878302f, 0.43960231f }
|
||||
};
|
||||
IIRBiquadFilter non_audio_hpf { non_audio_hpf_config };
|
||||
};
|
||||
|
||||
static volatile bool channel_spectrum_request_update { false };
|
||||
@ -332,10 +339,7 @@ private:
|
||||
const fir_taps_real<64>& channel_filter_taps = taps_64_lp_031_070_tfilter;
|
||||
dsp::decimate::FIRAndDecimateBy2Complex<64> channel_filter { channel_filter_taps.taps };
|
||||
dsp::demodulate::AM demod;
|
||||
IIRBiquadFilter audio_hpf {
|
||||
{ 0.93346032f, -1.86687724f, 0.93346032f },
|
||||
{ 1.0f , -1.97730264f, 0.97773668f }
|
||||
};
|
||||
IIRBiquadFilter audio_hpf { audio_hpf_config };
|
||||
};
|
||||
|
||||
class NarrowbandFMAudio : public BasebandProcessor {
|
||||
@ -393,10 +397,7 @@ private:
|
||||
dsp::decimate::FIRAndDecimateBy2Complex<64> channel_filter { channel_filter_taps.taps };
|
||||
dsp::demodulate::FM demod { 48000, 7500 };
|
||||
|
||||
IIRBiquadFilter audio_hpf {
|
||||
{ 0.93346032f, -1.86687724f, 0.93346032f },
|
||||
{ 1.0f , -1.97730264f, 0.97773668f }
|
||||
};
|
||||
IIRBiquadFilter audio_hpf { audio_hpf_config };
|
||||
FMSquelch squelch;
|
||||
};
|
||||
|
||||
@ -461,10 +462,7 @@ private:
|
||||
const fir_taps_real<64>& audio_filter_taps = taps_64_lp_156_198;
|
||||
dsp::decimate::FIR64AndDecimateBy2Real audio_filter { audio_filter_taps.taps };
|
||||
|
||||
IIRBiquadFilter audio_hpf {
|
||||
{ 0.93346032f, -1.86687724f, 0.93346032f },
|
||||
{ 1.0f , -1.97730264f, 0.97773668f }
|
||||
};
|
||||
IIRBiquadFilter audio_hpf { audio_hpf_config };
|
||||
};
|
||||
|
||||
class FSKProcessor : public BasebandProcessor {
|
||||
|
Loading…
Reference in New Issue
Block a user