aboutsummaryrefslogtreecommitdiffstats
path: root/src/mpt1327/dsp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mpt1327/dsp.c')
-rw-r--r--src/mpt1327/dsp.c71
1 files changed, 53 insertions, 18 deletions
diff --git a/src/mpt1327/dsp.c b/src/mpt1327/dsp.c
index 4b6b7dc..a318d2a 100644
--- a/src/mpt1327/dsp.c
+++ b/src/mpt1327/dsp.c
@@ -27,8 +27,8 @@
#include <math.h>
#include "../libsample/sample.h"
#include "../libmobile/call.h"
-#include "../libdebug/debug.h"
-#include "../libtimer/timer.h"
+#include "../liblogging/logging.h"
+#include <osmocom/core/timer.h>
#include "mpt1327.h"
#include "dsp.h"
#include "message.h"
@@ -61,7 +61,7 @@ int dsp_init_sender(mpt1327_t *mpt1327, double squelch_db)
{
int rc;
- PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Init DSP for Transceiver.\n");
+ LOGP_CHAN(DDSP, LOGL_DEBUG, "Init DSP for Transceiver.\n");
/* init squelch */
squelch_init(&mpt1327->squelch, mpt1327->sender.kanal, squelch_db, MUTE_TIME, MUTE_TIME);
@@ -69,15 +69,15 @@ int dsp_init_sender(mpt1327_t *mpt1327, double squelch_db)
/* set modulation parameters */
sender_set_fm(&mpt1327->sender, MAX_DEVIATION, MAX_MODULATION, SPEECH_DEVIATION, MAX_DISPLAY);
- PDEBUG(DDSP, DEBUG_DEBUG, "Using FSK level of %.3f (%.3f KHz deviation)\n", TX_PEAK_FSK, SPEECH_DEVIATION * TX_PEAK_FSK / 1e3);
+ LOGP(DDSP, LOGL_DEBUG, "Using FSK level of %.3f (%.3f KHz deviation)\n", TX_PEAK_FSK, SPEECH_DEVIATION * TX_PEAK_FSK / 1e3);
/* init fsk */
if (fsk_mod_init(&mpt1327->fsk_mod, mpt1327, fsk_send_bit, mpt1327->sender.samplerate, BIT_RATE, F0, F1, TX_PEAK_FSK, 1, 0) < 0) {
- PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n");
+ LOGP_CHAN(DDSP, LOGL_ERROR, "FSK init failed!\n");
return -EINVAL;
}
if (fsk_demod_init(&mpt1327->fsk_demod, mpt1327, fsk_receive_bit, mpt1327->sender.samplerate, BIT_RATE, F0, F1, BIT_ADJUST) < 0) {
- PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n");
+ LOGP_CHAN(DDSP, LOGL_ERROR, "FSK init failed!\n");
return -EINVAL;
}
@@ -85,9 +85,9 @@ int dsp_init_sender(mpt1327_t *mpt1327, double squelch_db)
mpt1327->dmp_frame_quality = display_measurements_add(&mpt1327->sender.dispmeas, "Frame Quality", "%.1f %% (last)", DISPLAY_MEAS_LAST, DISPLAY_MEAS_LEFT, 0.0, 100.0, 100.0);
/* repeater */
- rc = jitter_create(&mpt1327->repeater_dejitter, mpt1327->sender.samplerate / 5);
+ rc = jitter_create(&mpt1327->repeater_dejitter, "repeater", mpt1327->sender.samplerate, 0.050, 0.500, JITTER_FLAG_NONE);
if (rc < 0) {
- PDEBUG(DDSP, DEBUG_ERROR, "Failed to create and init repeater buffer!\n");
+ LOGP(DDSP, LOGL_ERROR, "Failed to create and init repeater buffer!\n");
goto error;
}
return 0;
@@ -100,7 +100,7 @@ error:
/* Cleanup transceiver instance. */
void dsp_cleanup_sender(mpt1327_t *mpt1327)
{
- PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup DSP for Transceiver.\n");
+ LOGP_CHAN(DDSP, LOGL_DEBUG, "Cleanup DSP for Transceiver.\n");
fsk_mod_cleanup(&mpt1327->fsk_mod);
fsk_demod_cleanup(&mpt1327->fsk_demod);
@@ -163,7 +163,7 @@ static void fsk_receive_bit(void *inst, int bit, double quality, double level)
/* check parity */
if (mpt1327_checkbits(mpt1327->rx_bits, NULL) != (mpt1327->rx_bits & 0xffff)) {
- PDEBUG(DDSP, DEBUG_NOTICE, "Received corrupt codeword or noise.\n");
+ LOGP(DDSP, LOGL_NOTICE, "Received corrupt codeword or noise.\n");
mpt1327->rx_in_sync = 0;
mpt1327->rx_mute = 0;
return;
@@ -234,9 +234,14 @@ void sender_receive(sender_t *sender, sample_t *samples, int length, double __at
if (mpt1327->dsp_mode == DSP_MODE_TRAFFIC) {
/* if repeater mode, store sample in jitter buffer */
- if (mpt1327->repeater)
- jitter_save(&mpt1327->repeater_dejitter, samples, length);
-
+ if (mpt1327->repeater) {
+ jitter_frame_t *jf;
+ jf = jitter_frame_alloc(NULL, NULL, (uint8_t *)samples, length * sizeof(*samples), 0, mpt1327->repeater_sequence, mpt1327->repeater_timestamp, 123);
+ if (jf)
+ jitter_save(&mpt1327->repeater_dejitter, jf);
+ mpt1327->repeater_sequence += 1;
+ mpt1327->repeater_timestamp += length;
+ }
if (mpt1327->unit && mpt1327->unit->callref) {
int count;
@@ -279,6 +284,7 @@ static int fsk_send_bit(void *inst)
void sender_send(sender_t *sender, sample_t *samples, uint8_t *power, int length)
{
mpt1327_t *mpt1327 = (mpt1327_t *) sender;
+ int input_num;
if (mpt1327->dsp_mode == DSP_MODE_OFF) {
memset(power, 0, length);
@@ -289,12 +295,18 @@ void sender_send(sender_t *sender, sample_t *samples, uint8_t *power, int length
memset(power, 1, length);
if (mpt1327->dsp_mode == DSP_MODE_TRAFFIC) {
- jitter_load(&mpt1327->sender.dejitter, samples, length);
+ input_num = samplerate_upsample_input_num(&sender->srstate, length);
+ {
+ int16_t spl[input_num];
+ jitter_load_samples(&sender->dejitter, (uint8_t *)spl, input_num, sizeof(*spl), jitter_conceal_s16, NULL);
+ int16_to_samples_speech(samples, spl, input_num);
+ }
+ samplerate_upsample(&sender->srstate, samples, input_num, samples, length);
/* if repeater mode, sum samples from jitter buffer to samples */
if (mpt1327->repeater) {
sample_t uplink[length];
int i;
- jitter_load(&mpt1327->repeater_dejitter, uplink, length);
+ jitter_load_samples(&mpt1327->repeater_dejitter, (uint8_t *)uplink, length, sizeof(*uplink), NULL, NULL);
for (i = 0; i < length; i++)
samples[i] += uplink[i];
}
@@ -306,7 +318,7 @@ void sender_send(sender_t *sender, sample_t *samples, uint8_t *power, int length
fsk_mod_send(&mpt1327->fsk_mod, samples, length, 0);
}
-const char *mpt1327_dsp_mode_name(enum dsp_mode mode)
+static const char *mpt1327_dsp_mode_name(enum dsp_mode mode)
{
static char invalid[16];
@@ -331,12 +343,14 @@ void mpt1327_set_dsp_mode(mpt1327_t *mpt1327, enum dsp_mode mode, int repeater)
mpt1327->sync_word = 0xc4d7;
if (mode == DSP_MODE_TRAFFIC)
mpt1327->sync_word = 0x3b28;
+ if (mode == DSP_MODE_TRAFFIC && mpt1327->dsp_mode != mode)
+ jitter_reset(&mpt1327->sender.dejitter);
if (repeater)
- jitter_reset(&mpt1327->repeater_dejitter);
+ jitter_reset(&mpt1327->repeater_dejitter);
mpt1327->repeater = repeater;
- PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "DSP mode %s -> %s\n", mpt1327_dsp_mode_name(mpt1327->dsp_mode), mpt1327_dsp_mode_name(mode));
+ LOGP_CHAN(DDSP, LOGL_DEBUG, "DSP mode %s -> %s\n", mpt1327_dsp_mode_name(mpt1327->dsp_mode), mpt1327_dsp_mode_name(mode));
mpt1327->dsp_mode = mode;
}
@@ -347,3 +361,24 @@ void mpt1327_reset_sync(mpt1327_t *mpt1327)
mpt1327->rx_mute = 0;
}
+/* Receive audio from call instance. */
+void call_down_audio(void *decoder, void *decoder_priv, int callref, uint16_t sequence, uint8_t marker, uint32_t timestamp, uint32_t ssrc, uint8_t *payload, int payload_len)
+{
+ mpt1327_unit_t *unit;
+
+ unit = find_unit_callref(callref);
+ if (!unit)
+ return;
+ if (!unit->tc)
+ return;
+
+ if (unit->tc->state == STATE_BUSY && unit->tc->dsp_mode == DSP_MODE_TRAFFIC) {
+ jitter_frame_t *jf;
+ jf = jitter_frame_alloc(decoder, decoder_priv, payload, payload_len, marker, sequence, timestamp, ssrc);
+ if (jf)
+ jitter_save(&unit->tc->sender.dejitter, jf);
+ }
+}
+
+void call_down_clock(void) {}
+