Improved output format possibilities
[mirrors/Programs.git] / c / goertzel / dtmf.sh
1 #!/bin/bash
2 #This is sample implementation of DTMF decoder using my C implementation of Goertzel Algorithm
3 #This is not very efficient or precise, it's just proof of concept
4 #Note that it's also quite tricky (but not imposible) to detect DTMF using microphone
5 #You will probably need to tune treshold and mixer settings a bit...
6 #I've had best results using dtmfdial (Linux software) and two soundcards connected directly using cable
7 #Usage example: arecord 2>/dev/null | ./dtmf.sh
8
9 tresh=10
10 last='';
11 ./goertzel -n B -q -l -r 8000 -d 20 -t $tresh -f 697 -f 770 -f 852 -f 941 -f 1209 -f 1336 -f 1477 -f 1633 $@ | while read line; do
12 #echo "$line";
13
14 #Get time
15 pos="$(echo "$line" | cut -f 1)";
16
17 #Get values for each tone
18 a="$(echo "$line" | cut -f 2)";
19 b="$(echo "$line" | cut -f 3)";
20 c="$(echo "$line" | cut -f 4)";
21 d="$(echo "$line" | cut -f 5)";
22 e="$(echo "$line" | cut -f 6)";
23 f="$(echo "$line" | cut -f 7)";
24 g="$(echo "$line" | cut -f 8)";
25 h="$(echo "$line" | cut -f 9)";
26
27 #echo "$pos: $a $b $c $d $e $f $g $h";
28 state="$a$b$c$d$e$f$g$h";
29
30 #Test if tones changed since last time
31 #echo test "$state" != "$last"
32 test "$state" != "$last" && {
33
34 #DTMF Table
35 $a && {
36 $e && echo -n '1'
37 $f && echo -n '2'
38 $g && echo -n '3'
39 $h && echo -n 'A'
40 }
41 $b && {
42 $e && echo -n '4'
43 $f && echo -n '5'
44 $g && echo -n '6'
45 $h && echo -n 'B'
46 }
47 $c && {
48 $e && echo -n '7'
49 $f && echo -n '8'
50 $g && echo -n '9'
51 $h && echo -n 'C'
52 }
53 $d && {
54 $e && echo -n '*'
55 $f && echo -n '0'
56 $g && echo '#'
57 $h && echo -n 'D'
58 }
59
60 }
61
62 last="$state"
63
64 done
This page took 0.270397 seconds and 4 git commands to generate.