Improved emphasis
This commit is contained in:
parent
50fee02c63
commit
3a5fa8837c
|
@ -587,7 +587,8 @@ int amps_create(int channel, enum amps_chan_type chan_type, const char *audiodev
|
||||||
|
|
||||||
amps->pre_emphasis = pre_emphasis;
|
amps->pre_emphasis = pre_emphasis;
|
||||||
amps->de_emphasis = de_emphasis;
|
amps->de_emphasis = de_emphasis;
|
||||||
rc = init_emphasis(&s->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(&s->estate, samplerate, CUT_OFF_EMPHASIS_DEFAULT, CUT_OFF_HIGHPASS_DEFAULT, CUT_OFF_LOWPASS_DEFAULT);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
|
|
@ -358,7 +358,7 @@ int cnetz_create(int kanal, enum cnetz_chan_type chan_type, const char *audiodev
|
||||||
|
|
||||||
cnetz->pre_emphasis = pre_emphasis;
|
cnetz->pre_emphasis = pre_emphasis;
|
||||||
cnetz->de_emphasis = de_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)
|
if (rc < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,6 @@
|
||||||
|
|
||||||
#define PI M_PI
|
#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)
|
static void gen_sine(sample_t *samples, int num, int samplerate, double freq)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -50,7 +47,13 @@ static double get_level(sample_t *samples, int num)
|
||||||
return envelope;
|
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;
|
double factor;
|
||||||
sample_t test_samples[samplerate / 10];
|
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;
|
state->d.amp = 1.0;
|
||||||
|
|
||||||
/* do not de-emphasis below CUT_OFF_H */
|
/* 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 */
|
/* do not pre-emphasis above CUT_OFF_L
|
||||||
iir_lowpass_init(&state->p.lp, CUT_OFF_L, samplerate, 1);
|
* 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 */
|
/* calibrate amplification to be neutral at 1000 Hz */
|
||||||
gen_sine(test_samples, sizeof(test_samples) / sizeof(test_samples[0]), samplerate, 1000.0);
|
gen_sine(test_samples, sizeof(test_samples) / sizeof(test_samples[0]), samplerate, 1000.0);
|
||||||
|
|
|
@ -15,9 +15,13 @@ typedef struct emphasis {
|
||||||
} d;
|
} d;
|
||||||
} emphasis_t;
|
} emphasis_t;
|
||||||
|
|
||||||
|
/* refers to NMT specs, cnetz uses different emphasis cutoff */
|
||||||
#define CUT_OFF_EMPHASIS_DEFAULT 300.0
|
#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 pre_emphasis(emphasis_t *state, sample_t *samples, int num);
|
||||||
void de_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);
|
void dc_filter(emphasis_t *state, sample_t *samples, int num);
|
||||||
|
|
|
@ -142,7 +142,7 @@ int sender_create(sender_t *sender, int kanal, double sendefrequenz, double empf
|
||||||
goto error;
|
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)
|
if (rc < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
|
|
@ -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->pre_emphasis = pre_emphasis;
|
||||||
r2000->de_emphasis = de_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)
|
if (rc < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ int main(void)
|
||||||
double level;
|
double level;
|
||||||
double i;
|
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);
|
printf("testing pre-emphasis filter with cut-off frequency %.1f\n", cut_off);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue