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 * time_format;
40 extern char_t * tempo_method;
42 extern smpl_t silence_threshold;
43 extern uint_t mix_input;
45 extern uint_t force_overwrite;
47 // functions defined in utils.c
48 extern void examples_common_init (int argc, char **argv);
49 extern void examples_common_del (void);
50 extern void examples_common_process (aubio_process_func_t process_func,
51 aubio_print_func_t print);
52 int parse_args (int argc, char **argv);
60 const char *prog_name;
62 void usage (FILE * stream, int exit_code);
64 void usage (FILE * stream, int exit_code)
66 fprintf (stream, "usage: %s [ options ] \n", prog_name);
68 " -i --input input file\n"
69 #ifdef PROG_HAS_OUTPUT
70 " -o --output output file\n"
72 " -r --samplerate select samplerate\n"
73 " use 0 to use input source samplerate, or 32000 to force 32kHz\n"
74 " -B --bufsize set buffer size\n"
75 " number of frames to run the analysis on\n"
76 " -H --hopsize set hopsize\n"
77 " number of frames to read from source before each analysis\n"
79 " -O --onset select onset detection algorithm\n"
80 " <default|energy|hfc|complex|phase|specdiff|kl|mkl|specflux>;\n"
82 " -t --onset-threshold set onset detection threshold\n"
83 " a value between 0.1 (more detections) and 1 (less); default=0.3\n"
84 #endif /* PROG_HAS_ONSET */
86 " -p --pitch select pitch detection algorithm\n"
87 " <default|yinfft|yin|mcomb|fcomb|schmitt>; default=yinfft\n"
88 " -u --pitch-unit select pitch output unit\n"
89 " <default|freq|hertz|Hz|midi|cent|bin>; default=freq\n"
90 " -l --pitch-tolerance select pitch tolerance\n"
91 " (yin, yinfft only) a value between 0.1 and 0.7; default=0.3\n"
92 #endif /* PROG_HAS_PITCH */
93 " -s --silence select silence threshold\n"
94 " a value in dB, for instance -70, or -100; default=-90\n"
95 " -T --time-format select time values output format\n"
96 " (samples, ms, seconds) default=seconds\n"
97 #ifdef PROG_HAS_OUTPUT
98 " -m --mix-input mix input signal with output signal\n"
99 " input signal will be added to output synthesis\n"
100 " -f --force-overwrite overwrite output file if needed\n"
101 " do not fail if output file already exists\n"
104 " -j --jack use Jack\n"
106 " -v --verbose be verbose\n"
107 " -h --help display this message\n"
113 parse_args (int argc, char **argv)
115 const char *options = "hv"
119 #endif /* PROG_HAS_JACK */
120 #ifdef PROG_HAS_OUTPUT
122 #endif /* PROG_HAS_OUTPUT */
123 #ifdef PROG_HAS_ONSET
125 #endif /* PROG_HAS_ONSET */
126 #ifdef PROG_HAS_PITCH
128 #endif /* PROG_HAS_PITCH */
132 struct option long_options[] = {
133 {"help", 0, NULL, 'h'},
134 {"verbose", 0, NULL, 'v'},
135 {"input", 1, NULL, 'i'},
136 {"samplerate", 1, NULL, 'r'},
137 {"bufsize", 1, NULL, 'B'},
138 {"hopsize", 1, NULL, 'H'},
140 {"jack", 0, NULL, 'j'},
141 #endif /* PROG_HAS_JACK */
142 #ifdef PROG_HAS_OUTPUT
143 {"output", 1, NULL, 'o'},
144 #endif /* PROG_HAS_OUTPUT */
145 #ifdef PROG_HAS_ONSET
146 {"onset", 1, NULL, 'O'},
147 {"onset-threshold", 1, NULL, 't'},
148 #endif /* PROG_HAS_ONSET */
149 #ifdef PROG_HAS_PITCH
150 {"pitch", 1, NULL, 'p'},
151 {"pitch-unit", 1, NULL, 'u'},
152 {"pitch-tolerance", 1, NULL, 'l'},
153 #endif /* PROG_HAS_PITCH */
154 {"silence", 1, NULL, 's'},
155 {"time-format", 1, NULL, 'T'},
156 {"mix-input", 0, NULL, 'm'},
157 {"force-overwrite", 0, NULL, 'f'},
166 next_option = getopt_long (argc, argv, options, long_options, NULL);
167 switch (next_option) {
171 case 'v': /* verbose */
183 case 'f': /* force_overwrite flag */
187 samplerate = atoi (optarg);
190 buffer_size = atoi (optarg);
193 hop_size = atoi (optarg);
195 case 'O': /*onset method */
196 onset_method = optarg;
198 case 't': /* threshold value for onset */
199 onset_threshold = (smpl_t) atof (optarg);
202 pitch_method = optarg;
208 pitch_tolerance = (smpl_t) atof (optarg);
211 time_format = optarg;
213 case 's': /* silence threshold */
214 silence_threshold = (smpl_t) atof (optarg);
216 case 'm': /* mix_input flag */
219 case '?': /* unknown options */
222 case -1: /* done with options */
224 default: /*something else unexpected */
225 fprintf (stderr, "Error parsing option '%c'\n", next_option);
229 while (next_option != -1);
231 // if unique, use the non option argument as the source
232 if ( source_uri == NULL ) {
233 if (argc - optind == 1) {
234 source_uri = argv[optind];
235 } else if ( argc - optind > 1 ) {
236 errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]);
239 } else if ( argc - optind > 0 ) {
240 errmsg ("Error: extra non-option argument %s\n", argv[optind]);
244 // if no source, show a message
245 if (source_uri == NULL) {
248 verbmsg("No input source given, using jack\n");
251 errmsg("Error: no arguments given (and no available audio input)\n");
253 #endif /* HAVE_JACK */
255 errmsg("Error: no arguments given\n");
257 #endif /* PROG_HAS_JACK */
260 if ((sint_t)hop_size < 1) {
261 errmsg("Error: got hop_size %d, but can not be < 1\n", hop_size);
263 } else if ((sint_t)buffer_size < 2) {
264 errmsg("Error: got buffer_size %d, but can not be < 2\n", buffer_size);
266 } else if ((sint_t)buffer_size < (sint_t)hop_size) {
267 errmsg("Error: hop size (%d) is larger than win size (%d)\n",
268 hop_size, buffer_size);
272 if ((sint_t)samplerate < 0) {
273 errmsg("Error: got samplerate %d, but can not be < 0\n", samplerate);