Improved emphasis

This commit is contained in:
Andreas Eversberg
2018-01-20 15:49:19 +01:00
parent 50fee02c63
commit 3a5fa8837c
7 changed files with 24 additions and 13 deletions

View File

@@ -27,9 +27,6 @@
#define PI M_PI
#define CUT_OFF_H 100.0 /* cut-off frequency for high-pass filter */
#define CUT_OFF_L 4000.0 /* cut-off frequency for low-pass filter */
static void gen_sine(sample_t *samples, int num, int samplerate, double freq)
{
int i;
@@ -50,7 +47,13 @@ static double get_level(sample_t *samples, int num)
return envelope;
}
int init_emphasis(emphasis_t *state, int samplerate, double cut_off)
/* calculate cut off from time constant in uS */
double timeconstant2cutoff(double time_constant_us)
{
return 1.0 / (2.0 * PI * time_constant_us / 1e6);
}
int init_emphasis(emphasis_t *state, int samplerate, double cut_off, double cut_off_h, double cut_off_l)
{
double factor;
sample_t test_samples[samplerate / 10];
@@ -67,10 +70,12 @@ int init_emphasis(emphasis_t *state, int samplerate, double cut_off)
state->d.amp = 1.0;
/* do not de-emphasis below CUT_OFF_H */
iir_highpass_init(&state->d.hp, CUT_OFF_H, samplerate, 1);
iir_highpass_init(&state->d.hp, cut_off_h, samplerate, 1);
/* do not pre-emphasis above CUT_OFF_L */
iir_lowpass_init(&state->p.lp, CUT_OFF_L, samplerate, 1);
/* do not pre-emphasis above CUT_OFF_L
* Mobile network specifications want -18 dB per octave.
* With two interations we have 24 dB, - 6 dB (from emphasis). */
iir_lowpass_init(&state->p.lp, cut_off_l, samplerate, 2);
/* calibrate amplification to be neutral at 1000 Hz */
gen_sine(test_samples, sizeof(test_samples) / sizeof(test_samples[0]), samplerate, 1000.0);

View File

@@ -15,9 +15,13 @@ typedef struct emphasis {
} d;
} emphasis_t;
/* refers to NMT specs, cnetz uses different emphasis cutoff */
#define CUT_OFF_EMPHASIS_DEFAULT 300.0
#define CUT_OFF_HIGHPASS_DEFAULT 300.0
#define CUT_OFF_LOWPASS_DEFAULT 3400.0
int init_emphasis(emphasis_t *state, int samplerate, double cut_off);
double timeconstant2cutoff(double time_constant_us);
int init_emphasis(emphasis_t *state, int samplerate, double cut_off, double cut_off_h, double cut_off_l);
void pre_emphasis(emphasis_t *state, sample_t *samples, int num);
void de_emphasis(emphasis_t *state, sample_t *samples, int num);
void dc_filter(emphasis_t *state, sample_t *samples, int num);