aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2018-01-20 15:49:19 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2018-02-16 15:54:39 +0100
commit3a5fa8837cb6b6c9fefdfc02bbe13473eeef32d1 (patch)
tree0a75be0ba32f053bf6b9dc951b5f0a85ed25073d
parent50fee02c6306c6fb64d967bf226cf5ec20ddc7e1 (diff)
Improved emphasis
-rw-r--r--src/amps/amps.c3
-rw-r--r--src/cnetz/cnetz.c2
-rw-r--r--src/libemphasis/emphasis.c19
-rw-r--r--src/libemphasis/emphasis.h6
-rw-r--r--src/libmobile/sender.c2
-rw-r--r--src/r2000/r2000.c3
-rw-r--r--src/test/test_emphasis.c2
7 files changed, 24 insertions, 13 deletions
diff --git a/src/amps/amps.c b/src/amps/amps.c
index 8420d05..4533da7 100644
--- a/src/amps/amps.c
+++ b/src/amps/amps.c
@@ -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;
diff --git a/src/cnetz/cnetz.c b/src/cnetz/cnetz.c
index 575fcf0..51b5e76 100644
--- a/src/cnetz/cnetz.c
+++ b/src/cnetz/cnetz.c
@@ -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;
diff --git a/src/libemphasis/emphasis.c b/src/libemphasis/emphasis.c
index ed4e2ec..843bb66 100644
--- a/src/libemphasis/emphasis.c
+++ b/src/libemphasis/emphasis.c
@@ -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);
diff --git a/src/libemphasis/emphasis.h b/src/libemphasis/emphasis.h
index 43d54e6..43c8256 100644
--- a/src/libemphasis/emphasis.h
+++ b/src/libemphasis/emphasis.h
@@ -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);
diff --git a/src/libmobile/sender.c b/src/libmobile/sender.c
index 546dcab..a46afbc 100644
--- a/src/libmobile/sender.c
+++ b/src/libmobile/sender.c
@@ -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;
diff --git a/src/r2000/r2000.c b/src/r2000/r2000.c
index 19258b4..16f2087 100644
--- a/src/r2000/r2000.c
+++ b/src/r2000/r2000.c
@@ -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;
diff --git a/src/test/test_emphasis.c b/src/test/test_emphasis.c
index a3198fc..aea6356 100644
--- a/src/test/test_emphasis.c
+++ b/src/test/test_emphasis.c
@@ -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);