mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-27 03:23:54 +01:00
damn it
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,
|
"port": 13452,
|
||||||
"time": 1742842256267,
|
"time": 1742920067458,
|
||||||
"version": "0.0.3"
|
"version": "0.0.3"
|
||||||
}
|
}
|
||||||
@@ -12,33 +12,4 @@ 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));
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
@@ -16,12 +16,4 @@ 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);
|
||||||
|
|
||||||
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);
|
|
||||||
@@ -414,10 +414,6 @@ 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);
|
||||||
|
|
||||||
FIRFilter lpf_l, lpf_r;
|
|
||||||
init_lpf(&lpf_l, 15000);
|
|
||||||
init_lpf(&lpf_r, 15000);
|
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
signal(SIGINT, stop);
|
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_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 = 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_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