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/>.
31 extern char_t *source_uri;
32 extern char_t *sink_uri;
34 extern uint_t samplerate;
35 extern uint_t buffer_size;
36 extern uint_t hop_size;
38 extern char_t * onset_method;
39 extern smpl_t onset_threshold;
40 extern smpl_t onset_minioi;
42 extern char_t * pitch_method;
43 extern char_t * pitch_unit;
44 extern smpl_t pitch_tolerance;
46 extern uint_t time_format;
48 extern char_t * tempo_method;
50 extern smpl_t silence_threshold;
51 extern smpl_t release_drop;
52 extern uint_t mix_input;
54 extern smpl_t miditap_note;
55 extern smpl_t miditap_velo;
57 extern uint_t force_overwrite;
59 // functions defined in utils.c
60 extern void examples_common_init (int argc, char **argv);
61 extern void examples_common_del (void);
62 extern void examples_common_process (aubio_process_func_t process_func,
63 aubio_print_func_t print);
64 int parse_args (int argc, char **argv);
69 extern fvec_t *input_buffer;
70 extern fvec_t *output_buffer;
72 const char *prog_name;
74 void usage (FILE * stream, int exit_code);
76 void usage (FILE * stream, int exit_code)
79 fprintf (stream, "usage: %s [ options ] \n", prog_name);
81 " -i --input input file\n"
82 #ifdef PROG_HAS_OUTPUT
83 " -o --output output file\n"
85 " -r --samplerate select samplerate\n"
86 " use 0 to use input source samplerate, or 32000 to force 32kHz\n"
87 " -B --bufsize set buffer size\n"
88 " number of frames to run the analysis on\n"
89 " -H --hopsize set hopsize\n"
90 " number of frames to read from source before each analysis\n"
92 " -O --onset select onset detection algorithm\n"
93 " <default|energy|hfc|complex|phase|specdiff|kl|mkl|specflux>;\n"
95 " -t --onset-threshold set onset detection threshold\n"
96 " a value between 0.1 (more detections) and 1 (less); default=0.3\n"
97 " -M --minioi set minimum inter-onset interval\n"
98 " a value in second; default=0.012\n"
99 #endif /* PROG_HAS_ONSET */
100 #ifdef PROG_HAS_PITCH
101 " -p --pitch select pitch detection algorithm\n"
102 " <default|yinfft|yinfast|yin|mcomb|fcomb|schmitt>; default=yinfft\n"
103 " -u --pitch-unit select pitch output unit\n"
104 " <default|freq|hertz|Hz|midi|cent|bin>; default=freq\n"
105 " -l --pitch-tolerance select pitch tolerance\n"
106 " (yin, yinfft only) a value between 0.1 and 0.7; default=0.3\n"
107 #endif /* PROG_HAS_PITCH */
108 #ifdef PROG_HAS_SILENCE
109 " -s --silence select silence threshold\n"
110 " a value in dB, for instance -70, or -100; default=-90\n"
111 #endif /* PROG_HAS_SILENCE */
112 #ifdef PROG_HAS_NOTES
113 " -d --release-drop select release drop threshold\n"
114 " a positive value in dB; default=10\n"
116 " -T --time-format select time values output format\n"
117 " (samples, ms, seconds) default=seconds\n"
118 #ifdef PROG_HAS_OUTPUT
119 " -m --mix-input mix input signal with output signal\n"
120 " input signal will be added to output synthesis\n"
121 " -f --force-overwrite overwrite output file if needed\n"
122 " do not fail if output file already exists\n"
123 #endif /* PROG_HAS_OUTPUT */
124 #if defined(PROG_HAS_JACK) && defined(HAVE_JACK)
125 " -j --jack use Jack\n"
126 #if defined(PROG_HAS_ONSET) && !defined(PROG_HAS_PITCH)
127 " -N --miditap-note MIDI note; default=69.\n"
128 " -V --miditap-velo MIDI velocity; default=65.\n"
129 #endif /* defined(PROG_HAS_ONSET) && !defined(PROG_HAS_PITCH) */
130 #endif /* defined(PROG_HAS_JACK) && defined(HAVE_JACK) */
131 " -q --quiet be quiet\n"
132 " -v --verbose be verbose\n"
133 " -h --help display this message\n"
135 #else /* HAVE_GETOPT_H */
136 fprintf (stream, "warning: compiled with getopt.h, no argument parsing\n");
137 fprintf (stream, "usage: %s <filename> \n", prog_name);
138 #endif /* HAVE_GETOPT_H */
143 parse_args (int argc, char **argv)
146 const char *options = "hvq"
150 #if defined(PROG_HAS_ONSET) && !defined(PROG_HAS_PITCH)
152 #endif /* defined(PROG_HAS_ONSET) && !defined(PROG_HAS_PITCH) */
153 #endif /* PROG_HAS_JACK */
154 #ifdef PROG_HAS_OUTPUT
156 #endif /* PROG_HAS_OUTPUT */
157 #ifdef PROG_HAS_ONSET
159 #endif /* PROG_HAS_ONSET */
160 #ifdef PROG_HAS_PITCH
162 #endif /* PROG_HAS_PITCH */
164 #ifdef PROG_HAS_SILENCE
166 #endif /* PROG_HAS_SILENCE */
167 #ifdef PROG_HAS_NOTES
169 #endif /* PROG_HAS_SILENCE */
170 #ifdef PROG_HAS_OUTPUT
172 #endif /* PROG_HAS_OUTPUT */
175 struct option long_options[] = {
176 {"help", 0, NULL, 'h'},
177 {"verbose", 0, NULL, 'v'},
178 {"quiet", 0, NULL, 'q'},
179 {"input", 1, NULL, 'i'},
180 {"samplerate", 1, NULL, 'r'},
181 {"bufsize", 1, NULL, 'B'},
182 {"hopsize", 1, NULL, 'H'},
184 {"jack", 0, NULL, 'j'},
185 #if defined(PROG_HAS_ONSET) && !defined(PROG_HAS_PITCH)
186 {"miditap-note", 1, NULL, 'N'},
187 {"miditap-velo", 1, NULL, 'V'},
188 #endif /* PROG_HAS_ONSET !PROG_HAS_PITCH */
189 #endif /* PROG_HAS_JACK */
190 #ifdef PROG_HAS_OUTPUT
191 {"output", 1, NULL, 'o'},
192 #endif /* PROG_HAS_OUTPUT */
193 #ifdef PROG_HAS_ONSET
194 {"onset", 1, NULL, 'O'},
195 {"onset-threshold", 1, NULL, 't'},
196 {"onset-minioi", 1, NULL, 'M'},
197 #endif /* PROG_HAS_ONSET */
198 #ifdef PROG_HAS_PITCH
199 {"pitch", 1, NULL, 'p'},
200 {"pitch-unit", 1, NULL, 'u'},
201 {"pitch-tolerance", 1, NULL, 'l'},
202 #endif /* PROG_HAS_PITCH */
203 #ifdef PROG_HAS_SILENCE
204 {"silence", 1, NULL, 's'},
205 #endif /* PROG_HAS_SILENCE */
206 #ifdef PROG_HAS_NOTES
207 {"release-drop", 1, NULL, 'd'},
208 #endif /* PROG_HAS_NOTES */
209 {"time-format", 1, NULL, 'T'},
210 #ifdef PROG_HAS_OUTPUT
211 {"mix-input", 0, NULL, 'm'},
212 {"force-overwrite", 0, NULL, 'f'},
213 #endif /* PROG_HAS_OUTPUT */
216 #endif /* HAVE_GETOPT_H */
217 // better safe than sorry
224 next_option = getopt_long (argc, argv, options, long_options, NULL);
225 switch (next_option) {
229 case 'v': /* verbose */
232 case 'q': /* quiet */
239 miditap_note = (smpl_t) atoi (optarg);
242 miditap_velo = (smpl_t) atoi (optarg);
250 case 'f': /* force_overwrite flag */
254 samplerate = atoi (optarg);
257 buffer_size = atoi (optarg);
260 hop_size = atoi (optarg);
262 case 'O': /*onset method */
263 onset_method = optarg;
265 case 't': /* threshold value for onset */
266 onset_threshold = (smpl_t) atof (optarg);
268 case 'M': /* minimum inter-onset-interval */
269 onset_minioi = (smpl_t) atof (optarg);
272 pitch_method = optarg;
278 pitch_tolerance = (smpl_t) atof (optarg);
281 if (strcmp (optarg, "samples") == 0) {
283 } else if (strcmp (optarg, "ms") == 0) {
285 } else if (strcmp (optarg, "seconds") == 0) {
288 errmsg ("Warning: did not get '%s' time-format string\n", optarg);
291 case 's': /* silence threshold */
292 silence_threshold = (smpl_t) atof (optarg);
294 case 'd': /* release-drop threshold */
295 release_drop = (smpl_t) atof (optarg);
297 case 'm': /* mix_input flag */
300 case '?': /* unknown options */
303 case -1: /* done with options */
305 default: /*something else unexpected */
306 fprintf (stderr, "Error parsing option '%c'\n", next_option);
310 while (next_option != -1);
311 #else /* HAVE_GETOPT_H */
313 #endif /* HAVE_GETOPT_H */
315 // if unique, use the non option argument as the source
316 if ( source_uri == NULL ) {
317 if (argc - optind == 1) {
318 source_uri = argv[optind];
319 } else if ( argc - optind > 1 ) {
320 errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]);
323 } else if ( argc - optind > 0 ) {
324 errmsg ("Error: extra non-option argument %s\n", argv[optind]);
328 // if no source, show a message
329 if (source_uri == NULL) {
332 verbmsg("No input source given, using jack\n");
335 errmsg("Error: no arguments given (and no available audio input)\n");
336 errmsg(" consider recompiling with jack support (--enable-jack)\n");
338 #endif /* HAVE_JACK */
340 errmsg("Error: no arguments given\n");
342 #endif /* PROG_HAS_JACK */
345 if ((sint_t)hop_size < 1) {
346 errmsg("Error: got hop_size %d, but can not be < 1\n", hop_size);
348 } else if ((sint_t)buffer_size < 2) {
349 errmsg("Error: got buffer_size %d, but can not be < 2\n", buffer_size);
351 } else if ((sint_t)buffer_size < (sint_t)hop_size) {
352 errmsg("Error: hop size (%d) is larger than win size (%d)\n",
353 hop_size, buffer_size);
357 if ((sint_t)samplerate < 0) {
358 errmsg("Error: got samplerate %d, but can not be < 0\n", samplerate);