From 294a7fe35b628b2c7b8b04e57230e965bfdce449 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Mon, 30 Dec 2024 16:54:25 +0100 Subject: [PATCH] fix preemphasis --- stereo_coder.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stereo_coder.c b/stereo_coder.c index a62190e..514676f 100644 --- a/stereo_coder.c +++ b/stereo_coder.c @@ -70,14 +70,16 @@ float get_next_sample(Oscillator *osc) { #ifdef PREEMPHASIS typedef struct { float prev_sample; + float alpha; } PreEmphasis; void init_pre_emphasis(PreEmphasis *pe) { pe->prev_sample = 0.0f; + pe->alpha = exp(-1 / (PREEMPHASIS_TAU*SAMPLE_RATE)); } float apply_pre_emphasis(PreEmphasis *pe, float sample) { - float output = sample - pe->prev_sample * (1.0f - (1 - exp(-1.0 / (SAMPLE_RATE * PREEMPHASIS_TAU)))); - pe->prev_sample = sample; + float output = sample - pe->alpha * pe->prev_sample; + pe->prev_sample = output; return output; } #endif