mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
do the preemp gain properly, set a refrence freq (+0db) sligthly above the LPF cutoff, thus we avoid clipping
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
#include "filters.h"
|
||||
|
||||
void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate) {
|
||||
float dt = 1.0f / sample_rate;
|
||||
filter->alpha = tau / (tau + dt);
|
||||
filter->gain = 1.0f / sqrtf(1.0f - filter->alpha);
|
||||
void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate, float ref_freq) {
|
||||
float dt = 1.0f / sample_rate;
|
||||
filter->alpha = tau / (tau + dt);
|
||||
|
||||
filter->prev_sample = 0.0f;
|
||||
float omega = 2.0f * M_PI * ref_freq / sample_rate;
|
||||
float cos_omega = cosf(omega);
|
||||
|
||||
float numerator = sqrtf(1.0f + filter->alpha * filter->alpha - 2.0f * filter->alpha * cos_omega);
|
||||
|
||||
filter->gain = 1.0f / numerator;
|
||||
|
||||
filter->prev_sample = 0.0f;
|
||||
}
|
||||
inline float apply_preemphasis(ResistorCapacitor *filter, float sample) {
|
||||
float out = (sample - filter->alpha * filter->prev_sample) * filter->gain;
|
||||
|
||||
@@ -10,5 +10,5 @@ typedef struct
|
||||
float gain;
|
||||
} ResistorCapacitor;
|
||||
|
||||
void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate);
|
||||
void init_preemphasis(ResistorCapacitor *filter, float tau, float sample_rate, float ref_freq);
|
||||
float apply_preemphasis(ResistorCapacitor *filter, float sample);
|
||||
|
||||
@@ -392,8 +392,8 @@ int main(int argc, char **argv) {
|
||||
iirfilt_rrrf mpx_lpf = iirfilt_rrrf_create_prototype(LIQUID_IIRDES_BUTTER, LIQUID_IIRDES_LOWPASS, LIQUID_IIRDES_SOS, 1, (polar_stereo ? (46250.0f/sample_rate) : (53000.0f/sample_rate)), 0.0f, 1.0f, 1.0f);
|
||||
|
||||
ResistorCapacitor preemp_l, preemp_r;
|
||||
init_preemphasis(&preemp_l, preemphasis_tau, sample_rate);
|
||||
init_preemphasis(&preemp_r, preemphasis_tau, sample_rate);
|
||||
init_preemphasis(&preemp_l, preemphasis_tau, sample_rate, 15100.0f);
|
||||
init_preemphasis(&preemp_r, preemphasis_tau, sample_rate, 15100.0f);
|
||||
|
||||
MPXPowerMeasurement power;
|
||||
init_modulation_power_measure(&power, sample_rate);
|
||||
|
||||
Reference in New Issue
Block a user