mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-27 03:23:54 +01:00
i love correcting tilt, its so simple and straight-forward
This commit is contained in:
29
filter/iir.c
29
filter/iir.c
@@ -15,17 +15,24 @@ inline float apply_preemphasis(ResistorCapacitor *filter, float sample) {
|
||||
return out;
|
||||
}
|
||||
|
||||
void tilt_init(TiltCorrectionFilter* filter, float correction_strength) {
|
||||
filter->tilt = correction_strength;
|
||||
filter->prev_in = 0.0f;
|
||||
filter->prev_out = 0.0f;
|
||||
void tilt_init(TiltCorrectionFilter* f, float correction_strength, float sr) {
|
||||
float cutoff = 1000.0f; // fixed split point
|
||||
|
||||
// one-pole lowpass setup
|
||||
float alpha = expf(-2.0f * (float)M_PI * cutoff / sr);
|
||||
f->a1 = alpha;
|
||||
f->a0 = 1.0f - alpha;
|
||||
f->lp = 0.0f;
|
||||
|
||||
// simple low/high gains from tilt
|
||||
float t = (tilt < -1.0f) ? -1.0f : (tilt > 1.0f ? 1.0f : tilt);
|
||||
f->low_gain = 1.0f - t;
|
||||
f->high_gain = 1.0f + t;
|
||||
}
|
||||
|
||||
float tilt(TiltCorrectionFilter* filter, float input) {
|
||||
float out = input + filter->tilt * (input - filter->prev_in);
|
||||
|
||||
filter->prev_in = input;
|
||||
filter->prev_out = out;
|
||||
|
||||
return out;
|
||||
float tilt(TiltCorrectionFilter* f, float in) {
|
||||
// lowpass
|
||||
f->lp = f->a0 * in + f->a1 * f->lp;
|
||||
float hp = in - f->lp;
|
||||
return f->lp * f->low_gain + hp * f->high_gain;
|
||||
}
|
||||
11
filter/iir.h
11
filter/iir.h
@@ -14,10 +14,11 @@ void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate, f
|
||||
float apply_preemphasis(ResistorCapacitor *filter, float sample);
|
||||
|
||||
typedef struct {
|
||||
float tilt; // Tilt amount (-1.0 to +1.0 typical)
|
||||
float prev_in; // Previous input sample
|
||||
float prev_out; // Previous output sample
|
||||
float a0, a1; // lowpass coeffs
|
||||
float lp; // lowpass state
|
||||
float low_gain; // gain for low frequencies
|
||||
float high_gain; // gain for high frequencies
|
||||
} TiltCorrectionFilter;
|
||||
|
||||
void tilt_init(TiltCorrectionFilter* filter, float alpha);
|
||||
float tilt(TiltCorrectionFilter *filter, float input);
|
||||
void tilt_init(TiltCorrectionFilter* f, float correction_strength, float sr);
|
||||
float tilt(TiltCorrectionFilter *f, float in);
|
||||
|
||||
Reference in New Issue
Block a user