summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-06-13 20:47:17 +0100
committerLeah Rowe <leah@libreboot.org>2023-06-13 20:47:17 +0100
commit5c5c1c64fd29f85644771810820ab912e75bc747 (patch)
treeaeebd1fd5b89bf7b48143299e6bf009598f869bc /util
parentf257eb6f9d866b5ec959106807bcaaee2262adbf (diff)
util/spkmodem-recv: cleaner ring buffer handling
make it more obvious that this *is* a ring buffer being handled, and make it more obvious when checking a pulse in the next frame Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
-rw-r--r--util/spkmodem_recv/spkmodem-recv.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/util/spkmodem_recv/spkmodem-recv.c b/util/spkmodem_recv/spkmodem-recv.c
index aea9ec29..16115bd0 100644
--- a/util/spkmodem_recv/spkmodem-recv.c
+++ b/util/spkmodem_recv/spkmodem-recv.c
@@ -27,6 +27,7 @@
/* Usage: parec --channels=1 --rate=48000 --format=s16le | ./spkmodem-recv */
#define SAMPLES_PER_FRAME 240
+#define MAX_SAMPLES (2 * SAMPLES_PER_FRAME)
#define FREQ_SEP_MIN 5
#define FREQ_SEP_MAX 15
#define FREQ_DATA_MIN 15
@@ -37,7 +38,7 @@
#define ERR() (errno = errno ? errno : ECANCELED)
#define reset_char() ascii = 0, ascii_bit = 7
-signed short frame[2 * SAMPLES_PER_FRAME], pulse[2 * SAMPLES_PER_FRAME];
+signed short frame[MAX_SAMPLES], pulse[MAX_SAMPLES];
int ringpos, debug, freq_data, freq_separator, sample_count, ascii_bit = 7;
char ascii = 0;
@@ -90,17 +91,16 @@ handle_audio(void)
void
fetch_sample(void)
{
+ int next_ringpos = (ringpos + SAMPLES_PER_FRAME) % MAX_SAMPLES;
freq_data -= pulse[ringpos];
- freq_data += pulse[(ringpos + SAMPLES_PER_FRAME)
- % (2 * SAMPLES_PER_FRAME)];
- freq_separator -= pulse[(ringpos + SAMPLES_PER_FRAME)
- % (2 * SAMPLES_PER_FRAME)];
+ freq_data += pulse[next_ringpos];
+ freq_separator -= pulse[next_ringpos];
read_frame();
if ((pulse[ringpos] = (abs(frame[ringpos]) > THRESHOLD) ? 1 : 0))
++freq_separator;
++ringpos;
- ringpos %= 2 * SAMPLES_PER_FRAME;
+ ringpos %= MAX_SAMPLES;
++sample_count;
}