Generate compador table only once when the application starts
This commit is contained in:
@@ -162,6 +162,8 @@ void dsp_init(void)
|
|||||||
}
|
}
|
||||||
dsp_sync_check[0x712] = 0x00; /* no bit error */
|
dsp_sync_check[0x712] = 0x00; /* no bit error */
|
||||||
dsp_sync_check[0x0ed] = 0x80; /* no bit error */
|
dsp_sync_check[0x0ed] = 0x80; /* no bit error */
|
||||||
|
|
||||||
|
compandor_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dsp_init_ramp(amps_t *amps)
|
static void dsp_init_ramp(amps_t *amps)
|
||||||
@@ -194,7 +196,7 @@ int dsp_init_sender(amps_t *amps, int tolerant)
|
|||||||
int half;
|
int half;
|
||||||
|
|
||||||
/* attack (3ms) and recovery time (13.5ms) according to amps specs */
|
/* attack (3ms) and recovery time (13.5ms) according to amps specs */
|
||||||
init_compandor(&s->cstate, 8000, 3.0, 13.5);
|
setup_compandor(&s->cstate, 8000, 3.0, 13.5);
|
||||||
|
|
||||||
PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for transceiver.\n");
|
PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for transceiver.\n");
|
||||||
|
|
||||||
|
@@ -76,6 +76,7 @@ const char *cnetz_dsp_mode_name(enum dsp_mode mode)
|
|||||||
|
|
||||||
void dsp_init(void)
|
void dsp_init(void)
|
||||||
{
|
{
|
||||||
|
compandor_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dsp_init_ramp(cnetz_t *cnetz)
|
static void dsp_init_ramp(cnetz_t *cnetz)
|
||||||
@@ -160,7 +161,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
|
/* init compandor, according to C-Netz specs, attack and recovery time
|
||||||
* shall not exceed according to ITU G.162 */
|
* shall not exceed according to ITU G.162 */
|
||||||
init_compandor(&cnetz->cstate, 8000, 5.0, 22.5);
|
setup_compandor(&cnetz->cstate, 8000, 5.0, 22.5);
|
||||||
|
|
||||||
/* use duration of one bit to ramp level of last frame to current frame */
|
/* use duration of one bit to ramp level of last frame to current frame */
|
||||||
cnetz->offset_range = ceil(cnetz->fsk_bitduration);
|
cnetz->offset_range = ceil(cnetz->fsk_bitduration);
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "../libsample/sample.h"
|
#include "../libsample/sample.h"
|
||||||
@@ -39,6 +40,7 @@
|
|||||||
#define ENVELOPE_MAX 9.990
|
#define ENVELOPE_MAX 9.990
|
||||||
|
|
||||||
static double sqrt_tab[10000];
|
static double sqrt_tab[10000];
|
||||||
|
static int compandor_initalized = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Init compandor according to ITU-T G.162 specification
|
* Init compandor according to ITU-T G.162 specification
|
||||||
@@ -46,10 +48,24 @@ static double sqrt_tab[10000];
|
|||||||
* Hopefully this is correct
|
* Hopefully this is correct
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void init_compandor(compandor_t *state, double samplerate, double attack_ms, double recovery_ms)
|
|
||||||
|
void compandor_init(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
// FIXME: make global, not at instance
|
||||||
|
for (i = 0; i < 10000; i++)
|
||||||
|
sqrt_tab[i] = sqrt(i * 0.001);
|
||||||
|
compandor_initalized = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup_compandor(compandor_t *state, double samplerate, double attack_ms, double recovery_ms)
|
||||||
|
{
|
||||||
|
if (!compandor_initalized) {
|
||||||
|
fprintf(stderr, "Compandor nicht initialized.\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
memset(state, 0, sizeof(*state));
|
memset(state, 0, sizeof(*state));
|
||||||
|
|
||||||
state->c.peak = 1.0;
|
state->c.peak = 1.0;
|
||||||
@@ -60,10 +76,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->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_up = pow(EXPAND_ATTACK_FACTOR, 1000.0 / attack_ms / samplerate);
|
||||||
state->e.step_down = pow(EXPAND_RECOVERY_FACTOR, 1000.0 / recovery_ms / samplerate);
|
state->e.step_down = pow(EXPAND_RECOVERY_FACTOR, 1000.0 / recovery_ms / samplerate);
|
||||||
|
|
||||||
// FIXME: make global, not at instance
|
|
||||||
for (i = 0; i < 10000; i++)
|
|
||||||
sqrt_tab[i] = sqrt(i * 0.001);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void compress_audio(compandor_t *state, sample_t *samples, int num)
|
void compress_audio(compandor_t *state, sample_t *samples, int num)
|
||||||
|
@@ -14,7 +14,8 @@ typedef struct compandor {
|
|||||||
} e;
|
} e;
|
||||||
} compandor_t;
|
} compandor_t;
|
||||||
|
|
||||||
void init_compandor(compandor_t *state, double samplerate, double attack_ms, double recovery_ms);
|
void compandor_init(void);
|
||||||
|
void setup_compandor(compandor_t *state, double samplerate, double attack_ms, double recovery_ms);
|
||||||
void compress_audio(compandor_t *state, sample_t *samples, int num);
|
void compress_audio(compandor_t *state, sample_t *samples, int num);
|
||||||
void expand_audio(compandor_t *state, sample_t *samples, int num);
|
void expand_audio(compandor_t *state, sample_t *samples, int num);
|
||||||
|
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <sys/param.h>
|
||||||
#include "../libsample/sample.h"
|
#include "../libsample/sample.h"
|
||||||
#include "../libdebug/debug.h"
|
#include "../libdebug/debug.h"
|
||||||
#include "../libdisplay/display.h"
|
#include "../libdisplay/display.h"
|
||||||
@@ -246,7 +247,7 @@ static void print_measurements(int on)
|
|||||||
memset(line_color + width - MAX_UNIT_LEN, 4, MAX_UNIT_LEN); /* blue */
|
memset(line_color + width - MAX_UNIT_LEN, 4, MAX_UNIT_LEN); /* blue */
|
||||||
else
|
else
|
||||||
memset(line_color + width - MAX_UNIT_LEN, 3, MAX_UNIT_LEN); /* yellow */
|
memset(line_color + width - MAX_UNIT_LEN, 3, MAX_UNIT_LEN); /* yellow */
|
||||||
strncpy(line + width - MAX_UNIT_LEN + 1, text, (strlen(text) < MAX_UNIT_LEN) ? strlen(text) : MAX_UNIT_LEN);
|
memcpy(line + width - MAX_UNIT_LEN + 1, text, MAX(strlen(text), MAX_UNIT_LEN));
|
||||||
display_line(on, width);
|
display_line(on, width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -97,6 +97,8 @@ void dsp_init(void)
|
|||||||
/* dialtone sine */
|
/* dialtone sine */
|
||||||
dsp_sine_dialtone[i] = s * TX_PEAK_DIALTONE;
|
dsp_sine_dialtone[i] = s * TX_PEAK_DIALTONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compandor_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fsk_send_bit(void *inst);
|
static int fsk_send_bit(void *inst);
|
||||||
@@ -109,7 +111,7 @@ int dsp_init_sender(nmt_t *nmt, double deviation_factor)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* attack (3ms) and recovery time (13.5ms) according to NMT specs */
|
/* attack (3ms) and recovery time (13.5ms) according to NMT specs */
|
||||||
init_compandor(&nmt->cstate, 8000, 3.0, 13.5);
|
setup_compandor(&nmt->cstate, 8000, 3.0, 13.5);
|
||||||
|
|
||||||
PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for Transceiver.\n");
|
PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for Transceiver.\n");
|
||||||
|
|
||||||
|
@@ -64,6 +64,7 @@
|
|||||||
/* global init for FSK */
|
/* global init for FSK */
|
||||||
void dsp_init(void)
|
void dsp_init(void)
|
||||||
{
|
{
|
||||||
|
compandor_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fsk_send_bit(void *inst);
|
static int fsk_send_bit(void *inst);
|
||||||
@@ -75,7 +76,7 @@ static void super_receive_bit(void *inst, int bit, double quality, double level)
|
|||||||
int dsp_init_sender(r2000_t *r2000)
|
int dsp_init_sender(r2000_t *r2000)
|
||||||
{
|
{
|
||||||
/* attack (3ms) and recovery time (13.5ms) according to NMT specs */
|
/* attack (3ms) and recovery time (13.5ms) according to NMT specs */
|
||||||
init_compandor(&r2000->cstate, 8000, 3.0, 13.5);
|
setup_compandor(&r2000->cstate, 8000, 3.0, 13.5);
|
||||||
|
|
||||||
PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for Transceiver.\n");
|
PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for Transceiver.\n");
|
||||||
|
|
||||||
|
@@ -72,7 +72,8 @@ int main(void)
|
|||||||
sample_t samples[SAMPLERATE * 2];
|
sample_t samples[SAMPLERATE * 2];
|
||||||
int f;
|
int f;
|
||||||
|
|
||||||
init_compandor(&cstate, SAMPLERATE, ATTACK_MS, RECOVERY_MS);
|
compandor_init();
|
||||||
|
setup_compandor(&cstate, SAMPLERATE, ATTACK_MS, RECOVERY_MS);
|
||||||
|
|
||||||
for (f = 0; f < 3; f++) {
|
for (f = 0; f < 3; f++) {
|
||||||
/* -16 and -4 dB */
|
/* -16 and -4 dB */
|
||||||
|
Reference in New Issue
Block a user