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