2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
6 aubio is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 aubio is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with aubio. If not, see <http://www.gnu.org/licenses/>.
24 extern char_t *source_uri;
25 extern char_t *sink_uri;
27 extern uint_t samplerate;
28 extern uint_t buffer_size;
29 extern uint_t hop_size;
31 extern char_t * onset_method;
32 extern smpl_t onset_threshold;
34 extern char_t * pitch_method;
35 extern char_t * pitch_unit;
36 extern smpl_t pitch_tolerance;
38 extern char_t * tempo_method;
40 extern smpl_t silence;
41 extern uint_t mix_input;
43 typedef int (*aubio_process_func_t)(fvec_t * input, fvec_t * output);
45 // functions defined in utils.c
46 extern void examples_common_init (int argc, char **argv);
47 extern void examples_common_del (void);
48 extern void examples_common_process (aubio_process_func_t process_func,
49 aubio_print_func_t print);
57 const char *prog_name;
60 usage (FILE * stream, int exit_code)
62 fprintf (stream, "usage: %s [ options ] \n", prog_name);
64 " -h --help display this message\n"
65 " -v --verbose be verbose\n"
67 " -j --jack use Jack\n"
69 " -i --input input type\n"
70 #ifdef PROG_HAS_OUTPUT
71 " -o --output output type\n"
73 " -r --samplerate select samplerate\n"
74 " -B --bufsize set buffer size\n"
75 " -H --hopsize set hopsize\n"
77 " -O --onset select onset detection algorithm\n"
78 " -t --onset-threshold set onset detection threshold\n"
79 #endif /* PROG_HAS_ONSET */
81 " -p --pitch select pitch detection algorithm\n"
82 " -u --pitch-unit select pitch output unit\n"
83 " -l --pitch-tolerance select pitch tolerance\n"
84 #endif /* PROG_HAS_PITCH */
85 " -s --silence select silence threshold\n"
86 #ifdef PROG_HAS_OUTPUT
87 " -m --mix-input mix input signal with output signal\n"
94 parse_args (int argc, char **argv)
96 const char *options = "hv"
100 #endif /* PROG_HAS_JACK */
101 #ifdef PROG_HAS_OUTPUT
103 #endif /* PROG_HAS_OUTPUT */
104 #ifdef PROG_HAS_ONSET
106 #endif /* PROG_HAS_ONSET */
107 #ifdef PROG_HAS_PITCH
109 #endif /* PROG_HAS_PITCH */
112 struct option long_options[] = {
113 {"help", 0, NULL, 'h'},
114 {"verbose", 0, NULL, 'v'},
115 {"input", 1, NULL, 'i'},
116 {"samplerate", 1, NULL, 'r'},
117 {"bufsize", 1, NULL, 'B'},
118 {"hopsize", 1, NULL, 'H'},
120 {"jack", 0, NULL, 'j'},
121 #endif /* PROG_HAS_JACK */
122 #ifdef PROG_HAS_OUTPUT
123 {"output", 1, NULL, 'o'},
124 #endif /* PROG_HAS_OUTPUT */
125 #ifdef PROG_HAS_ONSET
126 {"onset", 1, NULL, 'O'},
127 {"onset-threshold", 1, NULL, 't'},
128 #endif /* PROG_HAS_ONSET */
129 #ifdef PROG_HAS_PITCH
130 {"pitch", 1, NULL, 'p'},
131 {"pitch-unit", 1, NULL, 'u'},
132 {"pitch-tolerance", 1, NULL, 'l'},
133 #endif /* PROG_HAS_PITCH */
134 {"silence", 1, NULL, 's'},
135 {"mix-input", 0, NULL, 'm'},
144 next_option = getopt_long (argc, argv, options, long_options, NULL);
145 switch (next_option) {
149 case 'v': /* verbose */
162 samplerate = atoi (optarg);
165 buffer_size = atoi (optarg);
168 hop_size = atoi (optarg);
170 case 'O': /*onset type */
171 onset_method = optarg;
173 case 't': /* threshold value for onset */
174 onset_threshold = (smpl_t) atof (optarg);
177 pitch_method = optarg;
183 pitch_tolerance = (smpl_t) atof (optarg);
185 case 's': /* silence threshold */
186 silence = (smpl_t) atof (optarg);
188 case 'm': /* mix_input flag */
191 case '?': /* unknown options */
194 case -1: /* done with options */
196 default: /*something else unexpected */
197 fprintf (stderr, "Error parsing option '%c'\n", next_option);
201 while (next_option != -1);
203 // if unique, use the non option argument as the source
204 if ( source_uri == NULL ) {
205 if (argc - optind == 1) {
206 source_uri = argv[optind];
207 } else if ( argc - optind > 1 ) {
208 errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]);
211 } else if ( argc - optind > 0 ) {
212 errmsg ("Error: extra non-option argument %s\n", argv[optind]);
216 // if no source, show a message
217 if (source_uri == NULL) {
220 verbmsg("No input source given, using jack\n");
223 errmsg("Error: no arguments given (and no available audio input)\n");
225 #endif /* HAVE_JACK */
227 errmsg("Error: no arguments given\n");
229 #endif /* PROG_HAS_JACK */