From 1ea95de1204d70bb98f117bd5c71bff7b8376c72 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 23 Oct 2016 08:46:05 +0200 Subject: [PATCH] C-Netz: Use emphasis with 200 uS time constant --- src/amps/amps.c | 2 +- src/cnetz/cnetz.c | 4 +++- src/common/emphasis.c | 13 +++++++------ src/common/emphasis.h | 4 +++- src/common/sender.c | 2 +- src/test/test_emphasis.c | 4 ++-- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/amps/amps.c b/src/amps/amps.c index b526237..88cb95d 100644 --- a/src/amps/amps.c +++ b/src/amps/amps.c @@ -422,7 +422,7 @@ int amps_create(int channel, enum amps_chan_type chan_type, const char *sounddev amps->pre_emphasis = pre_emphasis; amps->de_emphasis = de_emphasis; - rc = init_emphasis(&s->estate, samplerate); + rc = init_emphasis(&s->estate, samplerate, CUT_OFF_EMPHASIS_DEFAULT); if (rc < 0) goto error; diff --git a/src/cnetz/cnetz.c b/src/cnetz/cnetz.c index 339362b..49e9430 100644 --- a/src/cnetz/cnetz.c +++ b/src/cnetz/cnetz.c @@ -105,6 +105,8 @@ /* uncomment this to do echo debugging (-L) on Speech Channel */ //#define DEBUG_SPK +#define CUT_OFF_EMPHASIS_CNETZ 796 /* 200 uS time constant */ + /* Call reference for calls from mobile station to network This offset of 0x400000000 is required for MNCC interface. */ static int new_callref = 0x40000000; @@ -286,7 +288,7 @@ int cnetz_create(int kanal, enum cnetz_chan_type chan_type, const char *sounddev cnetz->pre_emphasis = pre_emphasis; cnetz->de_emphasis = de_emphasis; - rc = init_emphasis(&cnetz->estate, samplerate); + rc = init_emphasis(&cnetz->estate, samplerate, CUT_OFF_EMPHASIS_CNETZ); if (rc < 0) goto error; diff --git a/src/common/emphasis.c b/src/common/emphasis.c index 3e753e7..c4a8242 100644 --- a/src/common/emphasis.c +++ b/src/common/emphasis.c @@ -26,10 +26,9 @@ #define PI M_PI -#define CUT_OFF_E 300.0 /* cut-off frequency for emphasis filters */ -#define CUT_OFF_H 300.0 /* cut-off frequency for high-pass filters */ +#define CUT_OFF_H 200.0 /* cut-off frequency for high-pass filters */ -int init_emphasis(emphasis_t *state, int samplerate) +int init_emphasis(emphasis_t *state, int samplerate, double cut_off) { double factor, rc, dt; @@ -40,13 +39,15 @@ int init_emphasis(emphasis_t *state, int samplerate) } /* exp (-2 * PI * CUT_OFF * delta_t) */ - factor = exp(-2.0 * PI * CUT_OFF_E / samplerate); /* 1/samplerate == delta_t */ + factor = exp(-2.0 * PI * cut_off / samplerate); /* 1/samplerate == delta_t */ PDEBUG(DDSP, DEBUG_DEBUG, "Emphasis factor = %.3f\n", factor); state->p.factor = factor; - state->p.amp = samplerate / 6350.0; + state->p.amp = samplerate / 6400.0; state->d.d_factor = factor; - state->d.amp = 1.0 / (samplerate / 5550.0); + state->d.amp = 1.0 / (samplerate / 5750.0); + /* high-pass filter prevents low frequency noise and dc level + * from being amplified by de-emphasis */ rc = 1.0 / (CUT_OFF_H * 2.0 *3.14); dt = 1.0 / samplerate; state->d.h_factor = rc / (rc + dt); diff --git a/src/common/emphasis.h b/src/common/emphasis.h index 119693c..8a631e4 100644 --- a/src/common/emphasis.h +++ b/src/common/emphasis.h @@ -13,7 +13,9 @@ typedef struct emphasis { } d; } emphasis_t; -int init_emphasis(emphasis_t *state, int samplerate); +#define CUT_OFF_EMPHASIS_DEFAULT 300.0 + +int init_emphasis(emphasis_t *state, int samplerate, double cut_off); void pre_emphasis(emphasis_t *state, int16_t *samples, int num); void de_emphasis(emphasis_t *state, int16_t *samples, int num); diff --git a/src/common/sender.c b/src/common/sender.c index caa2689..054e787 100644 --- a/src/common/sender.c +++ b/src/common/sender.c @@ -130,7 +130,7 @@ int sender_create(sender_t *sender, int kanal, const char *sounddev, int sampler } } - rc = init_emphasis(&sender->estate, samplerate); + rc = init_emphasis(&sender->estate, samplerate, CUT_OFF_EMPHASIS_DEFAULT); if (rc < 0) goto error; diff --git a/src/test/test_emphasis.c b/src/test/test_emphasis.c index 5e4720e..036a45e 100644 --- a/src/test/test_emphasis.c +++ b/src/test/test_emphasis.c @@ -11,7 +11,7 @@ #define SAMPLERATE 48000 #define DEVIATION 8000.0 -static double test_freq[] = { 25, 50, 100, 150, 200, 250, 300, 350, 400, 500, 1000, 2000, 4000, 0 }; +static double test_freq[] = { 25, 50, 100, 200, 250, 300, 400, 500, 1000, 2000, 4000, 0 }; static void check_level(int16_t *samples, double freq, const char *desc) { @@ -55,7 +55,7 @@ int main(void) printf("1000 Hz shall be close to 0 dB, that is no significant change in volume.\n\n"); - init_emphasis(&estate, SAMPLERATE); + init_emphasis(&estate, SAMPLERATE, CUT_OFF_EMPHASIS_DEFAULT); for (i = 0; test_freq[i]; i++) { gen_samples(samples, test_freq[i]);