Compandor: Remove unused option for unaffected level
parent
56d8df5351
commit
e9a7f610ee
|
@ -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");
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue