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;
40 extern char_t * pitch_method;
41 extern char_t * pitch_unit;
42 extern smpl_t pitch_tolerance;
44 extern uint_t time_format;
46 extern char_t * tempo_method;
48 extern smpl_t silence_threshold;
49 extern uint_t mix_input;
51 extern smpl_t miditap_note;
52 extern smpl_t miditap_velo;
54 extern uint_t force_overwrite;
56 // functions defined in utils.c
57 extern void examples_common_init (int argc, char **argv);
58 extern void examples_common_del (void);
59 extern void examples_common_process (aubio_process_func_t process_func,
60 aubio_print_func_t print);
61 int parse_args (int argc, char **argv);
69 const char *prog_name;
71 void usage (FILE * stream, int exit_code);
73 void usage (FILE * stream, int exit_code)
76 fprintf (stream, "usage: %s [ options ] \n", prog_name);
78 " -i --input input file\n"
79 #ifdef PROG_HAS_OUTPUT
80 " -o --output output file\n"
82 " -r --samplerate select samplerate\n"
83 " use 0 to use input source samplerate, or 32000 to force 32kHz\n"
84 " -B --bufsize set buffer size\n"
85 " number of frames to run the analysis on\n"
86 " -H --hopsize set hopsize\n"
87 " number of frames to read from source before each analysis\n"
89 " -O --onset select onset detection algorithm\n"
90 " <default|energy|hfc|complex|phase|specdiff|kl|mkl|specflux>;\n"
92 " -t --onset-threshold set onset detection threshold\n"
93 " a value between 0.1 (more detections) and 1 (less); default=0.3\n"
94 #endif /* PROG_HAS_ONSET */
96 " -p --pitch select pitch detection algorithm\n"
97 " <default|yinfft|yin|mcomb|fcomb|schmitt>; default=yinfft\n"
98 " -u --pitch-unit select pitch output unit\n"
99 " <default|freq|hertz|Hz|midi|cent|bin>; default=freq\n"
100 " -l --pitch-tolerance select pitch tolerance\n"
101 " (yin, yinfft only) a value between 0.1 and 0.7; default=0.3\n"
102 #endif /* PROG_HAS_PITCH */
103 #ifdef PROG_HAS_SILENCE
104 " -s --silence select silence threshold\n"
105 " a value in dB, for instance -70, or -100; default=-90\n"
106 #endif /* PROG_HAS_SILENCE */
107 " -T --time-format select time values output format\n"
108 " (samples, ms, seconds) default=seconds\n"
109 #ifdef PROG_HAS_OUTPUT
110 " -m --mix-input mix input signal with output signal\n"
111 " input signal will be added to output synthesis\n"
112 " -f --force-overwrite overwrite output file if needed\n"
113 " do not fail if output file already exists\n"
114 #endif /* PROG_HAS_OUTPUT */
116 " -j --jack use Jack\n"
117 #endif /* PROG_HAS_JACK */
118 " -v --verbose be verbose\n"
119 " -h --help display this message\n"
121 #else /* HAVE_GETOPT_H */
122 fprintf (stream, "warning: compiled with getopt.h, no argument parsing\n");
123 fprintf (stream, "usage: %s <filename> \n", prog_name);
124 #endif /* HAVE_GETOPT_H */
129 parse_args (int argc, char **argv)
132 const char *options = "hv"
136 #endif /* PROG_HAS_JACK */
137 #ifdef PROG_HAS_OUTPUT
139 #endif /* PROG_HAS_OUTPUT */
140 #ifdef PROG_HAS_ONSET
142 #endif /* PROG_HAS_ONSET */
143 #ifdef PROG_HAS_PITCH
145 #endif /* PROG_HAS_PITCH */
147 #ifdef PROG_HAS_SILENCE
149 #endif /* PROG_HAS_SILENCE */
150 #ifdef PROG_HAS_OUTPUT
152 #endif /* PROG_HAS_OUTPUT */
155 struct option long_options[] = {
156 {"help", 0, NULL, 'h'},
157 {"verbose", 0, NULL, 'v'},
158 {"input", 1, NULL, 'i'},
159 {"samplerate", 1, NULL, 'r'},
160 {"bufsize", 1, NULL, 'B'},
161 {"hopsize", 1, NULL, 'H'},
163 {"jack", 0, NULL, 'j'},
164 #endif /* PROG_HAS_JACK */
165 #ifdef PROG_HAS_OUTPUT
166 {"output", 1, NULL, 'o'},
167 #endif /* PROG_HAS_OUTPUT */
168 #ifdef PROG_HAS_ONSET
169 {"onset", 1, NULL, 'O'},
170 {"onset-threshold", 1, NULL, 't'},
171 #endif /* PROG_HAS_ONSET */
172 #ifdef PROG_HAS_PITCH
173 {"pitch", 1, NULL, 'p'},
174 {"pitch-unit", 1, NULL, 'u'},
175 {"pitch-tolerance", 1, NULL, 'l'},
176 #endif /* PROG_HAS_PITCH */
177 #ifdef PROG_HAS_SILENCE
178 {"silence", 1, NULL, 's'},
179 #endif /* PROG_HAS_SILENCE */
180 {"time-format", 1, NULL, 'T'},
181 #ifdef PROG_HAS_OUTPUT
182 {"mix-input", 0, NULL, 'm'},
183 {"force-overwrite", 0, NULL, 'f'},
184 #endif /* PROG_HAS_OUTPUT */
187 #endif /* HAVE_GETOPT_H */
195 next_option = getopt_long (argc, argv, options, long_options, NULL);
196 switch (next_option) {
200 case 'v': /* verbose */
212 case 'f': /* force_overwrite flag */
216 samplerate = atoi (optarg);
219 buffer_size = atoi (optarg);
222 hop_size = atoi (optarg);
224 case 'O': /*onset method */
225 onset_method = optarg;
227 case 't': /* threshold value for onset */
228 onset_threshold = (smpl_t) atof (optarg);
231 pitch_method = optarg;
237 pitch_tolerance = (smpl_t) atof (optarg);
240 if (strcmp (optarg, "samples") == 0) {
242 } else if (strcmp (optarg, "ms") == 0) {
244 } else if (strcmp (optarg, "seconds") == 0) {
247 errmsg ("Warning: did not get '%s' time-format string\n", optarg);
250 case 's': /* silence threshold */
251 silence_threshold = (smpl_t) atof (optarg);
253 case 'm': /* mix_input flag */
256 case '?': /* unknown options */
259 case -1: /* done with options */
261 default: /*something else unexpected */
262 fprintf (stderr, "Error parsing option '%c'\n", next_option);
266 while (next_option != -1);
267 #else /* HAVE_GETOPT_H */
269 #endif /* HAVE_GETOPT_H */
271 // if unique, use the non option argument as the source
272 if ( source_uri == NULL ) {
273 if (argc - optind == 1) {
274 source_uri = argv[optind];
275 } else if ( argc - optind > 1 ) {
276 errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]);
279 } else if ( argc - optind > 0 ) {
280 errmsg ("Error: extra non-option argument %s\n", argv[optind]);
284 // if no source, show a message
285 if (source_uri == NULL) {
288 verbmsg("No input source given, using jack\n");
291 errmsg("Error: no arguments given (and no available audio input)\n");
293 #endif /* HAVE_JACK */
295 errmsg("Error: no arguments given\n");
297 #endif /* PROG_HAS_JACK */
300 if ((sint_t)hop_size < 1) {
301 errmsg("Error: got hop_size %d, but can not be < 1\n", hop_size);
303 } else if ((sint_t)buffer_size < 2) {
304 errmsg("Error: got buffer_size %d, but can not be < 2\n", buffer_size);
306 } else if ((sint_t)buffer_size < (sint_t)hop_size) {
307 errmsg("Error: hop size (%d) is larger than win size (%d)\n",
308 hop_size, buffer_size);
312 if ((sint_t)samplerate < 0) {
313 errmsg("Error: got samplerate %d, but can not be < 0\n", samplerate);