fixup debug class definition: rename DFSK and DAUDIO to DDSP

pull/1/head
Andreas Eversberg 7 years ago
parent 57caa536cf
commit a5db02775e
  1. 20
      src/anetz/dsp.c
  2. 28
      src/bnetz/dsp.c
  3. 3
      src/common/debug.c
  4. 15
      src/common/debug.h
  5. 2
      src/common/jitter.c
  6. 6
      src/common/loss.c
  7. 38
      src/nmt/dsp.c

@ -60,7 +60,7 @@ void dsp_init(void)
{
int i;
PDEBUG(DFSK, DEBUG_DEBUG, "Generating sine table.\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Generating sine table.\n");
for (i = 0; i < 256; i++) {
dsp_sine[i] = (int)(sin((double)i / 256.0 * 2.0 * PI) * TX_PEAK);
}
@ -78,15 +78,15 @@ int dsp_init_sender(anetz_t *anetz)
double coeff;
int detect_tone = (anetz->sender.loopback) ? 0 : 1;
PDEBUG(DFSK, DEBUG_DEBUG, "Init DSP for 'Sender'.\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Init DSP for 'Sender'.\n");
audio_init_loss(&anetz->sender.loss, LOSS_INTERVAL, anetz->sender.loss_volume, LOSS_TIME);
anetz->samples_per_chunk = anetz->sender.samplerate * CHUNK_DURATION;
PDEBUG(DFSK, DEBUG_DEBUG, "Using %d samples per chunk duration.\n", anetz->samples_per_chunk);
PDEBUG(DDSP, DEBUG_DEBUG, "Using %d samples per chunk duration.\n", anetz->samples_per_chunk);
spl = calloc(1, anetz->samples_per_chunk << 1);
if (!spl) {
PDEBUG(DFSK, DEBUG_ERROR, "No memory!\n");
PDEBUG(DDSP, DEBUG_ERROR, "No memory!\n");
return -ENOMEM;
}
anetz->fsk_filter_spl = spl;
@ -95,9 +95,9 @@ int dsp_init_sender(anetz_t *anetz)
coeff = 2.0 * cos(2.0 * PI * fsk_tones[detect_tone] / (double)anetz->sender.samplerate);
anetz->fsk_tone_coeff = coeff * 32768.0;
PDEBUG(DFSK, DEBUG_DEBUG, "RX %.0f Hz coeff = %d\n", fsk_tones[detect_tone], (int)anetz->fsk_tone_coeff);
PDEBUG(DDSP, DEBUG_DEBUG, "RX %.0f Hz coeff = %d\n", fsk_tones[detect_tone], (int)anetz->fsk_tone_coeff);
anetz->tone_phaseshift256 = 256.0 / ((double)anetz->sender.samplerate / fsk_tones[0]);
PDEBUG(DFSK, DEBUG_DEBUG, "TX %.0f Hz phaseshift = %.4f\n", fsk_tones[0], anetz->tone_phaseshift256);
PDEBUG(DDSP, DEBUG_DEBUG, "TX %.0f Hz phaseshift = %.4f\n", fsk_tones[0], anetz->tone_phaseshift256);
return 0;
}
@ -105,7 +105,7 @@ int dsp_init_sender(anetz_t *anetz)
/* Cleanup transceiver instance. */
void dsp_cleanup_sender(anetz_t *anetz)
{
PDEBUG(DFSK, DEBUG_DEBUG, "Cleanup DSP for 'Sender'.\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Cleanup DSP for 'Sender'.\n");
if (anetz->fsk_filter_spl) {
free(anetz->fsk_filter_spl);
@ -119,7 +119,7 @@ static void fsk_receive_tone(anetz_t *anetz, int tone, int goodtone, double leve
/* lost tone because it is not good anymore or has changed */
if (!goodtone || tone != anetz->tone_detected) {
if (anetz->tone_count >= TONE_DETECT_TH) {
PDEBUG(DFSK, DEBUG_DEBUG, "Lost %.0f Hz tone after %d ms.\n", fsk_tones[anetz->tone_detected], 1000.0 * CHUNK_DURATION * anetz->tone_count);
PDEBUG(DDSP, DEBUG_DEBUG, "Lost %.0f Hz tone after %d ms.\n", fsk_tones[anetz->tone_detected], 1000.0 * CHUNK_DURATION * anetz->tone_count);
anetz_receive_tone(anetz, -1);
}
if (goodtone)
@ -136,7 +136,7 @@ static void fsk_receive_tone(anetz_t *anetz, int tone, int goodtone, double leve
if (anetz->tone_count >= TONE_DETECT_TH)
audio_reset_loss(&anetz->sender.loss);
if (anetz->tone_count == TONE_DETECT_TH) {
PDEBUG(DFSK, DEBUG_DEBUG, "Detecting continous %.0f Hz tone. (level = %d%%)\n", fsk_tones[anetz->tone_detected], (int)(level * 100));
PDEBUG(DDSP, DEBUG_DEBUG, "Detecting continous %.0f Hz tone. (level = %d%%)\n", fsk_tones[anetz->tone_detected], (int)(level * 100));
anetz_receive_tone(anetz, anetz->tone_detected);
}
}
@ -156,7 +156,7 @@ static void fsk_decode_chunk(anetz_t *anetz, int16_t *spl, int max)
/* show quality of tone */
if (anetz->sender.loopback) {
/* adjust level, so we get peak of sine curve */
PDEBUG(DFSK, DEBUG_NOTICE, "Quality Tone:%3.0f%% Level:%3.0f%%\n", result / level * 100.0, level / 0.63662 * 100.0);
PDEBUG(DDSP, DEBUG_NOTICE, "Quality Tone:%3.0f%% Level:%3.0f%%\n", result / level * 100.0, level / 0.63662 * 100.0);
}
/* adjust level, so we get peak of sine curve */

@ -58,7 +58,7 @@ void dsp_init(void)
{
int i;
PDEBUG(DFSK, DEBUG_DEBUG, "Generating sine table.\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Generating sine table.\n");
for (i = 0; i < 256; i++) {
dsp_sine[i] = (int)(sin((double)i / 256.0 * 2.0 * PI) * TX_PEAK);
}
@ -72,27 +72,27 @@ int dsp_init_sender(bnetz_t *bnetz)
int i;
if ((bnetz->sender.samplerate % 1000)) {
PDEBUG(DFSK, DEBUG_ERROR, "Samples rate must be a multiple of 1000 bits per second.\n");
PDEBUG(DDSP, DEBUG_ERROR, "Samples rate must be a multiple of 1000 bits per second.\n");
return -EINVAL;
}
PDEBUG(DFSK, DEBUG_DEBUG, "Init DSP for 'Sender'.\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Init DSP for 'Sender'.\n");
audio_init_loss(&bnetz->sender.loss, LOSS_INTERVAL, bnetz->sender.loss_volume, LOSS_TIME);
bnetz->samples_per_bit = bnetz->sender.samplerate * BIT_DURATION;
PDEBUG(DFSK, DEBUG_DEBUG, "Using %d samples per bit duration.\n", bnetz->samples_per_bit);
PDEBUG(DDSP, DEBUG_DEBUG, "Using %d samples per bit duration.\n", bnetz->samples_per_bit);
bnetz->fsk_filter_step = bnetz->sender.samplerate * FILTER_STEP;
PDEBUG(DFSK, DEBUG_DEBUG, "Using %d samples per filter step.\n", bnetz->fsk_filter_step);
PDEBUG(DDSP, DEBUG_DEBUG, "Using %d samples per filter step.\n", bnetz->fsk_filter_step);
spl = calloc(16, bnetz->samples_per_bit * sizeof(*spl));
if (!spl) {
PDEBUG(DFSK, DEBUG_ERROR, "No memory!\n");
PDEBUG(DDSP, DEBUG_ERROR, "No memory!\n");
return -ENOMEM;
}
bnetz->telegramm_spl = spl;
spl = calloc(1, bnetz->samples_per_bit * sizeof(*spl));
if (!spl) {
PDEBUG(DFSK, DEBUG_ERROR, "No memory!\n");
PDEBUG(DDSP, DEBUG_ERROR, "No memory!\n");
return -ENOMEM;
}
bnetz->fsk_filter_spl = spl;
@ -104,10 +104,10 @@ int dsp_init_sender(bnetz_t *bnetz)
for (i = 0; i < 2; i++) {
coeff = 2.0 * cos(2.0 * PI * fsk_bits[i] / (double)bnetz->sender.samplerate);
bnetz->fsk_coeff[i] = coeff * 32768.0;
PDEBUG(DFSK, DEBUG_DEBUG, "coeff[%d] = %d (must be -3601 and 2573 at 8000hz)\n", i, (int)bnetz->fsk_coeff[i]);
PDEBUG(DDSP, DEBUG_DEBUG, "coeff[%d] = %d (must be -3601 and 2573 at 8000hz)\n", i, (int)bnetz->fsk_coeff[i]);
bnetz->phaseshift256[i] = 256.0 / ((double)bnetz->sender.samplerate / fsk_bits[i]);
PDEBUG(DFSK, DEBUG_DEBUG, "phaseshift[%d] = %.4f (must be arround 64 at 8000hz)\n", i, bnetz->phaseshift256[i]);
PDEBUG(DDSP, DEBUG_DEBUG, "phaseshift[%d] = %.4f (must be arround 64 at 8000hz)\n", i, bnetz->phaseshift256[i]);
}
return 0;
@ -116,7 +116,7 @@ int dsp_init_sender(bnetz_t *bnetz)
/* Cleanup transceiver instance. */
void dsp_cleanup_sender(bnetz_t *bnetz)
{
PDEBUG(DFSK, DEBUG_DEBUG, "Cleanup DSP for 'Sender'.\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Cleanup DSP for 'Sender'.\n");
if (bnetz->telegramm_spl) {
free(bnetz->telegramm_spl);
@ -134,7 +134,7 @@ static void fsk_receive_tone(bnetz_t *bnetz, int bit, int goodtone, double level
/* lost tone because it is not good anymore or has changed */
if (!goodtone || bit != bnetz->tone_detected) {
if (bnetz->tone_count >= TONE_DETECT_TH) {
PDEBUG(DFSK, DEBUG_DEBUG, "Lost %.0f Hz tone after %d ms.\n", fsk_bits[bnetz->tone_detected], bnetz->tone_count);
PDEBUG(DDSP, DEBUG_DEBUG, "Lost %.0f Hz tone after %d ms.\n", fsk_bits[bnetz->tone_detected], bnetz->tone_count);
bnetz_receive_tone(bnetz, -1);
}
if (goodtone)
@ -151,7 +151,7 @@ static void fsk_receive_tone(bnetz_t *bnetz, int bit, int goodtone, double level
if (bnetz->tone_count >= TONE_DETECT_TH)
audio_reset_loss(&bnetz->sender.loss);
if (bnetz->tone_count == TONE_DETECT_TH) {
PDEBUG(DFSK, DEBUG_DEBUG, "Detecting continous %.0f Hz tone. (level = %d%%)\n", fsk_bits[bnetz->tone_detected], (int)(level * 100));
PDEBUG(DDSP, DEBUG_DEBUG, "Detecting continous %.0f Hz tone. (level = %d%%)\n", fsk_bits[bnetz->tone_detected], (int)(level * 100));
bnetz_receive_tone(bnetz, bnetz->tone_detected);
}
}
@ -339,10 +339,10 @@ static int fsk_telegramm(bnetz_t *bnetz, int16_t *samples, int length)
next_telegramm:
if (!bnetz->telegramm) {
/* request telegramm */
// PDEBUG(DFSK, DEBUG_DEBUG, "Request new 'Telegramm'.\n");
// PDEBUG(DDSP, DEBUG_DEBUG, "Request new 'Telegramm'.\n");
telegramm = bnetz_get_telegramm(bnetz);
if (!telegramm) {
PDEBUG(DFSK, DEBUG_DEBUG, "Stop sending 'Telegramm'.\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Stop sending 'Telegramm'.\n");
return length;
}
bnetz->telegramm = 1;

@ -35,8 +35,7 @@ struct debug_cat {
} debug_cat[] = {
{ "sender", "\033[1;33m" },
{ "sound", "\033[0;35m" },
{ "fsk", "\033[0;31m" },
{ "audio", "\033[0;31m" },
{ "dsp", "\033[0;31m" },
{ "anetz", "\033[1;34m" },
{ "bnetz", "\033[1;34m" },
{ "nmt", "\033[1;34m" },

@ -6,14 +6,13 @@
#define DSENDER 0
#define DSOUND 1
#define DFSK 2
#define DAUDIO 3
#define DANETZ 4
#define DBNETZ 5
#define DNMT 6
#define DFRAME 7
#define DCALL 8
#define DMNCC 9
#define DDSP 2
#define DANETZ 3
#define DBNETZ 4
#define DNMT 5
#define DFRAME 6
#define DCALL 7
#define DMNCC 8
#define PDEBUG(cat, level, fmt, arg...) _printdebug(__FILE__, __FUNCTION__, __LINE__, cat, level, fmt, ## arg)
void _printdebug(const char *file, const char *function, int line, int cat, int level, const char *fmt, ...);

@ -31,7 +31,7 @@ int jitter_create(jitter_t *jitter, int length)
memset(jitter, 0, sizeof(jitter));
jitter->spl = calloc(length * sizeof(int16_t), 1);
if (!jitter->spl) {
PDEBUG(DAUDIO, DEBUG_ERROR, "No memory for jitter buffer.\n");
PDEBUG(DDSP, DEBUG_ERROR, "No memory for jitter buffer.\n");
return -ENOMEM;
}
jitter->len = length;

@ -44,7 +44,7 @@ void audio_init_loss(loss_t *loss, int interval, double threshold, int seconds)
void audio_reset_loss(loss_t *loss)
{
if (loss->interval_count > 0) {
PDEBUG(DAUDIO, DEBUG_DEBUG, "Signal is recovered (loss is gone).\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Signal is recovered (loss is gone).\n");
loss->interval_count = 0;
}
loss->level = 0;
@ -71,7 +71,7 @@ int audio_detect_loss(loss_t *loss, double level)
/* normalize level */
loss->level = loss->level / loss->level_count;
PDEBUG(DAUDIO, DEBUG_DEBUG, "Noise level = %.0f%%\n", loss->level * 100);
PDEBUG(DDSP, DEBUG_DEBUG, "Noise level = %.0f%%\n", loss->level * 100);
diff = loss->level / loss->level_last;
if (diff < 1.0)
@ -81,7 +81,7 @@ int audio_detect_loss(loss_t *loss, double level)
loss->level_count = 0;
if (diff < LOSS_MAX_DIFF && loss->level_last > loss->threshold) {
loss->interval_count++;
PDEBUG(DAUDIO, DEBUG_DEBUG, "Detected signal loss %d for intervals level change %.0f%% (below %.0f%%).\n", loss->interval_count, diff * 100 - 100, LOSS_MAX_DIFF * 100 - 100);
PDEBUG(DDSP, DEBUG_DEBUG, "Detected signal loss %d for intervals level change %.0f%% (below %.0f%%).\n", loss->interval_count, diff * 100 - 100, LOSS_MAX_DIFF * 100 - 100);
} else if (loss->interval_count > 0) {
audio_reset_loss(loss);
}

@ -68,7 +68,7 @@ void dsp_init(void)
int i;
double s;
PDEBUG(DFSK, DEBUG_DEBUG, "Generating sine table for supervisory signal.\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Generating sine table for supervisory signal.\n");
for (i = 0; i < 256; i++) {
s = sin((double)i / 256.0 * 2.0 * PI);
dsp_sine_super[i] = (int)(s * TX_PEAK_SUPER);
@ -86,29 +86,29 @@ int dsp_init_sender(nmt_t *nmt)
init_compander(&nmt->cstate, 8000, 3.0, 13.5);
if ((nmt->sender.samplerate % (BIT_RATE * STEPS_PER_BIT))) {
PDEBUG(DFSK, DEBUG_ERROR, "Sample rate must be a multiple of %d bits per second.\n", BIT_RATE * STEPS_PER_BIT);
PDEBUG(DDSP, DEBUG_ERROR, "Sample rate must be a multiple of %d bits per second.\n", BIT_RATE * STEPS_PER_BIT);
return -EINVAL;
}
/* this should not happen. it is implied by previous check */
if (nmt->supervisory && nmt->sender.samplerate < 12000) {
PDEBUG(DFSK, DEBUG_ERROR, "Sample rate must be at least 12000 Hz to process supervisory signal.\n");
PDEBUG(DDSP, DEBUG_ERROR, "Sample rate must be at least 12000 Hz to process supervisory signal.\n");
return -EINVAL;
}
PDEBUG(DFSK, DEBUG_DEBUG, "Init DSP for Transceiver.\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Init DSP for Transceiver.\n");
/* allocate sample for 2 bits with 2 polarities */
nmt->samples_per_bit = nmt->sender.samplerate / BIT_RATE;
PDEBUG(DFSK, DEBUG_DEBUG, "Using %d samples per bit duration.\n", nmt->samples_per_bit);
PDEBUG(DDSP, DEBUG_DEBUG, "Using %d samples per bit duration.\n", nmt->samples_per_bit);
nmt->fsk_filter_step = nmt->samples_per_bit / STEPS_PER_BIT;
PDEBUG(DFSK, DEBUG_DEBUG, "Using %d samples per filter step.\n", nmt->fsk_filter_step);
PDEBUG(DDSP, DEBUG_DEBUG, "Using %d samples per filter step.\n", nmt->fsk_filter_step);
nmt->fsk_sine[0][0] = calloc(4, nmt->samples_per_bit * sizeof(int16_t));
nmt->fsk_sine[0][1] = nmt->fsk_sine[0][0] + nmt->samples_per_bit;
nmt->fsk_sine[1][0] = nmt->fsk_sine[0][1] + nmt->samples_per_bit;
nmt->fsk_sine[1][1] = nmt->fsk_sine[1][0] + nmt->samples_per_bit;
if (!nmt->fsk_sine[0][0]) {
PDEBUG(DFSK, DEBUG_ERROR, "No memory!\n");
PDEBUG(DDSP, DEBUG_ERROR, "No memory!\n");
return -ENOMEM;
}
@ -123,7 +123,7 @@ int dsp_init_sender(nmt_t *nmt)
/* allocate ring buffers, one bit duration */
spl = calloc(1, nmt->samples_per_bit * sizeof(*spl));
if (!spl) {
PDEBUG(DFSK, DEBUG_ERROR, "No memory!\n");
PDEBUG(DDSP, DEBUG_ERROR, "No memory!\n");
return -ENOMEM;
}
nmt->fsk_filter_spl = spl;
@ -132,7 +132,7 @@ int dsp_init_sender(nmt_t *nmt)
/* allocate transmit buffer for a complete frame */
spl = calloc(166, nmt->samples_per_bit * sizeof(*spl));
if (!spl) {
PDEBUG(DFSK, DEBUG_ERROR, "No memory!\n");
PDEBUG(DDSP, DEBUG_ERROR, "No memory!\n");
return -ENOMEM;
}
nmt->frame_spl = spl;
@ -141,7 +141,7 @@ int dsp_init_sender(nmt_t *nmt)
nmt->super_samples = (int)((double)nmt->sender.samplerate * SUPER_DURATION + 0.5);
spl = calloc(166, nmt->super_samples * sizeof(*spl));
if (!spl) {
PDEBUG(DFSK, DEBUG_ERROR, "No memory!\n");
PDEBUG(DDSP, DEBUG_ERROR, "No memory!\n");
return -ENOMEM;
}
nmt->super_filter_spl = spl;
@ -150,18 +150,18 @@ int dsp_init_sender(nmt_t *nmt)
for (i = 0; i < 2; i++) {
coeff = 2.0 * cos(2.0 * PI * fsk_bits[i] / (double)nmt->sender.samplerate);
nmt->fsk_coeff[i] = coeff * 32768.0;
PDEBUG(DFSK, DEBUG_DEBUG, "coeff[%d] = %d\n", i, (int)nmt->fsk_coeff[i]);
PDEBUG(DDSP, DEBUG_DEBUG, "coeff[%d] = %d\n", i, (int)nmt->fsk_coeff[i]);
}
/* count supervidory tones */
for (i = 0; i < 5; i++) {
coeff = 2.0 * cos(2.0 * PI * super_freq[i] / (double)nmt->sender.samplerate);
nmt->super_coeff[i] = coeff * 32768.0;
PDEBUG(DFSK, DEBUG_DEBUG, "supervisory coeff[%d] = %d\n", i, (int)nmt->super_coeff[i]);
PDEBUG(DDSP, DEBUG_DEBUG, "supervisory coeff[%d] = %d\n", i, (int)nmt->super_coeff[i]);
if (i < 4) {
nmt->super_phaseshift256[i] = 256.0 / ((double)nmt->sender.samplerate / super_freq[i]);
PDEBUG(DFSK, DEBUG_DEBUG, "phaseshift_super[%d] = %.4f\n", i, nmt->super_phaseshift256[i]);
PDEBUG(DDSP, DEBUG_DEBUG, "phaseshift_super[%d] = %.4f\n", i, nmt->super_phaseshift256[i]);
}
}
super_reset(nmt);
@ -178,7 +178,7 @@ int dsp_init_sender(nmt_t *nmt)
/* Cleanup transceiver instance. */
void dsp_cleanup_sender(nmt_t *nmt)
{
PDEBUG(DFSK, DEBUG_DEBUG, "Cleanup DSP for 'Sender'.\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Cleanup DSP for 'Sender'.\n");
if (nmt->frame_spl) {
free(nmt->frame_spl);
@ -348,14 +348,14 @@ static void super_decode(nmt_t *nmt, int16_t *samples, int length)
quality = 0;
if (nmt->sender.loopback)
PDEBUG(DFSK, DEBUG_NOTICE, "Supervisory level %.2f%% quality %.0f%%\n", result[0] / 0.63662 * 100.0, quality * 100.0);
PDEBUG(DDSP, DEBUG_NOTICE, "Supervisory level %.2f%% quality %.0f%%\n", result[0] / 0.63662 * 100.0, quality * 100.0);
if (quality > 0.5) {
if (nmt->super_detected == 0) {
nmt->super_detect_count++;
if (nmt->super_detect_count == SUPER_DETECT_COUNT) {
nmt->super_detected = 1;
nmt->super_detect_count = 0;
PDEBUG(DFSK, DEBUG_DEBUG, "Supervisory signal detected with level=%.0f%%, quality=%.0f%%.\n", result[0] / 0.63662 * 100.0, quality * 100.0);
PDEBUG(DDSP, DEBUG_DEBUG, "Supervisory signal detected with level=%.0f%%, quality=%.0f%%.\n", result[0] / 0.63662 * 100.0, quality * 100.0);
nmt_rx_super(nmt, 1, quality);
}
} else
@ -366,7 +366,7 @@ static void super_decode(nmt_t *nmt, int16_t *samples, int length)
if (nmt->super_detect_count == SUPER_DETECT_COUNT) {
nmt->super_detected = 0;
nmt->super_detect_count = 0;
PDEBUG(DFSK, DEBUG_DEBUG, "Supervisory signal lost.\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Supervisory signal lost.\n");
nmt_rx_super(nmt, 0, 0.0);
}
} else
@ -377,7 +377,7 @@ static void super_decode(nmt_t *nmt, int16_t *samples, int length)
/* Reset supervisory detection states, so ongoing tone will be detected again. */
void super_reset(nmt_t *nmt)
{
PDEBUG(DFSK, DEBUG_DEBUG, "Supervisory detector reset.\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Supervisory detector reset.\n");
nmt->super_detected = 0;
nmt->super_detect_count = 0;
}
@ -464,7 +464,7 @@ next_frame:
/* request frame */
frame = nmt_get_frame(nmt);
if (!frame) {
PDEBUG(DFSK, DEBUG_DEBUG, "Stop sending frames.\n");
PDEBUG(DDSP, DEBUG_DEBUG, "Stop sending frames.\n");
return length;
}
nmt->frame = 1;

Loading…
Cancel
Save