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>
This commit is contained in:
Leah Rowe
2026-03-12 19:30:11 +00:00
parent 3633878e1f
commit a7c69c3233
+14 -7
View File
@@ -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)