From 0a99e3364cd8021c0c90bd48d1a6d9844dd03e8f Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sun, 9 Mar 2025 09:35:10 +0100 Subject: [PATCH] get rid of lpf as it barely works, swh-plugin's lowpass_iir_1891 works better --- .vscode/.server-controller-port.log | 2 +- lib/filters.c | 21 --------------------- lib/filters.h | 9 --------- src/fm95.c | 17 ++--------------- 4 files changed, 3 insertions(+), 46 deletions(-) diff --git a/.vscode/.server-controller-port.log b/.vscode/.server-controller-port.log index 157f32b..23f7f96 100644 --- a/.vscode/.server-controller-port.log +++ b/.vscode/.server-controller-port.log @@ -1,5 +1,5 @@ { "port": 13452, - "time": 1741463839184, + "time": 1741509228803, "version": "0.0.3" } \ No newline at end of file diff --git a/lib/filters.c b/lib/filters.c index 8fa6af5..104a349 100644 --- a/lib/filters.c +++ b/lib/filters.c @@ -10,27 +10,6 @@ float apply_preemphasis(ResistorCapacitor *filter, float sample) { return out; } -void init_lpf(BiquadFilter* filter, float cutoffFreq, float qFactor, float sampleRate) { - float cutoffNorm = cutoffFreq / sampleRate; - float K = tanf(M_PI * cutoffNorm); - float norm = 1.0f/(1.0f+K/qFactor+K*K); - filter->a0 = K*K*norm; - filter->a1 = 2.0f*K*K*norm; - filter->a2 = K*K*norm; - filter->b1 = 2.0f*(K*K-1.0f)*norm; - filter->b2 = (1.0f-K/qFactor+K*K)*norm; - - filter->z1 = 0.0f; - filter->z2 = 0.0f; -} - -float apply_biquad(BiquadFilter* filter, float input) { - float out = input*filter->a0+filter->z1; - filter->z1 = input*filter->a1+filter->z2-filter->b1*out; - filter->z2 = input*filter->a2-filter->b2*out; - return out; -} - float hard_clip(float sample, float threshold) { if (sample > threshold) { diff --git a/lib/filters.h b/lib/filters.h index d56788d..cf4d3b4 100644 --- a/lib/filters.h +++ b/lib/filters.h @@ -14,15 +14,6 @@ typedef struct void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate); float apply_preemphasis(ResistorCapacitor *filter, float sample); -typedef struct { - // https://www.earlevel.com/main/2012/11/26/biquad-c-source-code/ - float a0, a1, a2; - float b1, b2; - float z1, z2; -} BiquadFilter; -void init_lpf(BiquadFilter* filter, float cutoffFreq, float qFactor, float sampleRate); -float apply_biquad(BiquadFilter* filter, float input); - float hard_clip(float sample, float threshold); float voltage_db_to_voltage(float db); float power_db_to_voltage(float db); diff --git a/src/fm95.c b/src/fm95.c index 985ad85..7596951 100644 --- a/src/fm95.c +++ b/src/fm95.c @@ -40,8 +40,6 @@ #define MPX_VOLUME 1.0f // Passtrough #define MPX_CLIPPER_THRESHOLD 1.0f -#define LPF_CUTOFF 15000 // Should't need to be changed - volatile sig_atomic_t to_run = 1; void uninterleave(const float *input, float *left, float *right, size_t num_samples) { @@ -368,13 +366,6 @@ int main(int argc, char **argv) { ResistorCapacitor preemp_l, preemp_r; init_preemphasis(&preemp_l, preemphasis_tau, SAMPLE_RATE); init_preemphasis(&preemp_r, preemphasis_tau, SAMPLE_RATE); - - // Use https://www.earlevel.com/main/2021/09/02/biquad-calculator-v3/ - BiquadFilter lpf_l1, lpf_r1, lpf_l2, lpf_r2; - init_lpf(&lpf_l1, LPF_CUTOFF, 0.70710678f, SAMPLE_RATE); - init_lpf(&lpf_r1, LPF_CUTOFF, 0.70710678f, SAMPLE_RATE); - init_lpf(&lpf_l2, LPF_CUTOFF, 0.70710678f/2.0f, SAMPLE_RATE); - init_lpf(&lpf_r2, LPF_CUTOFF, 0.70710678f/2.0f, SAMPLE_RATE); // #endregion signal(SIGINT, stop); @@ -415,12 +406,8 @@ int main(int argc, char **argv) { float current_mpx_in = mpx_in[i]; float current_sca_in = sca_in[i]; - float ready_l = apply_biquad(&lpf_l1, l_in); - float ready_r = apply_biquad(&lpf_r1, r_in); - ready_l = apply_biquad(&lpf_l2, ready_l); - ready_r = apply_biquad(&lpf_r2, ready_r); - ready_l = apply_preemphasis(&preemp_l, ready_l)*2; - ready_r = apply_preemphasis(&preemp_r, ready_r)*2; + float ready_l = apply_preemphasis(&preemp_l, l_in)*2; + float ready_r = apply_preemphasis(&preemp_r, r_in)*2; ready_l = hard_clip(ready_l*audio_volume, clipper_threshold); ready_r = hard_clip(ready_r*audio_volume, clipper_threshold);