0
1
mirror of https://github.com/radio95-rnt/fm95.git synced 2026-02-26 19:23:51 +01:00
This commit is contained in:
2025-03-25 17:27:59 +01:00
parent 023102e69a
commit 702117e4d7
4 changed files with 2 additions and 45 deletions

View File

@@ -1,5 +1,5 @@
{
"port": 13452,
"time": 1742842256267,
"time": 1742920067458,
"version": "0.0.3"
}

View File

@@ -12,33 +12,4 @@ float apply_preemphasis(ResistorCapacitor *filter, float sample) {
float hard_clip(float sample, float threshold) {
return fmaxf(-threshold, fminf(threshold, sample));
}
float sincf(float x) {
return (x == 0.0f) ? 1.0f : sinf(M_PI * x) / (M_PI * x);
}
void init_lpf(FIRFilter *lpf, float freq) {
int m = FILTER_LEN - 1;
float sum = 0.0f;
for(int n = 0; n < FILTER_LEN; n++) {
float x = n-m/2.0f;
lpf->filter[n] = sincf(2.0f*freq*x) * (0.54 - 0.46 * cosf(M_2PI * n / m));
sum += lpf->filter[n];
}
for(int n = 0; n < FILTER_LEN; n++) {
lpf->filter[n] /= sum;
}
}
float fir_filter(FIRFilter *fir, float sample) {
float out = 0.0f;
for(int i = 0; i < FILTER_LEN; i++) {
out += fir->filter[i] * sample;
}
fir->filter_idx++;
if(fir->filter_idx == FILTER_LEN) fir->filter_idx = 0;
return out;
}

View File

@@ -16,12 +16,4 @@ typedef struct
void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate);
float apply_preemphasis(ResistorCapacitor *filter, float sample);
float hard_clip(float sample, float threshold);
typedef struct filters
{
float filter[FILTER_LEN];
int filter_idx;
} FIRFilter;
void init_lpf(FIRFilter *lpf, float freq);
float fir_filter(FIRFilter *fir, float sample);
float hard_clip(float sample, float threshold);

View File

@@ -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);
FIRFilter lpf_l, lpf_r;
init_lpf(&lpf_l, 15000);
init_lpf(&lpf_r, 15000);
// #endregion
signal(SIGINT, stop);
@@ -475,8 +471,6 @@ int main(int argc, char **argv) {
float ready_l = apply_preemphasis(&preemp_l, l_in)*2;
float ready_r = apply_preemphasis(&preemp_r, r_in)*2;
ready_l = fir_filter(&lpf_l, ready_l);
ready_r = fir_filter(&lpf_l, ready_r);
ready_l = hard_clip(ready_l*audio_volume, clipper_threshold);
ready_r = hard_clip(ready_r*audio_volume, clipper_threshold);