From c63e94744e5928841c0f929f6b950669d1e6057e Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Sat, 25 Jan 2025 23:37:20 +0100 Subject: [PATCH] remove lpf --- lib/filters.c | 11 ----------- lib/filters.h | 3 --- src/options.h | 1 - src/sca_mod.c | 19 ------------------- src/stereo_coder.c | 35 +++++------------------------------ 5 files changed, 5 insertions(+), 64 deletions(-) diff --git a/lib/filters.c b/lib/filters.c index e40b065..43d12c6 100644 --- a/lib/filters.c +++ b/lib/filters.c @@ -16,17 +16,6 @@ float apply_pre_emphasis(ResistorCapacitor *rc, float sample) { return audio; } -void init_low_pass_filter(ResistorCapacitor *rc, float cutoff_frequency, float sample_rate) { - float RC = 1.0f / (M_2PI * cutoff_frequency); - init_rc(&rc, 1.0f / (1.0f + sample_rate * RC)); -} - -float apply_low_pass_filter(ResistorCapacitor *rc, float sample) { - float output = rc->alpha*sample+(1.0f-rc->alpha)*rc->prev_sample; - rc->prev_sample = output; - return output; -} - void init_delay_line(DelayLine *delay_line, int max_delay) { delay_line->buffer = (float *)calloc(max_delay, sizeof(float)); delay_line->size = max_delay; diff --git a/lib/filters.h b/lib/filters.h index 58137d0..621632a 100644 --- a/lib/filters.h +++ b/lib/filters.h @@ -14,9 +14,6 @@ void init_rc(ResistorCapacitor *pe, float alpha); void init_rc_tau(ResistorCapacitor *pe, float tau, float sample_rate); float apply_pre_emphasis(ResistorCapacitor *pe, float sample); -void init_low_pass_filter(ResistorCapacitor *lp, float cutoff_frequency, float sample_rate); -float apply_low_pass_filter(ResistorCapacitor *lp, float sample); - typedef struct { float *buffer; int write_idx; // Write position diff --git a/src/options.h b/src/options.h index 4671b01..88f02b8 100644 --- a/src/options.h +++ b/src/options.h @@ -1,5 +1,4 @@ #define PREEMPHASIS -#define LPF #define buffer_maxlength 12288 #define buffer_tlength_fragsize 8192 diff --git a/src/sca_mod.c b/src/sca_mod.c index 592026d..442aa14 100644 --- a/src/sca_mod.c +++ b/src/sca_mod.c @@ -35,10 +35,6 @@ #define PREEMPHASIS_TAU 0.00005 // 50 microseconds, use 0.000075 if in america #endif -#ifdef LPF -#define LPF_CUTOFF 7500 -#endif - volatile sig_atomic_t to_run = 1; float hard_clip(float sample) { @@ -149,10 +145,6 @@ int main() { ResistorCapacitor preemp; init_rc_tau(&preemp, PREEMPHASIS_TAU, SAMPLE_RATE); #endif -#ifdef LPF - ResistorCapacitor lpf; - init_low_pass_filter(&lpf, LPF_CUTOFF, SAMPLE_RATE); -#endif signal(SIGINT, stop); signal(SIGTERM, stop); @@ -171,21 +163,10 @@ int main() { float in = input[i]; #ifdef PREEMPHASIS -#ifdef LPF - float lowpassed = apply_low_pass_filter(&lpf, in); - float preemphasized = apply_pre_emphasis(&preemp, lowpassed)*2; - float current_input = hard_clip(preemphasized); -#else float preemphasized = apply_pre_emphasis(&preemp, in)*2; float current_input = hard_clip(preemphasized); -#endif -#else -#ifdef LPF - float lowpassed = apply_low_pass_filter(&lpf, in); - float current_input = hard_clip(lowpassed); #else float current_input = hard_clip(in); -#endif #endif signal[i] = modulate_fm(&mod, current_input)*VOLUME; diff --git a/src/stereo_coder.c b/src/stereo_coder.c index b66727e..3cc063b 100644 --- a/src/stereo_coder.c +++ b/src/stereo_coder.c @@ -42,10 +42,6 @@ #define PREEMPHASIS_TAU 0.00005 // 50 microseconds, use 0.000075 if in america #endif -#ifdef LPF -#define LPF_CUTOFF 15000 -#endif - volatile sig_atomic_t to_run = 1; float hard_clip(float sample, float threshold) { @@ -78,7 +74,7 @@ void show_version() { void show_help(char *name) { printf( - "FM95 (an FM Processor by radio95)\n" + "fm95 (an FM Processor by radio95)\n" "Usage: %s\n\n" " -m,--mono Force Mono\n" " -s,--stereo Force Stereo\n" @@ -97,10 +93,7 @@ void show_help(char *name) { int main(int argc, char **argv) { show_version(); int stereo = DEFAULT_STEREO; - int polar_stereo = DEFAULT_STEREO_POLAR; - int ssb = DEFAULT_STEREO_SSB; - float clipper_threshold = DEFAULT_CLIPPER_THRESHOLD; - #ifndef MPX_DEVICE + #ifndef MPX_DEVICE char audio_mpx_device[64] = "\0"; #else char audio_mpx_device[64] = MPX_DEVICE; @@ -109,6 +102,9 @@ int main(int argc, char **argv) { pa_simple *output_device; snd_pcm_hw_params_t *output_params; snd_pcm_t *output_handle; + float clipper_threshold = DEFAULT_CLIPPER_THRESHOLD; + int polar_stereo = DEFAULT_STEREO_POLAR; + int ssb = DEFAULT_STEREO_SSB; char audio_input_device[64] = INPUT_DEVICE; char audio_output_device[64] = OUTPUT_DEVICE; int alsa_output = DEFAULT_ALSA_OUTPUT; @@ -314,11 +310,6 @@ int main(int argc, char **argv) { init_rc_tau(&preemp_l, PREEMPHASIS_TAU, SAMPLE_RATE); init_rc_tau(&preemp_r, PREEMPHASIS_TAU, SAMPLE_RATE); #endif -#ifdef LPF - ResistorCapacitor lpf_l, lpf_r; - init_low_pass_filter(&lpf_l, LPF_CUTOFF, SAMPLE_RATE); - init_low_pass_filter(&lpf_r, LPF_CUTOFF, SAMPLE_RATE); -#endif signal(SIGINT, stop); signal(SIGTERM, stop); @@ -349,29 +340,13 @@ int main(int argc, char **argv) { float multiplex_in = mpx_in[i]; #ifdef PREEMPHASIS -#ifdef LPF - float lowpassed_left = apply_low_pass_filter(&lpf_l, l_in); - float lowpassed_right = apply_low_pass_filter(&lpf_r, r_in); - float preemphasized_left = apply_pre_emphasis(&preemp_l, lowpassed_left)*2; - float preemphasized_right = apply_pre_emphasis(&preemp_r, lowpassed_right)*2; - float current_left_input = hard_clip(preemphasized_left, clipper_threshold); - float current_right_input = hard_clip(preemphasized_right, clipper_threshold); -#else float preemphasized_left = apply_pre_emphasis(&preemp_l, l_in)*2; float preemphasized_right = apply_pre_emphasis(&preemp_r, r_in)*2; float current_left_input = hard_clip(preemphasized_left, clipper_threshold); float current_right_input = hard_clip(preemphasized_right, clipper_threshold); -#endif -#else -#ifdef LPF - float lowpassed_left = apply_low_pass_filter(&lpf_l, l_in); - float lowpassed_right = apply_low_pass_filter(&lpf_r, r_in); - float current_left_input = hard_clip(lowpassed_left, clipper_threshold); - float current_right_input = hard_clip(lowpassed_right, clipper_threshold); #else float current_left_input = hard_clip(l_in, clipper_threshold); float current_right_input = hard_clip(r_in, clipper_threshold); -#endif #endif float mono = (current_left_input + current_right_input) / 2.0f; // Stereo to Mono