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

@ -587,7 +587,8 @@ int amps_create(int channel, enum amps_chan_type chan_type, const char *audiodev
amps->pre_emphasis = pre_emphasis;
amps->de_emphasis = de_emphasis;
rc = init_emphasis(&amps->estate, samplerate, CUT_OFF_EMPHASIS_DEFAULT);
/* the AMPS uses a frequency rage of 300..3000 Hz, but we still use the default low pass filter, wich is not too far above */
rc = init_emphasis(&amps->estate, samplerate, CUT_OFF_EMPHASIS_DEFAULT, CUT_OFF_HIGHPASS_DEFAULT, CUT_OFF_LOWPASS_DEFAULT);
if (rc < 0)
goto error;

View File

@ -358,7 +358,7 @@ int cnetz_create(int kanal, enum cnetz_chan_type chan_type, const char *audiodev
cnetz->pre_emphasis = pre_emphasis;
cnetz->de_emphasis = de_emphasis;
rc = init_emphasis(&cnetz->estate, samplerate, CUT_OFF_EMPHASIS_CNETZ);
rc = init_emphasis(&cnetz->estate, samplerate, CUT_OFF_EMPHASIS_CNETZ, CUT_OFF_HIGHPASS_DEFAULT, CUT_OFF_LOWPASS_DEFAULT);
if (rc < 0)
goto error;

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);

View File

@ -142,7 +142,7 @@ int sender_create(sender_t *sender, int kanal, double sendefrequenz, double empf
goto error;
}
rc = init_emphasis(&sender->estate, samplerate, CUT_OFF_EMPHASIS_DEFAULT);
rc = init_emphasis(&sender->estate, samplerate, CUT_OFF_EMPHASIS_DEFAULT, CUT_OFF_HIGHPASS_DEFAULT, CUT_OFF_LOWPASS_DEFAULT);
if (rc < 0)
goto error;

View File

@ -464,7 +464,8 @@ int r2000_create(int band, int channel, enum r2000_chan_type chan_type, const ch
r2000->pre_emphasis = pre_emphasis;
r2000->de_emphasis = de_emphasis;
rc = init_emphasis(&r2000->estate, samplerate, CUT_OFF_EMPHASIS_R2000);
/* we don't know anything about frequency response, so we use NMT defaults */
rc = init_emphasis(&r2000->estate, samplerate, CUT_OFF_EMPHASIS_R2000, CUT_OFF_HIGHPASS_DEFAULT, CUT_OFF_LOWPASS_DEFAULT);
if (rc < 0)
goto error;

View File

@ -45,7 +45,7 @@ int main(void)
double level;
double i;
init_emphasis(&estate, SAMPLERATE, cut_off);
init_emphasis(&estate, SAMPLERATE, cut_off, CUT_OFF_HIGHPASS_DEFAULT, CUT_OFF_LOWPASS_DEFAULT);
printf("testing pre-emphasis filter with cut-off frequency %.1f\n", cut_off);