X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;ds=sidebyside;f=c%2Fgoertzel%2Fgoertzel.c;h=f22a1fcb1a911c011008ba7c266e279e46b6e6ef;hb=3e5828b5bfdae6ef1457d8e44c551369e12e467b;hp=96458a5b83c7cc2cacf5bd4536276df77c17221c;hpb=8f751717d8307e3aa09fdfee19bed9478b7b16be;p=mirrors%2FPrograms.git diff --git a/c/goertzel/goertzel.c b/c/goertzel/goertzel.c index 96458a5..f22a1fc 100644 --- a/c/goertzel/goertzel.c +++ b/c/goertzel/goertzel.c @@ -65,14 +65,23 @@ void print_help(char ** argv) { "\n" "\t-r \tInput samplerate (deault 8000 Hz)\n" "\t-c \tFrame size in samples (default 4000 Samples)\n" - "\t-d \tFrame size (default 2) (samplerate will be divided by this number to get frame size same as -c)\n" + "\t-d \tFrame size ( count = samplerate/divisor ) (default 2)\n" "\n" - "\t-f \tAdd frequency in Hz to detect (use multiple times, if no added 440 Hz will be...)\n" + "\t-f \tAdd frequency in Hz to detect (use multiple times, default 440 Hz)\n" + "\n" + "\t-n \tSet number output format\n" + "\t\tf: float\t23.4223 (default)\n" + "\t\ti: integer\t23\n" + "\t\tb: binary\t(0|1)\n" + "\t\tB: Boolean\t(false|true)\n" + "\n" + "\t-t \tSet treshold (used in filter, see -l) (defaults -1)\n" + "\t-l \tSet line filter\n" + "\t\tf: Falldown:\tprint only when over treshold or just crossed (default)\n" + "\t\tt: Treshold:\tprint only when over treshold\n" + "\t\tc: Crossed:\tprint only when treshold crossed\n" + "\t-u\t\tInvert\ttreshold (values under treshold will be displayed)\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-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" "\n" "\t-?\t\tPrint help\n" @@ -104,15 +113,18 @@ void addfreq(int *freqs, int freq) { int main(int argc, char ** argv) { int samplerate = 8000; int samplecount = 4000; + int treshold = -1; - char noreturn = 0; - char repeat = 1; - char integers=0; + char filter = 0; + char under = 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:l:uq")) != -1) { switch (opt) { case 'i': freopen(optarg, "r", stdin); @@ -139,13 +151,13 @@ int main(int argc, char ** argv) { treshold = atoi(optarg); break; case 'n': - integers = 1; + format = optarg[0]; break; case 'l': - repeat = 0; + filter = optarg[0]; break; - case 'b': - noreturn = 1; + case 'u': + under = 1; break; case 'q': verbose = 0; @@ -178,9 +190,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 = under ? power[i] < treshold : power[i] > treshold; //Is over/under 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 @@ -208,10 +230,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)round(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);