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/>.
30 extern char_t *source_uri;
31 extern char_t *sink_uri;
33 extern uint_t samplerate;
34 extern uint_t buffer_size;
35 extern uint_t hop_size;
37 extern char_t * onset_method;
38 extern smpl_t onset_threshold;
39 extern smpl_t onset_minioi;
41 extern char_t * pitch_method;
42 extern char_t * pitch_unit;
43 extern smpl_t pitch_tolerance;
45 extern uint_t time_format;
47 extern char_t * tempo_method;
49 extern smpl_t silence_threshold;
50 extern smpl_t release_drop;
51 extern uint_t mix_input;
53 extern smpl_t miditap_note;
54 extern smpl_t miditap_velo;
56 extern uint_t force_overwrite;
58 // functions defined in utils.c
59 extern void examples_common_init (int argc, char **argv);
60 extern void examples_common_del (void);
61 extern void examples_common_process (aubio_process_func_t process_func,
62 aubio_print_func_t print);
63 int parse_args (int argc, char **argv);
71 const char *prog_name;
73 void usage (FILE * stream, int exit_code);
75 void usage (FILE * stream, int exit_code)
78 fprintf (stream, "usage: %s [ options ] \n", prog_name);
80 " -i --input input file\n"
81 #ifdef PROG_HAS_OUTPUT
82 " -o --output output file\n"
84 " -r --samplerate select samplerate\n"
85 " use 0 to use input source samplerate, or 32000 to force 32kHz\n"
86 " -B --bufsize set buffer size\n"
87 " number of frames to run the analysis on\n"
88 " -H --hopsize set hopsize\n"
89 " number of frames to read from source before each analysis\n"
91 " -O --onset select onset detection algorithm\n"
92 " <default|energy|hfc|complex|phase|specdiff|kl|mkl|specflux>;\n"
94 " -t --onset-threshold set onset detection threshold\n"
95 " a value between 0.1 (more detections) and 1 (less); default=0.3\n"
96 " -M --minioi set minimum inter-onset interval\n"
97 " a value in second; default=0.012\n"
98 #endif /* PROG_HAS_ONSET */
100 " -p --pitch select pitch detection algorithm\n"
101 " <default|yinfft|yinfast|yin|mcomb|fcomb|schmitt>; default=yinfft\n"
102 " -u --pitch-unit select pitch output unit\n"
103 " <default|freq|hertz|Hz|midi|cent|bin>; default=freq\n"
104 " -l --pitch-tolerance select pitch tolerance\n"
105 " (yin, yinfft only) a value between 0.1 and 0.7; default=0.3\n"
106 #endif /* PROG_HAS_PITCH */
107 #ifdef PROG_HAS_SILENCE
108 " -s --silence select silence threshold\n"
109 " a value in dB, for instance -70, or -100; default=-90\n"
110 #endif /* PROG_HAS_SILENCE */
111 #ifdef PROG_HAS_NOTES
112 " -d --release-drop select release drop threshold\n"
113 " a positive value in dB; default=10\n"
115 " -T --time-format select time values output format\n"
116 " (samples, ms, seconds) default=seconds\n"
117 #ifdef PROG_HAS_OUTPUT
118 " -m --mix-input mix input signal with output signal\n"
119 " input signal will be added to output synthesis\n"
120 " -f --force-overwrite overwrite output file if needed\n"
121 " do not fail if output file already exists\n"
122 #endif /* PROG_HAS_OUTPUT */
123 #if defined(PROG_HAS_JACK) && defined(HAVE_JACK)
124 " -j --jack use Jack\n"
125 #if defined(PROG_HAS_ONSET) && !defined(PROG_HAS_PITCH)
126 " -N --miditap-note MIDI note; default=69.\n"
127 " -V --miditap-velo MIDI velocity; default=65.\n"
128 #endif /* defined(PROG_HAS_ONSET) && !defined(PROG_HAS_PITCH) */
129 #endif /* defined(PROG_HAS_JACK) && defined(HAVE_JACK) */
130 " -v --verbose be verbose\n"
131 " -h --help display this message\n"
133 #else /* HAVE_GETOPT_H */
134 fprintf (stream, "warning: compiled with getopt.h, no argument parsing\n");
135 fprintf (stream, "usage: %s <filename> \n", prog_name);
136 #endif /* HAVE_GETOPT_H */
141 parse_args (int argc, char **argv)
144 const char *options = "hv"
148 #if defined(PROG_HAS_ONSET) && !defined(PROG_HAS_PITCH)
150 #endif /* defined(PROG_HAS_ONSET) && !defined(PROG_HAS_PITCH) */
151 #endif /* PROG_HAS_JACK */
152 #ifdef PROG_HAS_OUTPUT
154 #endif /* PROG_HAS_OUTPUT */
155 #ifdef PROG_HAS_ONSET
157 #endif /* PROG_HAS_ONSET */
158 #ifdef PROG_HAS_PITCH
160 #endif /* PROG_HAS_PITCH */
162 #ifdef PROG_HAS_SILENCE
164 #endif /* PROG_HAS_SILENCE */
165 #ifdef PROG_HAS_NOTES
167 #endif /* PROG_HAS_SILENCE */
168 #ifdef PROG_HAS_OUTPUT
170 #endif /* PROG_HAS_OUTPUT */
173 struct option long_options[] = {
174 {"help", 0, NULL, 'h'},
175 {"verbose", 0, NULL, 'v'},
176 {"input", 1, NULL, 'i'},
177 {"samplerate", 1, NULL, 'r'},
178 {"bufsize", 1, NULL, 'B'},
179 {"hopsize", 1, NULL, 'H'},
181 {"jack", 0, NULL, 'j'},
182 #if defined(PROG_HAS_ONSET) && !defined(PROG_HAS_PITCH)
183 {"miditap-note", 1, NULL, 'N'},
184 {"miditap-velo", 1, NULL, 'V'},
185 #endif /* PROG_HAS_ONSET !PROG_HAS_PITCH */
186 #endif /* PROG_HAS_JACK */
187 #ifdef PROG_HAS_OUTPUT
188 {"output", 1, NULL, 'o'},
189 #endif /* PROG_HAS_OUTPUT */
190 #ifdef PROG_HAS_ONSET
191 {"onset", 1, NULL, 'O'},
192 {"onset-threshold", 1, NULL, 't'},
193 {"onset-minioi", 1, NULL, 'M'},
194 #endif /* PROG_HAS_ONSET */
195 #ifdef PROG_HAS_PITCH
196 {"pitch", 1, NULL, 'p'},
197 {"pitch-unit", 1, NULL, 'u'},
198 {"pitch-tolerance", 1, NULL, 'l'},
199 #endif /* PROG_HAS_PITCH */
200 #ifdef PROG_HAS_SILENCE
201 {"silence", 1, NULL, 's'},
202 #endif /* PROG_HAS_SILENCE */
203 #ifdef PROG_HAS_NOTES
204 {"release-drop", 1, NULL, 'd'},
205 #endif /* PROG_HAS_NOTES */
206 {"time-format", 1, NULL, 'T'},
207 #ifdef PROG_HAS_OUTPUT
208 {"mix-input", 0, NULL, 'm'},
209 {"force-overwrite", 0, NULL, 'f'},
210 #endif /* PROG_HAS_OUTPUT */
213 #endif /* HAVE_GETOPT_H */
221 next_option = getopt_long (argc, argv, options, long_options, NULL);
222 switch (next_option) {
226 case 'v': /* verbose */
233 miditap_note = (smpl_t) atoi (optarg);
236 miditap_velo = (smpl_t) atoi (optarg);
244 case 'f': /* force_overwrite flag */
248 samplerate = atoi (optarg);
251 buffer_size = atoi (optarg);
254 hop_size = atoi (optarg);
256 case 'O': /*onset method */
257 onset_method = optarg;
259 case 't': /* threshold value for onset */
260 onset_threshold = (smpl_t) atof (optarg);
262 case 'M': /* minimum inter-onset-interval */
263 onset_minioi = (smpl_t) atof (optarg);
266 pitch_method = optarg;
272 pitch_tolerance = (smpl_t) atof (optarg);
275 if (strcmp (optarg, "samples") == 0) {
277 } else if (strcmp (optarg, "ms") == 0) {
279 } else if (strcmp (optarg, "seconds") == 0) {
282 errmsg ("Warning: did not get '%s' time-format string\n", optarg);
285 case 's': /* silence threshold */
286 silence_threshold = (smpl_t) atof (optarg);
288 case 'd': /* release-drop threshold */
289 release_drop = (smpl_t) atof (optarg);
291 case 'm': /* mix_input flag */
294 case '?': /* unknown options */
297 case -1: /* done with options */
299 default: /*something else unexpected */
300 fprintf (stderr, "Error parsing option '%c'\n", next_option);
304 while (next_option != -1);
305 #else /* HAVE_GETOPT_H */
307 #endif /* HAVE_GETOPT_H */
309 // if unique, use the non option argument as the source
310 if ( source_uri == NULL ) {
311 if (argc - optind == 1) {
312 source_uri = argv[optind];
313 } else if ( argc - optind > 1 ) {
314 errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]);
317 } else if ( argc - optind > 0 ) {
318 errmsg ("Error: extra non-option argument %s\n", argv[optind]);
322 // if no source, show a message
323 if (source_uri == NULL) {
326 verbmsg("No input source given, using jack\n");
329 errmsg("Error: no arguments given (and no available audio input)\n");
330 errmsg(" consider recompiling with jack support (--enable-jack)\n");
332 #endif /* HAVE_JACK */
334 errmsg("Error: no arguments given\n");
336 #endif /* PROG_HAS_JACK */
339 if ((sint_t)hop_size < 1) {
340 errmsg("Error: got hop_size %d, but can not be < 1\n", hop_size);
342 } else if ((sint_t)buffer_size < 2) {
343 errmsg("Error: got buffer_size %d, but can not be < 2\n", buffer_size);
345 } else if ((sint_t)buffer_size < (sint_t)hop_size) {
346 errmsg("Error: hop size (%d) is larger than win size (%d)\n",
347 hop_size, buffer_size);
351 if ((sint_t)samplerate < 0) {
352 errmsg("Error: got samplerate %d, but can not be < 0\n", samplerate);