From 4b50f692bc27bd6275483c80720829b126fa2951 Mon Sep 17 00:00:00 2001 From: Harvie Date: Wed, 1 Aug 2012 01:24:22 +0200 Subject: [PATCH] More goertzel improvements --- c/goertzel/dtmf.sh | 7 +++++-- c/goertzel/goertzel.c | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/c/goertzel/dtmf.sh b/c/goertzel/dtmf.sh index 6c7798e..2c6547d 100755 --- a/c/goertzel/dtmf.sh +++ b/c/goertzel/dtmf.sh @@ -1,11 +1,14 @@ #!/bin/bash #This is sample implementation of DTMF decoder using my C implementation of Goertzel Algorithm #This is not very efficient or precise, it's just proof of concept +#Note that it's also quite tricky (but not imposible) to detect DTMF using microphone +#You will probably need to tune treshold and mixer settings a bit... +#I've had best results using dtmfdial (Linux software) and two soundcards connected directly using cable #Usage example: arecord 2>/dev/null | ./dtmf.sh -tresh=3 +tresh=10 last=''; -./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 +./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 #echo "$line"; #Get time diff --git a/c/goertzel/goertzel.c b/c/goertzel/goertzel.c index f5250a0..a269750 100644 --- a/c/goertzel/goertzel.c +++ b/c/goertzel/goertzel.c @@ -76,12 +76,13 @@ int main(int argc, char ** argv) { int samplecount = 4000; int treshold = -1; char noreturn = 0; + char repeat = 1; char integers=0; char verbose=1; int freqs[argc+1]; freqs[0]=-1; int opt; - while ((opt = getopt(argc, argv, "?r:s:f:t:iqn")) != -1) { + while ((opt = getopt(argc, argv, "?r:s:f:t:iqna")) != -1) { switch (opt) { case 'r': samplerate = atoi(optarg); @@ -98,6 +99,9 @@ int main(int argc, char ** argv) { case 'i': integers = 1; break; + case 'a': + repeat = 0; + break; case 'n': noreturn = 1; break; @@ -152,7 +156,7 @@ int main(int argc, char ** argv) { //Set print true if over treshold or if changed to false (print for the last time after going under treshold) printnow = power[i] > treshold; - print = print || printnow || (printlast && !noreturn); + print = !(!repeat && printlast && !(!printnow)) && (print || printnow || (printlast && !noreturn)); } printlast = printnow; fflush(stdout); -- 2.30.2