mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
try to add a simple rc lpf
This commit is contained in:
@@ -12,4 +12,16 @@ float apply_preemphasis(ResistorCapacitor *filter, float sample) {
|
|||||||
|
|
||||||
float hard_clip(float sample, float threshold) {
|
float hard_clip(float sample, float threshold) {
|
||||||
return fmaxf(-threshold, fminf(threshold, sample));
|
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;
|
||||||
}
|
}
|
||||||
@@ -16,4 +16,7 @@ typedef struct
|
|||||||
void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate);
|
void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate);
|
||||||
float apply_preemphasis(ResistorCapacitor *filter, float sample);
|
float apply_preemphasis(ResistorCapacitor *filter, float sample);
|
||||||
|
|
||||||
float hard_clip(float sample, float threshold);
|
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);
|
||||||
@@ -414,6 +414,10 @@ int main(int argc, char **argv) {
|
|||||||
ResistorCapacitor preemp_l, preemp_r;
|
ResistorCapacitor preemp_l, preemp_r;
|
||||||
init_preemphasis(&preemp_l, preemphasis_tau, sample_rate);
|
init_preemphasis(&preemp_l, preemphasis_tau, sample_rate);
|
||||||
init_preemphasis(&preemp_r, 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
|
// #endregion
|
||||||
|
|
||||||
signal(SIGINT, stop);
|
signal(SIGINT, stop);
|
||||||
@@ -471,6 +475,8 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
float ready_l = apply_preemphasis(&preemp_l, l_in)*2;
|
float ready_l = apply_preemphasis(&preemp_l, l_in)*2;
|
||||||
float ready_r = apply_preemphasis(&preemp_r, r_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);
|
||||||
ready_l = hard_clip(ready_l*audio_volume, clipper_threshold);
|
ready_l = hard_clip(ready_l*audio_volume, clipper_threshold);
|
||||||
ready_r = hard_clip(ready_r*audio_volume, clipper_threshold);
|
ready_r = hard_clip(ready_r*audio_volume, clipper_threshold);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user