diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-12 19:30:11 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-12 19:34:44 +0000 |
| commit | a7c69c323381a82e143d88244e099be8d4b7ca82 (patch) | |
| tree | e3f65eec19c99f049341bb8818bfc15e906c924c /util/spkmodem_recv/spkmodem-recv.c | |
| parent | 3633878e1f5a9c9356ba5228dc2d4bf2e65d06e7 (diff) | |
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 <leah@libreboot.org>
Diffstat (limited to 'util/spkmodem_recv/spkmodem-recv.c')
| -rw-r--r-- | util/spkmodem_recv/spkmodem-recv.c | 21 |
1 files 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) |
