From e9a7f610eefbc886518cd88284eeecb1ebf8f10c Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 14 Oct 2018 13:07:25 +0200 Subject: Compandor: Remove unused option for unaffected level --- src/amps/dsp.c | 3 +-- src/cnetz/dsp.c | 3 +-- src/libcompandor/compandor.c | 26 ++++++++------------------ src/libcompandor/compandor.h | 4 +--- src/nmt/dsp.c | 3 +-- src/r2000/dsp.c | 3 +-- src/test/test_compandor.c | 2 +- 7 files changed, 14 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/amps/dsp.c b/src/amps/dsp.c index 8f4c84a..1bf8c43 100644 --- a/src/amps/dsp.c +++ b/src/amps/dsp.c @@ -99,7 +99,6 @@ #define PI M_PI -#define COMPANDOR_0DB 1.0 /* A level of 0dBm (1.0) shall be unaccected */ #define AMPS_MAX_DEVIATION 8000.0 #define AMPS_MAX_MODULATION 10000.0 #define AMPS_DBM0_DEVIATION 2900.0 /* deviation of dBm0 at 1 kHz */ @@ -195,7 +194,7 @@ int dsp_init_sender(amps_t *amps, int tolerant) int half; /* attack (3ms) and recovery time (13.5ms) according to amps specs */ - init_compandor(&s->cstate, 8000, 3.0, 13.5, COMPANDOR_0DB); + init_compandor(&s->cstate, 8000, 3.0, 13.5); PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for transceiver.\n"); diff --git a/src/cnetz/dsp.c b/src/cnetz/dsp.c index 38e5f30..f05c883 100644 --- a/src/cnetz/dsp.c +++ b/src/cnetz/dsp.c @@ -43,7 +43,6 @@ #define MAX_DEVIATION 4000.0 #define MAX_MODULATION 3000.0 #define DBM0_DEVIATION 4000.0 /* deviation of dBm0 at 1 kHz */ -#define COMPANDOR_0DB 1.0 /* A level of 0dBm (1.0) shall be unaccected */ #define FSK_DEVIATION (2500.0 / DBM0_DEVIATION) /* no emphasis */ #define MAX_DISPLAY 1.4 /* something above dBm0, no emphasis */ #define BITRATE 5280.0 /* bits per second */ @@ -151,7 +150,7 @@ int dsp_init_sender(cnetz_t *cnetz, int measure_speed, double clock_speed[2], en /* init compandor, according to C-Netz specs, attack and recovery time * shall not exceed according to ITU G.162 */ - init_compandor(&cnetz->cstate, 8000, 5.0, 22.5, COMPANDOR_0DB); + init_compandor(&cnetz->cstate, 8000, 5.0, 22.5); /* use this filter to compensate level changes between two subsequent audio chunks */ RC = 1.0 / (CUT_OFF_OFFSET * 2.0 *3.14); diff --git a/src/libcompandor/compandor.c b/src/libcompandor/compandor.c index 3a2ca9b..b06602e 100644 --- a/src/libcompandor/compandor.c +++ b/src/libcompandor/compandor.c @@ -32,7 +32,7 @@ #define EXPAND_ATTACK_FACTOR 1.145 /* about 0.57 after 6 dB step up */ #define EXPAND_RECOVERY_FACTOR 0.753 /* about 1.51 after 6 dB step down */ -/* Minimum level value to keep state */ +/* Minimum level value to keep state (-60 dB) */ #define ENVELOPE_MIN 0.001 /* Maximum level, to prevent sqrt_tab to overflow */ @@ -46,7 +46,7 @@ static double sqrt_tab[10000]; * Hopefully this is correct * */ -void init_compandor(compandor_t *state, double samplerate, double attack_ms, double recovery_ms, double unaffected_level) +void init_compandor(compandor_t *state, double samplerate, double attack_ms, double recovery_ms) { int i; @@ -60,8 +60,6 @@ void init_compandor(compandor_t *state, double samplerate, double attack_ms, dou state->c.step_down = pow(COMPRESS_RECOVERY_FACTOR, 1000.0 / recovery_ms / samplerate); state->e.step_up = pow(EXPAND_ATTACK_FACTOR, 1000.0 / attack_ms / samplerate); state->e.step_down = pow(EXPAND_RECOVERY_FACTOR, 1000.0 / recovery_ms / samplerate); - state->c.unaffected = unaffected_level; - state->e.unaffected = unaffected_level; // FIXME: make global, not at instance for (i = 0; i < 10000; i++) @@ -70,19 +68,17 @@ void init_compandor(compandor_t *state, double samplerate, double attack_ms, dou void compress_audio(compandor_t *state, sample_t *samples, int num) { - double value, peak, envelope, step_up, step_down, unaffected; + double value, peak, envelope, step_up, step_down; int i; step_up = state->c.step_up; step_down = state->c.step_down; peak = state->c.peak; envelope = state->c.envelope; - unaffected = state->c.unaffected; // printf("envelope=%.4f\n", envelope); for (i = 0; i < num; i++) { - /* normalize sample value to unaffected level */ - value = *samples / unaffected; + value = *samples; /* 'peak' is the level that raises directly with the signal * level, but falls with specified recovery rate. */ @@ -101,11 +97,9 @@ void compress_audio(compandor_t *state, sample_t *samples, int num) if (envelope > ENVELOPE_MAX) envelope = ENVELOPE_MAX; - value = value / sqrt_tab[(int)(envelope / 0.001)]; + *samples++ = value / sqrt_tab[(int)(envelope / 0.001)]; //if (i > 47000.0 && i < 48144) //printf("time=%.4f envelope=%.4fdb, value=%.4f\n", (double)i/48000.0, 20*log10(envelope), value); - - *samples++ = value * unaffected; } //exit(0); @@ -115,18 +109,16 @@ void compress_audio(compandor_t *state, sample_t *samples, int num) void expand_audio(compandor_t *state, sample_t *samples, int num) { - double value, peak, envelope, step_up, step_down, unaffected; + double value, peak, envelope, step_up, step_down; int i; step_up = state->e.step_up; step_down = state->e.step_down; peak = state->e.peak; envelope = state->e.envelope; - unaffected = state->e.unaffected; for (i = 0; i < num; i++) { - /* normalize sample value to 0 DB level */ - value = *samples / unaffected; + value = *samples; /* for comments: see compress_audio() */ if (fabs(value) > peak) @@ -140,9 +132,7 @@ void expand_audio(compandor_t *state, sample_t *samples, int num) if (envelope < ENVELOPE_MIN) envelope = ENVELOPE_MIN; - value = value * envelope; - - *samples++ = value * unaffected; + *samples++ = value * envelope; } state->e.envelope = envelope; diff --git a/src/libcompandor/compandor.h b/src/libcompandor/compandor.h index 25d51ea..e912609 100644 --- a/src/libcompandor/compandor.h +++ b/src/libcompandor/compandor.h @@ -1,14 +1,12 @@ typedef struct compandor { struct { - double unaffected; double step_up; double step_down; double peak; double envelope; } c; struct { - double unaffected; double step_up; double step_down; double peak; @@ -16,7 +14,7 @@ typedef struct compandor { } e; } compandor_t; -void init_compandor(compandor_t *state, double samplerate, double attack_ms, double recovery_ms, double unaffected_level); +void init_compandor(compandor_t *state, double samplerate, double attack_ms, double recovery_ms); void compress_audio(compandor_t *state, sample_t *samples, int num); void expand_audio(compandor_t *state, sample_t *samples, int num); diff --git a/src/nmt/dsp.c b/src/nmt/dsp.c index 1a9c49f..e9e2253 100644 --- a/src/nmt/dsp.c +++ b/src/nmt/dsp.c @@ -55,7 +55,6 @@ #define MAX_DEVIATION 4700.0 #define MAX_MODULATION 4055.0 #define DBM0_DEVIATION 3000.0 /* deviation of dBm0 at 1 kHz */ -#define COMPANDOR_0DB 1.0 /* A level of 0dBm (1.0) shall be unaccected */ #define TX_PEAK_FSK (4200.0 / 1800.0 * 1000.0 / DBM0_DEVIATION) #define TX_PEAK_SUPER (300.0 / 4015.0 * 1000.0 / DBM0_DEVIATION) #define BIT_RATE 1200.0 @@ -110,7 +109,7 @@ int dsp_init_sender(nmt_t *nmt, double deviation_factor) int i; /* attack (3ms) and recovery time (13.5ms) according to NMT specs */ - init_compandor(&nmt->cstate, 8000, 3.0, 13.5, COMPANDOR_0DB); + init_compandor(&nmt->cstate, 8000, 3.0, 13.5); PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for Transceiver.\n"); diff --git a/src/r2000/dsp.c b/src/r2000/dsp.c index 22634aa..fd438e4 100644 --- a/src/r2000/dsp.c +++ b/src/r2000/dsp.c @@ -48,7 +48,6 @@ #define MAX_DEVIATION 2500.0 #define MAX_MODULATION 2550.0 #define DBM0_DEVIATION 1500.0 /* deviation of dBm0 at 1 kHz */ -#define COMPANDOR_0DB 1.0 /* A level of 0dBm (1.0) shall be unaccected */ #define TX_PEAK_FSK (1425.0 / 1500.0 * 1000.0 / DBM0_DEVIATION) /* with emphasis */ #define TX_PEAK_SUPER (300.0 / DBM0_DEVIATION) /* no emphasis */ #define FSK_BIT_RATE 1200.0 @@ -76,7 +75,7 @@ static void super_receive_bit(void *inst, int bit, double quality, double level) int dsp_init_sender(r2000_t *r2000) { /* attack (3ms) and recovery time (13.5ms) according to NMT specs */ - init_compandor(&r2000->cstate, 8000, 3.0, 13.5, COMPANDOR_0DB); + init_compandor(&r2000->cstate, 8000, 3.0, 13.5); PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for Transceiver.\n"); diff --git a/src/test/test_compandor.c b/src/test/test_compandor.c index 4f916a8..b1cd51e 100644 --- a/src/test/test_compandor.c +++ b/src/test/test_compandor.c @@ -72,7 +72,7 @@ int main(void) sample_t samples[SAMPLERATE * 2]; int f; - init_compandor(&cstate, SAMPLERATE, ATTACK_MS, RECOVERY_MS, 1.0); + init_compandor(&cstate, SAMPLERATE, ATTACK_MS, RECOVERY_MS); for (f = 0; f < 3; f++) { /* -16 and -4 dB */ -- cgit v1.2.3