summaryrefslogtreecommitdiff
path: root/util/spkmodem_recv/spkmodem-recv.c
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-06-04 15:53:00 +0100
committerLeah Rowe <leah@libreboot.org>2023-06-04 16:30:03 +0100
commitb21c1dd5e8d81fb8e22570f41c14079cfece932e (patch)
tree8437f5fc936af5bf60653a9a08bb87463321a8e0 /util/spkmodem_recv/spkmodem-recv.c
parent3401f287b441a15ceb21b1de82a34897c2a92e24 (diff)
util/spkmodem-recv: squash a few code lines
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.c33
1 files changed, 8 insertions, 25 deletions
diff --git a/util/spkmodem_recv/spkmodem-recv.c b/util/spkmodem_recv/spkmodem-recv.c
index 481643d1..f2737b15 100644
--- a/util/spkmodem_recv/spkmodem-recv.c
+++ b/util/spkmodem_recv/spkmodem-recv.c
@@ -23,8 +23,7 @@
#define FLUSH_TIMEOUT 1
#define ERR() (errno = errno ? errno : ECANCELED)
-signed short frame[2 * SAMPLES_PER_FRAME];
-signed short pulse[2 * SAMPLES_PER_FRAME];
+signed short frame[2 * SAMPLES_PER_FRAME], pulse[2 * SAMPLES_PER_FRAME];
int f1, f2, lp, ascii_bit = 7;
char ascii = 0;
@@ -37,25 +36,17 @@ int
main(int argc, char *argv[])
{
int c;
-
#ifdef __OpenBSD__
if (pledge("stdio", NULL) == -1)
err(ERR(), "pledge");
#endif
-
while ((c = getopt(argc, argv, "u")) != -1) {
- switch (c) {
- case 'u':
- setvbuf(stdout, NULL, _IONBF, 0);
- break;
- default:
+ if (c != 'u')
err(errno = EINVAL, NULL);
- }
+ setvbuf(stdout, NULL, _IONBF, 0);
}
-
while (!feof(stdin))
handle_audio();
-
if (errno)
err(errno, "Unhandled error upon exit. Exit status is errno.");
return 0;
@@ -65,7 +56,6 @@ void
handle_audio(void)
{
static int llp = 0;
-
if (lp > (3 * SAMPLES_PER_FRAME)) {
ascii_bit = 7;
ascii = lp = 0;
@@ -74,13 +64,11 @@ handle_audio(void)
if (llp == FLUSH_TIMEOUT)
if (fflush(stdout) == EOF)
err(ERR(), NULL);
-
if ((f2 <= FREQ_SEP_MIN) || (f2 >= FREQ_SEP_MAX)
|| (f1 <= FREQ_DATA_MIN) || (f1 >= FREQ_DATA_MAX)) {
fetch_sample();
return;
}
-
print_char();
lp = llp = 0;
@@ -92,14 +80,12 @@ void
fetch_sample(void)
{
static int ringpos = 0;
-
f1 -= pulse[ringpos];
f1 += pulse[(ringpos + SAMPLES_PER_FRAME) % (2 * SAMPLES_PER_FRAME)];
f2 -= pulse[(ringpos + SAMPLES_PER_FRAME) % (2 * SAMPLES_PER_FRAME)];
- read_frame(ringpos);
- pulse[ringpos] = (abs(frame[ringpos]) > THRESHOLD) ? 1 : 0;
- if (pulse[ringpos])
+ read_frame(ringpos);
+ if ((pulse[ringpos] = (abs(frame[ringpos]) > THRESHOLD) ? 1 : 0))
++f2;
++ringpos;
ringpos %= 2 * SAMPLES_PER_FRAME;
@@ -109,11 +95,9 @@ fetch_sample(void)
void
read_frame(int ringpos)
{
- if (fread(frame + ringpos, 1, sizeof(frame[0]), stdin)
- != sizeof(frame[0]))
+ if ((fread(frame + ringpos, 1, sizeof(frame[0]), stdin)
+ != sizeof(frame[0])) || (ferror(stdin) != 0))
err(ERR(), "Could not read from frame.");
- if (ferror(stdin) != 0)
- err(ERR(), "Could not read from frame");
}
void
@@ -128,8 +112,7 @@ print_char(void)
#endif
if (f1 < FREQ_DATA_THRESHOLD)
ascii |= (1 << ascii_bit);
- ascii_bit--;
- if (ascii_bit < 0) {
+ if (!ascii_bit) {
#if DEBUG
printf("<%c, %x>", ascii, ascii);
#else