mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 11:22:00 +01:00
remove lpf and add normalization to the preemp
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": 1742991617814,
|
||||
"time": 1743013405321,
|
||||
"version": "0.0.3"
|
||||
}
|
||||
@@ -33,7 +33,7 @@ Done!
|
||||
|
||||
## CPU Usage?
|
||||
|
||||
Should run completly fine on a pi 5, right now with the preemp, on a pi 3b, its 32%
|
||||
Should run completly fine on a pi 5, right now with the preemp and rds2, on a pi 3b, its 25%
|
||||
|
||||
## Recommendations
|
||||
|
||||
|
||||
@@ -2,26 +2,15 @@
|
||||
|
||||
void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate) {
|
||||
filter->prev_sample = 0.0f;
|
||||
filter->alpha = exp(-1 / (tau*sample_rate));
|
||||
filter->alpha = expf(-1 / (tau*sample_rate));
|
||||
filter->gain = 1.0f / (1.0f - filter->alpha);
|
||||
}
|
||||
float apply_preemphasis(ResistorCapacitor *filter, float sample) {
|
||||
float out = sample-filter->alpha*filter->prev_sample;
|
||||
float out = (sample - filter->alpha * filter->prev_sample) * filter->gain;
|
||||
filter->prev_sample = sample;
|
||||
return out;
|
||||
}
|
||||
|
||||
float hard_clip(float sample, float threshold) {
|
||||
return fmaxf(-threshold, fminf(threshold, sample));
|
||||
}
|
||||
|
||||
void init_rc_lpf(ResistorCapacitor *filter, float cutoff, float sample_rate) {
|
||||
filter->prev_sample = 0.0f;
|
||||
float dt = 1.0f/sample_rate;
|
||||
float rc = 1.0f/(cutoff*M_2PI);
|
||||
filter->alpha = dt/(rc+dt);
|
||||
}
|
||||
float apply_rc_lpf(ResistorCapacitor *filter, float sample) {
|
||||
float out = filter->prev_sample+(filter->alpha*(sample-filter->prev_sample));
|
||||
filter->prev_sample = sample;
|
||||
return out;
|
||||
}
|
||||
@@ -5,18 +5,14 @@
|
||||
#include "constants.h"
|
||||
#include "oscillator.h"
|
||||
|
||||
#define FILTER_LEN 51
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float alpha;
|
||||
float prev_sample;
|
||||
float gain;
|
||||
} ResistorCapacitor;
|
||||
|
||||
void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate);
|
||||
float apply_preemphasis(ResistorCapacitor *filter, float sample);
|
||||
|
||||
float hard_clip(float sample, float threshold);
|
||||
|
||||
void init_rc_lpf(ResistorCapacitor *filter, float cutoff, float sample_rate);
|
||||
float apply_rc_lpf(ResistorCapacitor *filter, float sample);
|
||||
float hard_clip(float sample, float threshold);
|
||||
10
src/fm95.c
10
src/fm95.c
@@ -414,10 +414,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);
|
||||
|
||||
ResistorCapacitor lpf_l, lpf_r;
|
||||
init_rc_lpf(&lpf_l, 15000, sample_rate);
|
||||
init_rc_lpf(&lpf_r, 15000, sample_rate);
|
||||
// #endregion
|
||||
|
||||
signal(SIGINT, stop);
|
||||
@@ -473,10 +469,8 @@ int main(int argc, char **argv) {
|
||||
float current_rds2_in = rds2_in[i];
|
||||
float current_sca_in = sca_in[i];
|
||||
|
||||
float ready_l = apply_preemphasis(&preemp_l, l_in)*2;
|
||||
float ready_r = apply_preemphasis(&preemp_r, r_in)*2;
|
||||
ready_l = apply_rc_lpf(&lpf_l, ready_l);
|
||||
ready_r = apply_rc_lpf(&lpf_r, ready_r);
|
||||
float ready_l = apply_preemphasis(&preemp_l, l_in);
|
||||
float ready_r = apply_preemphasis(&preemp_r, r_in);
|
||||
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