From: Tomas Mudrunka Date: Thu, 2 Aug 2012 17:57:30 +0000 (+0200) Subject: Fixed bug in treshold-cross logic X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=19a509d14a28519397f352f3cd0570c9becf7c47;p=mirrors%2FPrograms.git Fixed bug in treshold-cross logic --- diff --git a/c/goertzel/dtmf.sh b/c/goertzel/dtmf.sh index 2abc22b..e01571e 100755 --- a/c/goertzel/dtmf.sh +++ b/c/goertzel/dtmf.sh @@ -8,7 +8,7 @@ tresh=10 last=''; -./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 +./goertzel -n B -q -l c -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 #echo "$line"; #Get time diff --git a/c/goertzel/goertzel.c b/c/goertzel/goertzel.c index 95e3099..a6070ca 100644 --- a/c/goertzel/goertzel.c +++ b/c/goertzel/goertzel.c @@ -75,8 +75,10 @@ void print_help(char ** argv) { "\t\ti: integer\n" "\t\tb: binary (0|1)\n" "\t\tB: Boolean (false|true)\n" - "\t-l\t\tDo not repeat values while still over treshold\n" - "\t-b\t\tDo not print first value that will fall under treshold\n" + "\t-l \tSet filter\n" + "\t\tf: Falldown: print only when over treshold or just falled under (default)\n" + "\t\tt: Treshold: print only when over treshold\n" + "\t\tc: Crossed: print only when treshold crossed\n" "\t-q\t\tQuiet mode: print only values\n" "\n" "\t-?\t\tPrint help\n" @@ -109,14 +111,13 @@ int main(int argc, char ** argv) { int samplerate = 8000; int samplecount = 4000; int treshold = -1; - char noreturn = 0; - char repeat = 1; + char filter = 0; char format=0; char verbose=1; int freqs[argc+1]; freqs[0]=-1; int opt; - while ((opt = getopt(argc, argv, "?i:o:a:r:c:d:f:t:n:lbq")) != -1) { + while ((opt = getopt(argc, argv, "?i:o:a:r:c:d:f:t:n:l:q")) != -1) { switch (opt) { case 'i': freopen(optarg, "r", stdin); @@ -146,10 +147,7 @@ int main(int argc, char ** argv) { format = optarg[0]; break; case 'l': - repeat = 0; - break; - case 'b': - noreturn = 1; + filter = optarg[0]; break; case 'q': verbose = 0; @@ -182,9 +180,10 @@ int main(int argc, char ** argv) { puts(""); } - char print=0, printnow=0, printlast = 0; + int i; + char print=0, printnow=0; + char laststate[argc]; for(i=0;freqs[i]!=-1;i++) laststate[i]=-1; while(!feof(stdin)) { - int i; //Sample data for(i=0;i treshold; - print = !(!repeat && printlast && !(!printnow)) && (print || printnow || (printlast && !noreturn)); + //Decide if we will print + printnow = power[i] > treshold; //Is over treshold? + switch(filter) { + case 'c': //Print if treshold crossed + print = print || (laststate[i] != printnow); + break; + default: + case 'f': //Print if over treshold or falled down + print = print || (laststate[i] != printnow); + case 't': //Print if over treshold + print = print || printnow; + } + laststate[i] = printnow; //Store last state } - printlast = printnow; fflush(stdout); //Print data diff --git a/c/goertzel/sleepmon.sh b/c/goertzel/sleepmon.sh index 3ccc670..4896e87 100755 --- a/c/goertzel/sleepmon.sh +++ b/c/goertzel/sleepmon.sh @@ -22,7 +22,7 @@ while getopts "s" OPT; do test "$OPT" == 's' && screen=true; done echo "Writing to file: $out"; -arecord | ./goertzel -n i -q -l -t $tresh -d 4 | while read line; do +arecord | ./goertzel -n i -q -l c -t $tresh -d 4 | while read line; do date="$(date +%s)" time="$(echo "$line" | cut -f 1)" level="$(echo "$line" | cut -f 2)" @@ -42,4 +42,5 @@ arecord | ./goertzel -n i -q -l -t $tresh -d 4 | while read line; do lastdate="$date"; done | tee "$out" kill $! +echo echo "Your file: $out"