6c7798e956ce113417a02e114e1738a06065dae9
[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 #Usage example: arecord 2>/dev/null | ./dtmf.sh
5
6 tresh=3
7 last='';
8 ./goertzel -i -q -r 8000 -s 400 -t $tresh -f 697 -f 770 -f 852 -f 941 -f 1209 -f 1336 -f 1477 -f 1633 | while read line; do
9 #echo "$line";
10
11 #Get time
12 pos="$(echo "$line" | cut -f 1)";
13
14 #Get values for each tone
15 a="$(echo "$line" | cut -f 2)";
16 b="$(echo "$line" | cut -f 3)";
17 c="$(echo "$line" | cut -f 4)";
18 d="$(echo "$line" | cut -f 5)";
19 e="$(echo "$line" | cut -f 6)";
20 f="$(echo "$line" | cut -f 7)";
21 g="$(echo "$line" | cut -f 8)";
22 h="$(echo "$line" | cut -f 9)";
23
24 #Compare values to treshold
25 test $a -gt $tresh && a=true || a=false
26 test $b -gt $tresh && b=true || b=false
27 test $c -gt $tresh && c=true || c=false
28 test $d -gt $tresh && d=true || d=false
29 test $e -gt $tresh && e=true || e=false
30 test $f -gt $tresh && f=true || f=false
31 test $g -gt $tresh && g=true || g=false
32 test $h -gt $tresh && h=true || h=false
33
34 #echo "$pos: $a $b $c $d $e $f $g $h";
35 state="$a$b$c$d$e$f$g$h";
36
37 #Test if tones changed since last time
38 #echo test "$state" != "$last"
39 test "$state" != "$last" && {
40
41 #DTMF Table
42 $a && {
43 $e && echo -n '1'
44 $f && echo -n '2'
45 $g && echo -n '3'
46 $h && echo -n 'A'
47 }
48 $b && {
49 $e && echo -n '4'
50 $f && echo -n '5'
51 $g && echo -n '6'
52 $h && echo -n 'B'
53 }
54 $c && {
55 $e && echo -n '7'
56 $f && echo -n '8'
57 $g && echo -n '9'
58 $h && echo -n 'C'
59 }
60 $d && {
61 $e && echo -n '*'
62 $f && echo -n '0'
63 $g && echo '#'
64 $h && echo -n 'D'
65 }
66
67 }
68
69 last="$state"
70
71 done
This page took 0.311783 seconds and 3 git commands to generate.