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

@@ -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;
}