-
Notifications
You must be signed in to change notification settings - Fork 1
/
decode-with-average.pl
executable file
·58 lines (44 loc) · 1.06 KB
/
decode-with-average.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
# arecord -r44100 -f S32_LE -t raw 2>/dev/null | ./fourier2 | ./decode-without-leader.pl 950 1305 1717 2123 3000 2>/dev/null
use warnings;
use strict;
use constant EPS => 20;
my $leader = $ARGV[0];
my @detect = @ARGV;
$|++;
sub hear { split /\s+/, scalar <STDIN> }
sub contains {
my ($needle, @haystack) = @_;
for my $f (@haystack) {
if(abs($needle - $f) < EPS) {
return 1;
}
}
return;
}
print STDERR "/" until contains($leader, hear());
#print STDERR "\\" while contains($leader, hear());
#hear();
hear() for 1..18;
print STDERR "\n";
my $num = 0;
while(1) {
my @freq = hear();
# print STDERR "@freq\n";
# last if contains($leader, @freq);
my $data = 0;
for(my $i = 0; $i < @detect; $i++) {
if(contains($detect[$i], @freq)) {
print STDERR "*";
$data += 1 << $i;
} else {
print STDERR ".";
}
}
print STDERR "\n";
if($num % 12 == 1) {
print STDERR chr(65 + $data);
print STDERR "\n";
}
$num++;
}