mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-07-30 16:29:15 +02:00
i love correcting tilt, its so simple and straight-forward
This commit is contained in:
+18
-11
@@ -15,17 +15,24 @@ inline float apply_preemphasis(ResistorCapacitor *filter, float sample) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tilt_init(TiltCorrectionFilter* filter, float correction_strength) {
|
void tilt_init(TiltCorrectionFilter* f, float correction_strength, float sr) {
|
||||||
filter->tilt = correction_strength;
|
float cutoff = 1000.0f; // fixed split point
|
||||||
filter->prev_in = 0.0f;
|
|
||||||
filter->prev_out = 0.0f;
|
// 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 tilt(TiltCorrectionFilter* f, float in) {
|
||||||
float out = input + filter->tilt * (input - filter->prev_in);
|
// lowpass
|
||||||
|
f->lp = f->a0 * in + f->a1 * f->lp;
|
||||||
filter->prev_in = input;
|
float hp = in - f->lp;
|
||||||
filter->prev_out = out;
|
return f->lp * f->low_gain + hp * f->high_gain;
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
+6
-5
@@ -14,10 +14,11 @@ void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate, f
|
|||||||
float apply_preemphasis(ResistorCapacitor *filter, float sample);
|
float apply_preemphasis(ResistorCapacitor *filter, float sample);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float tilt; // Tilt amount (-1.0 to +1.0 typical)
|
float a0, a1; // lowpass coeffs
|
||||||
float prev_in; // Previous input sample
|
float lp; // lowpass state
|
||||||
float prev_out; // Previous output sample
|
float low_gain; // gain for low frequencies
|
||||||
|
float high_gain; // gain for high frequencies
|
||||||
} TiltCorrectionFilter;
|
} TiltCorrectionFilter;
|
||||||
|
|
||||||
void tilt_init(TiltCorrectionFilter* filter, float alpha);
|
void tilt_init(TiltCorrectionFilter* f, float correction_strength, float sr);
|
||||||
float tilt(TiltCorrectionFilter *filter, float input);
|
float tilt(TiltCorrectionFilter *f, float in);
|
||||||
|
|||||||
+1
-1
@@ -439,7 +439,7 @@ int setup_audio(FM95_Runtime* runtime, const FM95_DeviceNames dv_names, const FM
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init_runtime(FM95_Runtime* runtime, const FM95_Config config) {
|
void init_runtime(FM95_Runtime* runtime, const FM95_Config config) {
|
||||||
if(config.tilt != 0) tilt_init(&runtime->tilter, config.tilt);
|
if(config.tilt != 0) tilt_init(&runtime->tilter, config.tilt, config.sample_rate);
|
||||||
|
|
||||||
if(config.calibration != 0) {
|
if(config.calibration != 0) {
|
||||||
init_oscillator(&runtime->osc, (config.calibration == 2) ? 60 : 400, config.sample_rate);
|
init_oscillator(&runtime->osc, (config.calibration == 2) ? 60 : 400, config.sample_rate);
|
||||||
|
|||||||
Reference in New Issue
Block a user