aboutsummaryrefslogtreecommitdiffstats
path: root/src/bnetz
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2017-01-27 16:57:34 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2017-02-18 21:01:08 +0100
commit7ea3bc188df54a4dbe3026bc30ed39a5cded8fdb (patch)
tree696c78eca5f1676246fed55314c1eab67408c7f4 /src/bnetz
parent538a9591285bdc2604c5e05c06e4b2d776f4bdf9 (diff)
Move samples of int16_t format to sample_t, that is of type double
This prepares the correction of all levels
Diffstat (limited to 'src/bnetz')
-rw-r--r--src/bnetz/bnetz.c5
-rw-r--r--src/bnetz/bnetz.h7
-rw-r--r--src/bnetz/dsp.c33
-rw-r--r--src/bnetz/main.c1
4 files changed, 22 insertions, 24 deletions
diff --git a/src/bnetz/bnetz.c b/src/bnetz/bnetz.c
index fb92ef3..d6f7b1f 100644
--- a/src/bnetz/bnetz.c
+++ b/src/bnetz/bnetz.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include "../common/sample.h"
#include "../common/debug.h"
#include "../common/timer.h"
#include "../common/call.h"
@@ -808,7 +809,7 @@ void call_out_release(int callref, int __attribute__((unused)) cause)
}
/* Receive audio from call instance. */
-void call_rx_audio(int callref, int16_t *samples, int count)
+void call_rx_audio(int callref, sample_t *samples, int count)
{
sender_t *sender;
bnetz_t *bnetz;
@@ -822,7 +823,7 @@ void call_rx_audio(int callref, int16_t *samples, int count)
return;
if (bnetz->dsp_mode == DSP_MODE_AUDIO) {
- int16_t up[(int)((double)count * bnetz->sender.srstate.factor + 0.5) + 10];
+ sample_t up[(int)((double)count * bnetz->sender.srstate.factor + 0.5) + 10];
count = samplerate_upsample(&bnetz->sender.srstate, samples, count, up);
jitter_save(&bnetz->sender.dejitter, up, count);
}
diff --git a/src/bnetz/bnetz.h b/src/bnetz/bnetz.h
index dcd3a87..3ba4b51 100644
--- a/src/bnetz/bnetz.h
+++ b/src/bnetz/bnetz.h
@@ -1,3 +1,4 @@
+#include "../common/goertzel.h"
#include "../common/sender.h"
/* fsk modes of transmission */
@@ -74,9 +75,9 @@ typedef struct bnetz {
/* dsp states */
enum dsp_mode dsp_mode; /* current mode: audio, durable tone 0 or 1, "Telegramm" */
- int fsk_coeff[2]; /* coefficient k = 2*cos(2*PI*f/samplerate), k << 15 */
+ goertzel_t fsk_goertzel[2]; /* filter for fsk decoding */
int samples_per_bit; /* how many samples lasts one bit */
- int16_t *fsk_filter_spl; /* array with samples_per_bit */
+ sample_t *fsk_filter_spl; /* array with samples_per_bit */
int fsk_filter_pos; /* current sample position in filter_spl */
int fsk_filter_step; /* number of samples for each analyzation */
int fsk_filter_bit; /* last bit, so we detect a bit change */
@@ -90,7 +91,7 @@ typedef struct bnetz {
double phaseshift256[2]; /* how much the phase of sine wave changes per sample */
double phase256; /* current phase */
int telegramm; /* set, if there is a valid telegram */
- int16_t *telegramm_spl; /* 16 * samples_per_bit */
+ sample_t *telegramm_spl; /* 16 * samples_per_bit */
int telegramm_pos; /* current sample position in telegramm_spl */
/* loopback test for latency */
diff --git a/src/bnetz/dsp.c b/src/bnetz/dsp.c
index 58a5375..95a78d6 100644
--- a/src/bnetz/dsp.c
+++ b/src/bnetz/dsp.c
@@ -25,10 +25,10 @@
#include <string.h>
#include <errno.h>
#include <math.h>
+#include "../common/sample.h"
#include "../common/debug.h"
#include "../common/timer.h"
#include "../common/call.h"
-#include "../common/goertzel.h"
#include "bnetz.h"
#include "dsp.h"
@@ -54,7 +54,7 @@ static double fsk_bits[2] = {
};
/* table for fast sine generation */
-int dsp_sine[256];
+static sample_t dsp_sine[256];
/* global init for FSK */
void dsp_init(void)
@@ -75,8 +75,7 @@ void dsp_init(void)
/* Init transceiver instance. */
int dsp_init_sender(bnetz_t *bnetz)
{
- double coeff;
- int16_t *spl;
+ sample_t *spl;
int i;
if ((bnetz->sender.samplerate % 1000)) {
@@ -114,10 +113,7 @@ int dsp_init_sender(bnetz_t *bnetz)
/* count symbols */
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(DDSP, DEBUG_DEBUG, "coeff[%d] = %d (must be -3601 and 2573 at 8000hz)\n", i, (int)bnetz->fsk_coeff[i]);
-
+ audio_goertzel_init(&bnetz->fsk_goertzel[i], fsk_bits[i], bnetz->sender.samplerate);
bnetz->phaseshift256[i] = 256.0 / ((double)bnetz->sender.samplerate / fsk_bits[i]);
PDEBUG(DDSP, DEBUG_DEBUG, "phaseshift[%d] = %.4f (must be arround 64 at 8000hz)\n", i, bnetz->phaseshift256[i]);
}
@@ -205,7 +201,7 @@ static inline void fsk_decode_step(bnetz_t *bnetz, int pos)
{
double level, result[2], softbit, quality;
int max;
- int16_t *spl;
+ sample_t *spl;
int bit;
max = bnetz->samples_per_bit;
@@ -216,7 +212,7 @@ static inline void fsk_decode_step(bnetz_t *bnetz, int pos)
if (audio_detect_loss(&bnetz->sender.loss, level))
bnetz_loss_indication(bnetz);
- audio_goertzel(spl, max, pos, bnetz->fsk_coeff, result, 2);
+ audio_goertzel(bnetz->fsk_goertzel, spl, max, pos, result, 2);
/* calculate soft bit from both frequencies */
softbit = (result[1] / level - result[0] / level + 1.0) / 2.0;
@@ -266,10 +262,10 @@ static inline void fsk_decode_step(bnetz_t *bnetz, int pos)
}
/* Process received audio stream from radio unit. */
-void sender_receive(sender_t *sender, int16_t *samples, int length)
+void sender_receive(sender_t *sender, sample_t *samples, int length)
{
bnetz_t *bnetz = (bnetz_t *) sender;
- int16_t *spl;
+ sample_t *spl;
int max, pos, step;
int i;
@@ -290,14 +286,13 @@ void sender_receive(sender_t *sender, int16_t *samples, int length)
bnetz->fsk_filter_pos = pos;
if (bnetz->dsp_mode == DSP_MODE_AUDIO && bnetz->callref) {
- int16_t down[length]; /* more than enough */
int count;
- count = samplerate_downsample(&bnetz->sender.srstate, samples, length, down);
+ count = samplerate_downsample(&bnetz->sender.srstate, samples, length);
spl = bnetz->sender.rxbuf;
pos = bnetz->sender.rxbuf_pos;
for (i = 0; i < count; i++) {
- spl[pos++] = down[i];
+ spl[pos++] = samples[i];
if (pos == 160) {
call_tx_audio(bnetz->callref, spl, 160);
pos = 0;
@@ -308,7 +303,7 @@ void sender_receive(sender_t *sender, int16_t *samples, int length)
bnetz->sender.rxbuf_pos = 0;
}
-static void fsk_tone(bnetz_t *bnetz, int16_t *samples, int length, int tone)
+static void fsk_tone(bnetz_t *bnetz, sample_t *samples, int length, int tone)
{
double phaseshift, phase;
int i;
@@ -326,9 +321,9 @@ static void fsk_tone(bnetz_t *bnetz, int16_t *samples, int length, int tone)
bnetz->phase256 = phase;
}
-static int fsk_telegramm(bnetz_t *bnetz, int16_t *samples, int length)
+static int fsk_telegramm(bnetz_t *bnetz, sample_t *samples, int length)
{
- int16_t *spl;
+ sample_t *spl;
const char *telegramm;
int i, j;
double phaseshift, phase;
@@ -382,7 +377,7 @@ next_telegramm:
}
/* Provide stream of audio toward radio unit */
-void sender_send(sender_t *sender, int16_t *samples, int length)
+void sender_send(sender_t *sender, sample_t *samples, int length)
{
bnetz_t *bnetz = (bnetz_t *) sender;
int len;
diff --git a/src/bnetz/main.c b/src/bnetz/main.c
index e8eb47c..c3a5a9b 100644
--- a/src/bnetz/main.c
+++ b/src/bnetz/main.c
@@ -22,6 +22,7 @@
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
+#include "../common/sample.h"
#include "../common/debug.h"
#include "../common/timer.h"
#include "../common/call.h"