libpayload: Fix x86 output arch
[coreboot.git] / util / spkmodem_recv / spkmodem-recv.c
blobcd7bd483d09b3d6be6f9204af1325a4c667bf60a
1 /* spkmodem-recv.c - decode spkmodem signals */
2 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
8 /* Compilation: gcc -o spkmodem-recv spkmodem-recv */
9 /* Usage: parec --channels=1 --rate=48000 --format=s16le | ./spkmodem-recv */
11 #define SAMPLES_PER_TRAME 240
12 #define FREQ_SEP_MIN 5
13 #define FREQ_SEP_MAX 15
14 #define FREQ_DATA_MIN 15
15 #define FREQ_DATA_THRESHOLD 25
16 #define FREQ_DATA_MAX 60
17 #define THRESHOLD 500
19 #define DEBUG 0
20 #define FLUSH_TIMEOUT 1
22 static signed short trame[2 * SAMPLES_PER_TRAME];
23 static signed short pulse[2 * SAMPLES_PER_TRAME];
24 static int ringpos = 0;
25 static int pos, f1, f2;
26 static int amplitude = 0;
27 static int lp = 0;
29 static void
30 read_sample (void)
32 amplitude -= abs (trame[ringpos]);
33 f1 -= pulse[ringpos];
34 f1 += pulse[(ringpos + SAMPLES_PER_TRAME) % (2 * SAMPLES_PER_TRAME)];
35 f2 -= pulse[(ringpos + SAMPLES_PER_TRAME) % (2 * SAMPLES_PER_TRAME)];
36 fread (trame + ringpos, 1, sizeof (trame[0]), stdin);
37 amplitude += abs (trame[ringpos]);
39 if (pos ? (trame[ringpos] < -THRESHOLD)
40 : (trame[ringpos] > +THRESHOLD))
42 pulse[ringpos] = 1;
43 pos = !pos;
44 f2++;
46 else
47 pulse[ringpos] = 0;
48 ringpos++;
49 ringpos %= 2 * SAMPLES_PER_TRAME;
50 lp++;
53 int
54 main ()
56 int bitn = 7;
57 char c = 0;
58 int i;
59 int llp = 0;
60 while (!feof (stdin))
62 if (lp > 3 * SAMPLES_PER_TRAME)
64 bitn = 7;
65 c = 0;
66 lp = 0;
67 llp++;
69 if (llp == FLUSH_TIMEOUT)
70 fflush (stdout);
71 if (f2 > FREQ_SEP_MIN && f2 < FREQ_SEP_MAX
72 && f1 > FREQ_DATA_MIN && f1 < FREQ_DATA_MAX)
74 #if DEBUG
75 printf ("%d %d %d @%d\n", f1, f2, FREQ_DATA_THRESHOLD,
76 ftell (stdin) - sizeof (trame));
77 #endif
78 if (f1 < FREQ_DATA_THRESHOLD)
79 c |= (1 << bitn);
80 bitn--;
81 if (bitn < 0)
83 #if DEBUG
84 printf ("<%c, %x>", c, c);
85 #else
86 printf ("%c", c);
87 #endif
88 bitn = 7;
89 c = 0;
91 lp = 0;
92 llp = 0;
93 for (i = 0; i < SAMPLES_PER_TRAME; i++)
94 read_sample ();
95 continue;
97 read_sample ();
99 return 0;