mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
get rid of lpf as it barely works, swh-plugin's lowpass_iir_1891 works better
This commit is contained in:
2
.vscode/.server-controller-port.log
vendored
2
.vscode/.server-controller-port.log
vendored
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"port": 13452,
|
||||
"time": 1741463839184,
|
||||
"time": 1741509228803,
|
||||
"version": "0.0.3"
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
17
src/fm95.c
17
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user