Split FSK modem code into separate modulator and demodulator

This commit is contained in:
Andreas Eversberg
2019-09-01 15:38:16 +02:00
parent 360729d270
commit 6dcc8baad4
9 changed files with 213 additions and 137 deletions

View File

@@ -87,7 +87,8 @@ typedef struct bnetz {
/* dsp states */
enum dsp_mode dsp_mode; /* current mode: audio, durable tone 0 or 1, "Telegramm" */
fsk_t fsk; /* fsk modem instance */
fsk_mod_t fsk_mod; /* fsk modem instance */
fsk_demod_t fsk_demod;
uint16_t rx_telegramm; /* rx shift register for receiveing telegramm */
double rx_telegramm_quality[16];/* quality of each bit in telegramm */
double rx_telegramm_level[16]; /* level of each bit in telegramm */

View File

@@ -61,7 +61,7 @@ int tx_telegramm_pos = 0;
int latspl;
/* instances */
fsk_t fsk;
fsk_mod_t fsk_mod;
#ifdef HAVE_ALSA
void *audio = NULL;
#endif
@@ -226,7 +226,7 @@ again:
break;
case TX_MODE_FSK:
/* send FSK until it stops, then fill with silence */
count = fsk_send(&fsk, samples, length, 0);
count = fsk_mod_send(&fsk_mod, samples, length, 0);
samples += count;
length -= count;
if (length)
@@ -286,7 +286,7 @@ int main(int argc, char *argv[])
/* init */
bnetz_init_telegramm();
memset(&fsk, 0, sizeof(fsk));
memset(&fsk_mod, 0, sizeof(fsk_mod));
/* latency of send buffer in samples */
latspl = samplerate * latency / 1000;
@@ -340,7 +340,7 @@ int main(int argc, char *argv[])
sprintf(funkwahl, "wwww%c%s%se%c%s%se", start_digit, station_id, dialing + 1, start_digit, station_id, dialing + 1);
/* init fsk */
if (fsk_init(&fsk, NULL, fsk_send_bit, NULL, samplerate, BIT_RATE, F0, F1, 1.0, 0, 0) < 0) {
if (fsk_mod_init(&fsk_mod, NULL, fsk_send_bit, samplerate, BIT_RATE, F0, F1, 1.0, 0) < 0) {
PDEBUG(DDSP, DEBUG_ERROR, "FSK init failed!\n");
goto exit;
}
@@ -389,7 +389,7 @@ exit:
#endif
/* exit fsk */
fsk_cleanup(&fsk);
fsk_mod_cleanup(&fsk_mod);
return 0;
}

View File

@@ -96,7 +96,11 @@ int dsp_init_sender(bnetz_t *bnetz, double squelch_db)
PDEBUG(DDSP, DEBUG_DEBUG, "Using FSK level of %.3f (%.3f KHz deviation @ 2000 Hz)\n", TX_PEAK_FSK, 4.0);
/* init fsk */
if (fsk_init(&bnetz->fsk, bnetz, fsk_send_bit, fsk_receive_bit, bnetz->sender.samplerate, BIT_RATE, F0, F1, TX_PEAK_FSK, 0, BIT_ADJUST) < 0) {
if (fsk_mod_init(&bnetz->fsk_mod, bnetz, fsk_send_bit, bnetz->sender.samplerate, BIT_RATE, F0, F1, TX_PEAK_FSK, 0) < 0) {
PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n");
return -EINVAL;
}
if (fsk_demod_init(&bnetz->fsk_demod, bnetz, fsk_receive_bit, bnetz->sender.samplerate, BIT_RATE, F0, F1, BIT_ADJUST) < 0) {
PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n");
return -EINVAL;
}
@@ -121,7 +125,8 @@ void dsp_cleanup_sender(bnetz_t *bnetz)
{
PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "Cleanup DSP for 'Sender'.\n");
fsk_cleanup(&bnetz->fsk);
fsk_mod_cleanup(&bnetz->fsk_mod);
fsk_demod_cleanup(&bnetz->fsk_demod);
}
/* If good tone is received, we just set this tone, if not already and reset counters.
@@ -270,7 +275,7 @@ void sender_receive(sender_t *sender, sample_t *samples, int length, double rf_l
int i;
/* fsk/tone signal */
fsk_receive(&bnetz->fsk, samples, length);
fsk_demod_receive(&bnetz->fsk_demod, samples, length);
/* process signal mute/loss, without signalling tone / FSK frames */
switch (squelch(&bnetz->squelch, rf_level_db, (double)length / (double)bnetz->sender.samplerate)) {
@@ -375,7 +380,7 @@ again:
case DSP_MODE_TELEGRAMM:
/* Encode tone/frame into audio stream. If frames have
* stopped, process again for rest of stream. */
count = fsk_send(&bnetz->fsk, samples, length, 0);
count = fsk_mod_send(&bnetz->fsk_mod, samples, length, 0);
samples += count;
length -= count;
if (length)
@@ -412,7 +417,7 @@ void bnetz_set_dsp_mode(bnetz_t *bnetz, enum dsp_mode mode)
/* reset telegramm */
if (mode == DSP_MODE_TELEGRAMM && bnetz->dsp_mode != mode) {
bnetz->tx_telegramm = 0;
fsk_tx_reset(&bnetz->fsk);
fsk_mod_tx_reset(&bnetz->fsk_mod);
}
PDEBUG_CHAN(DDSP, DEBUG_DEBUG, "DSP mode %s -> %s\n", bnetz_dsp_mode_name(bnetz->dsp_mode), bnetz_dsp_mode_name(mode));