diff options
| -rw-r--r-- | util/spkmodem_decode/spkmodem-decode.c | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/util/spkmodem_decode/spkmodem-decode.c b/util/spkmodem_decode/spkmodem-decode.c index e5c0afd0..7e199430 100644 --- a/util/spkmodem_decode/spkmodem-decode.c +++ b/util/spkmodem_decode/spkmodem-decode.c @@ -216,6 +216,7 @@ static const char *argv0; static int host_is_big_endian(void); static void handle_audio(struct decoder_state *st); +static void collect_separator_tone(struct decoder_state *st); static int valid_signal(struct decoder_state *st); static void decode_pulse(struct decoder_state *st); static void auto_detect_tone(struct decoder_state *st); @@ -296,7 +297,6 @@ host_is_big_endian(void) static void handle_audio(struct decoder_state *st) { - int avg; int sample; /* @@ -306,39 +306,52 @@ handle_audio(struct decoder_state *st) if (st->sample_count >= (3 * SAMPLES_PER_FRAME)) reset_char(st); - if (!valid_signal(st)) { + collect_separator_tone(st); - /* - * collect separator tone statistics - * (and auto-adjust tolerances) - */ - if (st->sep_samples < 50 && st->freq_separator > 0) { - st->sep_sum += st->freq_separator; - st->sep_samples++; + if (set_ascii_bit(st) < 0) + print_char(st); - if (st->sep_samples == 50) { - avg = st->sep_sum / st->sep_samples; + st->sample_count = 0; + for (sample = 0; sample < SAMPLES_PER_FRAME; sample++) + decode_pulse(st); +} - /* ±3 pulse window */ - st->sep_min = avg - SEP_TOLERANCE_PULSES; - st->sep_max = avg + SEP_TOLERANCE_PULSES; +/* + * collect separator tone statistics + * (and auto-adjust tolerances) + */ +static void +collect_separator_tone(struct decoder_state *st) +{ + int avg; - if (st->debug) - printf("separator calibrated: %dHz\n", - avg * FRAME_RATE); - } - } + if (valid_signal(st)) + return; + if (st->sep_samples >= 50 && st->freq_separator <= 0) { decode_pulse(st); return; } - if (set_ascii_bit(st) < 0) - print_char(st); + st->sep_sum += st->freq_separator; + st->sep_samples++; - st->sample_count = 0; - for (sample = 0; sample < SAMPLES_PER_FRAME; sample++) + if (st->sep_samples != 50) { decode_pulse(st); + return; + } + + avg = st->sep_sum / st->sep_samples; + + /* ±3 pulse window */ + st->sep_min = avg - SEP_TOLERANCE_PULSES; + st->sep_max = avg + SEP_TOLERANCE_PULSES; + + if (st->debug) + printf("separator calibrated: %dHz\n", + avg * FRAME_RATE); + + decode_pulse(st); } /* |
