From e2864704320e9fdde78ea34088256d99df9d5931 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Tue, 16 May 2023 08:17:29 +0100 Subject: [PATCH] util/spkmodem_recv: Top-down logic (main on top) Add the appropriate prototype. Top-down function order is easier to read. Signed-off-by: Leah Rowe --- util/spkmodem_recv/spkmodem-recv.c | 46 ++++++++++++++++-------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/util/spkmodem_recv/spkmodem-recv.c b/util/spkmodem_recv/spkmodem-recv.c index 5efa25a7..d543d32e 100644 --- a/util/spkmodem_recv/spkmodem-recv.c +++ b/util/spkmodem_recv/spkmodem-recv.c @@ -26,28 +26,7 @@ static int pos, f1, f2; static int amplitude = 0; static int lp = 0; -static void -read_sample (void) -{ - amplitude -= abs (trame[ringpos]); - f1 -= pulse[ringpos]; - f1 += pulse[(ringpos + SAMPLES_PER_TRAME) % (2 * SAMPLES_PER_TRAME)]; - f2 -= pulse[(ringpos + SAMPLES_PER_TRAME) % (2 * SAMPLES_PER_TRAME)]; - fread (trame + ringpos, 1, sizeof (trame[0]), stdin); - amplitude += abs (trame[ringpos]); - - if (abs(trame[ringpos]) > THRESHOLD) { /* rising/falling edge(pulse) */ - pulse[ringpos] = 1; - pos = !pos; - f2++; - } else { - pulse[ringpos] = 0; - } - - ringpos++; - ringpos %= 2 * SAMPLES_PER_TRAME; - lp++; -} +static void read_sample (void); int main (int argc, char *argv[]) @@ -97,3 +76,26 @@ main (int argc, char *argv[]) } return 0; } + +static void +read_sample (void) +{ + amplitude -= abs (trame[ringpos]); + f1 -= pulse[ringpos]; + f1 += pulse[(ringpos + SAMPLES_PER_TRAME) % (2 * SAMPLES_PER_TRAME)]; + f2 -= pulse[(ringpos + SAMPLES_PER_TRAME) % (2 * SAMPLES_PER_TRAME)]; + fread (trame + ringpos, 1, sizeof (trame[0]), stdin); + amplitude += abs (trame[ringpos]); + + if (abs(trame[ringpos]) > THRESHOLD) { /* rising/falling edge(pulse) */ + pulse[ringpos] = 1; + pos = !pos; + f2++; + } else { + pulse[ringpos] = 0; + } + + ringpos++; + ringpos %= 2 * SAMPLES_PER_TRAME; + lp++; +}