From: Tomas Mudrunka Date: Thu, 2 Aug 2012 16:32:49 +0000 (+0200) Subject: Improved output format possibilities X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=c9be90d53f9bbcbfa1e69f4d245052450b4bd1b8;p=mirrors%2FPrograms.git Improved output format possibilities --- diff --git a/c/goertzel/dtmf.sh b/c/goertzel/dtmf.sh index 80a9d59..2abc22b 100755 --- a/c/goertzel/dtmf.sh +++ b/c/goertzel/dtmf.sh @@ -8,7 +8,7 @@ tresh=10 last=''; -./goertzel -n -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 -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 @@ -24,16 +24,6 @@ last=''; g="$(echo "$line" | cut -f 8)"; h="$(echo "$line" | cut -f 9)"; - #Compare values to treshold - test $a -gt $tresh && a=true || a=false - test $b -gt $tresh && b=true || b=false - test $c -gt $tresh && c=true || c=false - test $d -gt $tresh && d=true || d=false - test $e -gt $tresh && e=true || e=false - test $f -gt $tresh && f=true || f=false - test $g -gt $tresh && g=true || g=false - test $h -gt $tresh && h=true || h=false - #echo "$pos: $a $b $c $d $e $f $g $h"; state="$a$b$c$d$e$f$g$h"; diff --git a/c/goertzel/goertzel.c b/c/goertzel/goertzel.c index 96458a5..95e3099 100644 --- a/c/goertzel/goertzel.c +++ b/c/goertzel/goertzel.c @@ -70,7 +70,11 @@ void print_help(char ** argv) { "\t-f \tAdd frequency in Hz to detect (use multiple times, if no added 440 Hz will be...)\n" "\n" "\t-t \tSet treshold (used to hide magnitudes lower than treshold) (defaults -1)\n" - "\t-n\t\tPrint integers rather than floats\n" + "\t-n \tSet output format\n" + "\t\tf: float (default)\n" + "\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-q\t\tQuiet mode: print only values\n" @@ -107,12 +111,12 @@ int main(int argc, char ** argv) { int treshold = -1; char noreturn = 0; char repeat = 1; - char integers=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:nlbq")) != -1) { + while ((opt = getopt(argc, argv, "?i:o:a:r:c:d:f:t:n:lbq")) != -1) { switch (opt) { case 'i': freopen(optarg, "r", stdin); @@ -139,7 +143,7 @@ int main(int argc, char ** argv) { treshold = atoi(optarg); break; case 'n': - integers = 1; + format = optarg[0]; break; case 'l': repeat = 0; @@ -208,10 +212,21 @@ int main(int argc, char ** argv) { printf("%8.2f", position); for(i=0;freqs[i]!=-1;i++) { printf("\t"); - if(integers) - printf("%d",(int)power[i]); - else - printf("%.4f",power[i]); + switch(format) { + case 'i': + printf("%d",(int)power[i]); + break; + case 'b': + printf("%d",power[i]>treshold); + break; + case 'B': + if(power[i]>treshold) printf("true"); + else printf("false"); + break; + case 'f': + default: + printf("%.4f",power[i]); + } } puts(""); fflush(stdout); diff --git a/c/goertzel/sleepmon.sh b/c/goertzel/sleepmon.sh index a5d9d81..3ccc670 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 -q -l -t $tresh -d 4 | while read line; do +arecord | ./goertzel -n i -q -l -t $tresh -d 4 | while read line; do date="$(date +%s)" time="$(echo "$line" | cut -f 1)" level="$(echo "$line" | cut -f 2)"