-int main() {
- /*
- int samples[] = {0,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1};
- int samplecount = 18;
- float power = goertzel(samplecount, samples, 1.2, 18);
- printf("G: %f\n", power);
- */
+void print_help(char ** argv) {
+ printf(
+ "%s takes raw (wav) audio stream and computes power (or magnitude)\n"
+ "of desired frequencies using Goertzel algorithm for time frames\n"
+ "of fixed length (specified in samples or relative to sample rate).\n"
+ "This can be used in various frequency detection applications\n"
+ "like guitar tuning, DTMF decoding and many others...\n"
+ "\n"
+ "http://en.wikipedia.org/wiki/Goertzel_algorithm\n"
+ "\n"
+ "Curently only raw unsigned 8bit (u8) mono audio is supported, but\n"
+ "samplerate may vary. You can convert other formats before processing.\n"
+ "\n"
+ "On lower samplerates and frame sizes this may perform sub-optimally. Eg.:\n"
+ "When set to detect 440Hz (at 8000Hz samplerate and ~4000 samples)\n"
+ "it actually detects something around 438,3Hz rather than 400Hz...\n"
+ "If you can't increase samplerate way around this is just to increase sensitivity.\n"
+ "\n"
+ ,argv[0]
+ );
+
+ printf(
+ "Arguments:\n"
+ "\t-i <file>\tInput from file (default STDIN)\n"
+ "\t-o <file>\tOutput to file (default STDOUT)\n"
+ "\t-a <file>\tOutput to file (append) (default STDOUT)\n"
+ "\n"
+ "\t-r <samplerate>\tInput samplerate (deault 8000 Hz)\n"
+ "\t-c <count>\tFrame size in samples (default 4000 Samples)\n"
+ "\t-d <divisor>\tFrame size ( count = samplerate/divisor ) (default 2)\n"
+ "\n"
+ "\t-f <freq>\tAdd frequency in Hz to detect (use multiple times, default 440 Hz)\n"
+ "\n"
+ "\t-n <format>\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 <treshold>\tSet treshold (used in filter, see -l) (defaults -1)\n"
+ "\t-l <filter>\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-q\t\tQuiet mode: print only values\n"
+ "\n"
+ "\t-?\t\tPrint help\n"
+ "\n"
+ );
+
+ printf(
+ "Usage examples:\n"
+ "\tarecord | %s\n"
+ "\tsox input.mp3 -b 8 -c 1 -r 8000 -t wav - | %s\n"
+ "\t%s -n -q -l -r 8000 -d 20 -t $tresh -f 697 [-f 770 ...]\n"
+ "\n"
+ ,argv[0],argv[0],argv[0]
+ );
+
+ printf(
+ "Frequencies for DTMF decoding:\n"
+ "\t-f 697 -f 770 -f 852 -f 941 -f 1209 -f 1336 -f 1477 -f 1633 -t 10\n"
+ );
+}
+
+void addfreq(float *freqs, float freq) {
+ int i = 0;
+ while(freqs[i]!=-1) i++;
+ freqs[i]=freq;
+ freqs[i+1]=-1;
+}