More goertzel improvements
[mirrors/Programs.git] / c / goertzel / dtmf.sh
CommitLineData
59934436
H
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
4b50f692
H
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
59934436
H
7#Usage example: arecord 2>/dev/null | ./dtmf.sh
8
4b50f692 9tresh=10
59934436 10last='';
4b50f692 11./goertzel -i -q -a -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
59934436
H
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 #Compare values to treshold
28 test $a -gt $tresh && a=true || a=false
29 test $b -gt $tresh && b=true || b=false
30 test $c -gt $tresh && c=true || c=false
31 test $d -gt $tresh && d=true || d=false
32 test $e -gt $tresh && e=true || e=false
33 test $f -gt $tresh && f=true || f=false
34 test $g -gt $tresh && g=true || g=false
35 test $h -gt $tresh && h=true || h=false
36
37 #echo "$pos: $a $b $c $d $e $f $g $h";
38 state="$a$b$c$d$e$f$g$h";
39
40 #Test if tones changed since last time
41 #echo test "$state" != "$last"
42 test "$state" != "$last" && {
43
44 #DTMF Table
45 $a && {
46 $e && echo -n '1'
47 $f && echo -n '2'
48 $g && echo -n '3'
49 $h && echo -n 'A'
50 }
51 $b && {
52 $e && echo -n '4'
53 $f && echo -n '5'
54 $g && echo -n '6'
55 $h && echo -n 'B'
56 }
57 $c && {
58 $e && echo -n '7'
59 $f && echo -n '8'
60 $g && echo -n '9'
61 $h && echo -n 'C'
62 }
63 $d && {
64 $e && echo -n '*'
65 $f && echo -n '0'
66 $g && echo '#'
67 $h && echo -n 'D'
68 }
69
70 }
71
72 last="$state"
73
74done
This page took 0.134088 seconds and 4 git commands to generate.