C-Netz: Correctly synchronize time stamp of SpK to OgK

Even if the SpK is not used (yet), it must count time stamp (bit_time) so that
SpK keeps in sync with the OgK, until frames are received from mobile station.
This commit is contained in:
Andreas Eversberg 2019-10-26 11:40:48 +02:00
parent 6dd9999dc8
commit 195f7481d8
3 changed files with 53 additions and 48 deletions

View File

@ -564,8 +564,9 @@ void sender_receive(sender_t *sender, sample_t *samples, int length, double __at
if (cnetz->dsp_mode != DSP_MODE_OFF) { if (cnetz->dsp_mode != DSP_MODE_OFF) {
iir_process(&cnetz->lp, samples, length); iir_process(&cnetz->lp, samples, length);
fsk_fm_demod(&cnetz->fsk_demod, samples, length); fsk_fm_demod(&cnetz->fsk_demod, samples, length); /* process */
} } else
fsk_fm_demod(&cnetz->fsk_demod, NULL, length); /* just count bit time */
return; return;
} }
@ -610,7 +611,7 @@ again:
/* start new telegramm, so we generate one */ /* start new telegramm, so we generate one */
if (pos == 0) { if (pos == 0) {
/* a new hyper frame starts */ /* a new super frame starts */
if (cnetz->sched_ts == 0 && cnetz->sched_r_m == 0) { if (cnetz->sched_ts == 0 && cnetz->sched_r_m == 0) {
/* measure actual signal speed */ /* measure actual signal speed */
calc_clock_speed(cnetz, (double)cnetz->sender.samplerate * 2.4, 1, 1); calc_clock_speed(cnetz, (double)cnetz->sender.samplerate * 2.4, 1, 1);
@ -624,7 +625,7 @@ again:
cnetz_t *master = (cnetz_t *)cnetz->sender.master; cnetz_t *master = (cnetz_t *)cnetz->sender.master;
/* it may happen that the sample count does not match with the master, /* it may happen that the sample count does not match with the master,
* because one has a phase wrap before and the other after a sample. * because one has a phase wrap before and the other after a sample.
* then we do it next hyper frame cycle */ * then we do it next super frame cycle */
if (master->frame_last_scount == cnetz->fsk_tx_scount) { if (master->frame_last_scount == cnetz->fsk_tx_scount) {
PDEBUG(DDSP, DEBUG_DEBUG, "Sync phase of slave to master: master=%.15f, slave=%.15f, diff=%.15f\n", master->frame_last_phase, cnetz->fsk_tx_phase, master->frame_last_phase - cnetz->fsk_tx_phase); PDEBUG(DDSP, DEBUG_DEBUG, "Sync phase of slave to master: master=%.15f, slave=%.15f, diff=%.15f\n", master->frame_last_phase, cnetz->fsk_tx_phase, master->frame_last_phase - cnetz->fsk_tx_phase);
cnetz->fsk_tx_phase = master->frame_last_phase; cnetz->fsk_tx_phase = master->frame_last_phase;

View File

@ -584,55 +584,58 @@ void fsk_fm_demod(fsk_fm_demod_t *fsk, sample_t *samples, int length)
/* process signaling block, sample by sample */ /* process signaling block, sample by sample */
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
fsk->bit_buffer_spl[fsk->bit_buffer_pos++] = samples[i]; /* samples == NULL, if no processing is wanted, then just count bit time */
if (fsk->bit_buffer_pos == fsk->bit_buffer_len) if (samples) {
fsk->bit_buffer_pos = 0; fsk->bit_buffer_spl[fsk->bit_buffer_pos++] = samples[i];
if (fsk->bit_buffer_pos == fsk->bit_buffer_len)
fsk->bit_buffer_pos = 0;
/* for each sample process buffer */ /* for each sample process buffer */
if (fsk->cnetz->dsp_mode != DSP_MODE_SPK_V) { if (fsk->cnetz->dsp_mode != DSP_MODE_SPK_V) {
if (fsk->demod_type == FSK_DEMOD_SLOPE)
find_change_slope(fsk);
else
find_change_level(fsk);
} else {
#ifdef DEBUG_DECODER
/* start debugging */
debug = 1;
#endif
/* in distributed signaling, measure over 5 bits, but ignore 5th bit.
* also reset next_bit, as soon as we reach the window */
/* note that we start from 0.5, because we detect change 0.5 bits later,
* because the detector of the change is in the middle of the 1 bit
* search window */
t = fmod(fsk->bit_time, BITS_PER_SPK_BLOCK);
if (t < 0.5) {
fsk->next_bit = 1.0 - fsk->bits_per_sample;
#ifdef DEBUG_DECODER
if (debug && fsk->bit_count)
fprintf(fsk->debug_fp, "---- SPK(V) BLOCK START ----\n");
#endif
fsk->bit_count = 0;
} else
if (t >= 0.5 && t < 5.5) {
if (fsk->demod_type == FSK_DEMOD_SLOPE) if (fsk->demod_type == FSK_DEMOD_SLOPE)
find_change_slope(fsk); find_change_slope(fsk);
else else
find_change_level(fsk); find_change_level(fsk);
} else } else {
if (t >= 5.5 && t < 65.5) { #ifdef DEBUG_DECODER
/* get audio for the duration of 60 bits */ /* start debugging */
/* prevent overflow, if speech_size != 0 and SPK_V debug = 1;
* has been restarted. */ #endif
if (fsk->speech_count < fsk->speech_size) /* in distributed signaling, measure over 5 bits, but ignore 5th bit.
fsk->speech_buffer[fsk->speech_count++] = samples[i]; * also reset next_bit, as soon as we reach the window */
} else /* note that we start from 0.5, because we detect change 0.5 bits later,
if (t >= 65.5) { * because the detector of the change is in the middle of the 1 bit
if (fsk->speech_count) { * search window */
unshrink_speech(fsk->cnetz, fsk->speech_buffer, fsk->speech_count); t = fmod(fsk->bit_time, BITS_PER_SPK_BLOCK);
fsk->speech_count = 0; if (t < 0.5) {
fsk->next_bit = 1.0 - fsk->bits_per_sample;
#ifdef DEBUG_DECODER
if (debug && fsk->bit_count)
fprintf(fsk->debug_fp, "---- SPK(V) BLOCK START ----\n");
#endif
fsk->bit_count = 0;
} else
if (t >= 0.5 && t < 5.5) {
if (fsk->demod_type == FSK_DEMOD_SLOPE)
find_change_slope(fsk);
else
find_change_level(fsk);
} else
if (t >= 5.5 && t < 65.5) {
/* get audio for the duration of 60 bits */
/* prevent overflow, if speech_size != 0 and SPK_V
* has been restarted. */
if (fsk->speech_count < fsk->speech_size)
fsk->speech_buffer[fsk->speech_count++] = samples[i];
} else
if (t >= 65.5) {
if (fsk->speech_count) {
unshrink_speech(fsk->cnetz, fsk->speech_buffer, fsk->speech_count);
fsk->speech_count = 0;
}
} }
}
}
} }
fsk->bit_time += fsk->bits_per_sample; fsk->bit_time += fsk->bits_per_sample;
if (fsk->bit_time >= BITS_PER_SUPERFRAME) { if (fsk->bit_time >= BITS_PER_SUPERFRAME) {
@ -652,10 +655,11 @@ void fsk_correct_sync(fsk_fm_demod_t *fsk, double offset)
fsk->bit_time = fmod(fsk->bit_time - offset + BITS_PER_SUPERFRAME, BITS_PER_SUPERFRAME); fsk->bit_time = fmod(fsk->bit_time - offset + BITS_PER_SUPERFRAME, BITS_PER_SUPERFRAME);
} }
/* copy sync from one instance to another (used to sync RX of SpK to OgK */ /* copy sync from one instance to another (used to sync RX of SpK to OgK) */
void fsk_copy_sync(fsk_fm_demod_t *fsk_to, fsk_fm_demod_t *fsk_from) void fsk_copy_sync(fsk_fm_demod_t *fsk_to, fsk_fm_demod_t *fsk_from)
{ {
fsk_to->bit_time = fsk_from->bit_time; fsk_to->bit_time = fsk_from->bit_time;
fsk_demod_reset(fsk_to);
} }
void fsk_demod_reset(fsk_fm_demod_t *fsk) void fsk_demod_reset(fsk_fm_demod_t *fsk)

View File

@ -526,7 +526,7 @@ int main(int argc, char *argv[])
/* OgK must be the first channel, so it becomes master. This is required for syncing SPK channels */ /* OgK must be the first channel, so it becomes master. This is required for syncing SPK channels */
if (i != 0) { if (i != 0) {
fprintf(stderr, "The first channel you defined must be OgK (control) or OgK/SPK (control/speech) channel type. Quitting!\n"); fprintf(stderr, "The first channel you define must be OgK (control) or OgK/SPK (control/speech) channel type. Quitting!\n");
goto fail; goto fail;
} }