1 /* spkmodem-recv.c - decode spkmodem signals */
2 /* SPDX-License-Identifier: GPL-2.0-or-later */
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
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;
32 amplitude
-= abs (trame
[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
))
49 ringpos
%= 2 * SAMPLES_PER_TRAME
;
62 if (lp
> 3 * SAMPLES_PER_TRAME
)
69 if (llp
== FLUSH_TIMEOUT
)
71 if (f2
> FREQ_SEP_MIN
&& f2
< FREQ_SEP_MAX
72 && f1
> FREQ_DATA_MIN
&& f1
< FREQ_DATA_MAX
)
75 printf ("%d %d %d @%d\n", f1
, f2
, FREQ_DATA_THRESHOLD
,
76 ftell (stdin
) - sizeof (trame
));
78 if (f1
< FREQ_DATA_THRESHOLD
)
84 printf ("<%c, %x>", c
, c
);
93 for (i
= 0; i
< SAMPLES_PER_TRAME
; i
++)