| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include <stdio.h> |
| 5 |
#include <stdlib.h> |
| 6 |
#include <string.h> |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 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 |
| 18 |
|
| 19 |
#define DEBUG 0 |
| 20 |
#define FLUSH_TIMEOUT 1 |
| 21 |
|
| 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; |
| 28 |
|
| 29 |
static void |
| 30 |
read_sample (void) |
| 31 |
{ |
| 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]); |
| 38 |
|
| 39 |
if (pos ? (trame[ringpos] < -THRESHOLD) |
| 40 |
: (trame[ringpos] > +THRESHOLD)) |
| 41 |
{ |
| 42 |
pulse[ringpos] = 1; |
| 43 |
pos = !pos; |
| 44 |
f2++; |
| 45 |
} |
| 46 |
else |
| 47 |
pulse[ringpos] = 0; |
| 48 |
ringpos++; |
| 49 |
ringpos %= 2 * SAMPLES_PER_TRAME; |
| 50 |
lp++; |
| 51 |
} |
| 52 |
|
| 53 |
int |
| 54 |
main () |
| 55 |
{ |
| 56 |
int bitn = 7; |
| 57 |
char c = 0; |
| 58 |
int i; |
| 59 |
int llp = 0; |
| 60 |
while (!feof (stdin)) |
| 61 |
{ |
| 62 |
if (lp > 3 * SAMPLES_PER_TRAME) |
| 63 |
{ |
| 64 |
bitn = 7; |
| 65 |
c = 0; |
| 66 |
lp = 0; |
| 67 |
llp++; |
| 68 |
} |
| 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) |
| 73 |
{ |
| 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) |
| 82 |
{ |
| 83 |
#if DEBUG |
| 84 |
printf ("<%c, %x>", c, c); |
| 85 |
#else |
| 86 |
printf ("%c", c); |
| 87 |
#endif |
| 88 |
bitn = 7; |
| 89 |
c = 0; |
| 90 |
} |
| 91 |
lp = 0; |
| 92 |
llp = 0; |
| 93 |
for (i = 0; i < SAMPLES_PER_TRAME; i++) |
| 94 |
read_sample (); |
| 95 |
continue; |
| 96 |
} |
| 97 |
read_sample (); |
| 98 |
} |
| 99 |
return 0; |
| 100 |
} |