From a7c69c323381a82e143d88244e099be8d4b7ca82 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Thu, 12 Mar 2026 19:30:11 +0000 Subject: util/spkmodem-recv: clean up decode_pulse make it easier to read by clearer variable naming. this change also reduces memory accesses (fewer struct dereferences - see: struct decoder_state), when using much weaker/older compilers that don't optimise properly. this, in the most active part of the code, which is called.... 48000 times a second. peanuts on modern CPUs, but on old (early 90s) CPUs it makes a big difference. Signed-off-by: Leah Rowe --- util/spkmodem_recv/spkmodem-recv.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/util/spkmodem_recv/spkmodem-recv.c b/util/spkmodem_recv/spkmodem-recv.c index 02f627e5..48b06527 100644 --- a/util/spkmodem_recv/spkmodem-recv.c +++ b/util/spkmodem_recv/spkmodem-recv.c @@ -179,28 +179,35 @@ decode_pulse(struct decoder_state *st) { unsigned char old_ring, old_sep; unsigned char new_pulse; + int ringpos; + signed short sample; - old_ring = st->pulse[st->ringpos]; + ringpos = st->ringpos; + + old_ring = st->pulse[ringpos]; old_sep = st->pulse[st->sep_pos]; st->freq_data -= old_ring; st->freq_data += old_sep; st->freq_separator -= old_sep; - st->frame[st->ringpos] = read_sample(st); + sample = read_sample(st); + st->frame[ringpos] = sample; - if ((unsigned)(st->frame[st->ringpos] + THRESHOLD) + if ((unsigned)(sample + THRESHOLD) > (unsigned)(2 * THRESHOLD)) new_pulse = 1; else new_pulse = 0; - st->pulse[st->ringpos] = new_pulse; + st->pulse[ringpos] = new_pulse; st->freq_separator += new_pulse; - st->ringpos++; - if (st->ringpos >= MAX_SAMPLES) - st->ringpos = 0; + ringpos++; + if (ringpos >= MAX_SAMPLES) + ringpos = 0; + + st->ringpos = ringpos; st->sep_pos++; if (st->sep_pos >= MAX_SAMPLES) -- cgit v1.2.1