mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-27 03:23:54 +01:00
sca
This commit is contained in:
@@ -81,9 +81,9 @@ typedef struct {
|
||||
float prev_sample;
|
||||
} PreEmphasis;
|
||||
|
||||
void init_pre_emphasis(PreEmphasis *pe) {
|
||||
void init_pre_emphasis(PreEmphasis *pe, float sample_rate) {
|
||||
pe->prev_sample = 0.0f;
|
||||
pe->alpha = exp(-1 / (PREEMPHASIS_TAU * SAMPLE_RATE));
|
||||
pe->alpha = exp(-1 / (PREEMPHASIS_TAU * sample_rate));
|
||||
}
|
||||
|
||||
float apply_pre_emphasis(PreEmphasis *pe, float sample) {
|
||||
@@ -100,12 +100,12 @@ typedef struct {
|
||||
int buffer_index;
|
||||
} LowPassFilter;
|
||||
|
||||
void init_low_pass_filter(LowPassFilter *lp) {
|
||||
void init_low_pass_filter(LowPassFilter *lp, float sample_rate) {
|
||||
for (int i = 0; i < FIR_TAPS; i++) {
|
||||
for (int j = 0; j < FIR_PHASES; j++) {
|
||||
int mi = i * FIR_PHASES + j + 1;
|
||||
float sincpos = mi - (((FIR_TAPS * FIR_PHASES) + 1.0f) / 2.0f);
|
||||
float firlowpass = (sincpos == 0.0f) ? 1.0f : sinf(M_2PI * LPF_CUTOFF * sincpos / SAMPLE_RATE) / (PI * sincpos);
|
||||
float firlowpass = (sincpos == 0.0f) ? 1.0f : sinf(M_2PI * LPF_CUTOFF * sincpos / sample_rate) / (PI * sincpos);
|
||||
float window = 0.54f - 0.46f * cosf(M_2PI * mi / (FIR_TAPS * FIR_PHASES)); // Hamming window
|
||||
lp->low_pass_fir[j][i] = firlowpass * window;
|
||||
}
|
||||
@@ -205,13 +205,13 @@ int main() {
|
||||
init_oscillator(&stereo_osc, STEREO_FREQ, SAMPLE_RATE);
|
||||
#ifdef PREEMPHASIS
|
||||
PreEmphasis preemp_l, preemp_r;
|
||||
init_pre_emphasis(&preemp_l);
|
||||
init_pre_emphasis(&preemp_r);
|
||||
init_pre_emphasis(&preemp_l, SAMPLE_RATE);
|
||||
init_pre_emphasis(&preemp_r, SAMPLE_RATE);
|
||||
#endif
|
||||
#ifdef LPF
|
||||
LowPassFilter lpf_l, lpf_r;
|
||||
init_low_pass_filter(&lpf_l);
|
||||
init_low_pass_filter(&lpf_r);
|
||||
init_low_pass_filter(&lpf_l, SAMPLE_RATE);
|
||||
init_low_pass_filter(&lpf_r, SAMPLE_RATE);
|
||||
#endif
|
||||
|
||||
signal(SIGINT, stop);
|
||||
|
||||
Reference in New Issue
Block a user