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_threshold;
41 extern uint_t mix_input;
43 extern uint_t force_overwrite;
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 " -i --input input file\n"
65 #ifdef PROG_HAS_OUTPUT
66 " -o --output output file\n"
68 " -r --samplerate select samplerate\n"
69 " -B --bufsize set buffer size\n"
70 " -H --hopsize set hopsize\n"
72 " -O --onset select onset detection algorithm\n"
73 " -t --onset-threshold set onset detection threshold\n"
74 #endif /* PROG_HAS_ONSET */
76 " -p --pitch select pitch detection algorithm\n"
77 " -u --pitch-unit select pitch output unit\n"
78 " -l --pitch-tolerance select pitch tolerance\n"
79 #endif /* PROG_HAS_PITCH */
80 " -s --silence select silence threshold\n"
81 #ifdef PROG_HAS_OUTPUT
82 " -m --mix-input mix input signal with output signal\n"
83 " -f --force-overwrite overwrite output file if needed\n"
86 " -j --jack use Jack\n"
88 " -v --verbose be verbose\n"
89 " -h --help display this message\n"
95 parse_args (int argc, char **argv)
97 const char *options = "hv"
101 #endif /* PROG_HAS_JACK */
102 #ifdef PROG_HAS_OUTPUT
104 #endif /* PROG_HAS_OUTPUT */
105 #ifdef PROG_HAS_ONSET
107 #endif /* PROG_HAS_ONSET */
108 #ifdef PROG_HAS_PITCH
110 #endif /* PROG_HAS_PITCH */
113 struct option long_options[] = {
114 {"help", 0, NULL, 'h'},
115 {"verbose", 0, NULL, 'v'},
116 {"input", 1, NULL, 'i'},
117 {"samplerate", 1, NULL, 'r'},
118 {"bufsize", 1, NULL, 'B'},
119 {"hopsize", 1, NULL, 'H'},
121 {"jack", 0, NULL, 'j'},
122 #endif /* PROG_HAS_JACK */
123 #ifdef PROG_HAS_OUTPUT
124 {"output", 1, NULL, 'o'},
125 #endif /* PROG_HAS_OUTPUT */
126 #ifdef PROG_HAS_ONSET
127 {"onset", 1, NULL, 'O'},
128 {"onset-threshold", 1, NULL, 't'},
129 #endif /* PROG_HAS_ONSET */
130 #ifdef PROG_HAS_PITCH
131 {"pitch", 1, NULL, 'p'},
132 {"pitch-unit", 1, NULL, 'u'},
133 {"pitch-tolerance", 1, NULL, 'l'},
134 #endif /* PROG_HAS_PITCH */
135 {"silence", 1, NULL, 's'},
136 {"mix-input", 0, NULL, 'm'},
137 {"force-overwrite", 0, NULL, 'f'},
146 next_option = getopt_long (argc, argv, options, long_options, NULL);
147 switch (next_option) {
151 case 'v': /* verbose */
163 case 'f': /* force_overwrite flag */
167 samplerate = atoi (optarg);
170 buffer_size = atoi (optarg);
173 hop_size = atoi (optarg);
175 case 'O': /*onset method */
176 onset_method = optarg;
178 case 't': /* threshold value for onset */
179 onset_threshold = (smpl_t) atof (optarg);
182 pitch_method = optarg;
188 pitch_tolerance = (smpl_t) atof (optarg);
190 case 's': /* silence threshold */
191 silence_threshold = (smpl_t) atof (optarg);
193 case 'm': /* mix_input flag */
196 case '?': /* unknown options */
199 case -1: /* done with options */
201 default: /*something else unexpected */
202 fprintf (stderr, "Error parsing option '%c'\n", next_option);
206 while (next_option != -1);
208 // if unique, use the non option argument as the source
209 if ( source_uri == NULL ) {
210 if (argc - optind == 1) {
211 source_uri = argv[optind];
212 } else if ( argc - optind > 1 ) {
213 errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]);
216 } else if ( argc - optind > 0 ) {
217 errmsg ("Error: extra non-option argument %s\n", argv[optind]);
221 // if no source, show a message
222 if (source_uri == NULL) {
225 verbmsg("No input source given, using jack\n");
228 errmsg("Error: no arguments given (and no available audio input)\n");
230 #endif /* HAVE_JACK */
232 errmsg("Error: no arguments given\n");
234 #endif /* PROG_HAS_JACK */
237 if ((sint_t)hop_size < 1) {
238 errmsg("Error: got hop_size %d, but can not be < 1\n", hop_size);
240 } else if ((sint_t)buffer_size < 2) {
241 errmsg("Error: got buffer_size %d, but can not be < 2\n", buffer_size);
243 } else if ((sint_t)buffer_size < (sint_t)hop_size + 1) {
244 errmsg("Error: hop size (%d) is larger than or equal to win size (%d)\n",
245 hop_size, buffer_size);
249 if ((sint_t)samplerate < 0) {
250 errmsg("Error: got samplerate %d, but can not be < 0\n", samplerate);