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;
41 extern uint_t mix_input;
43 // functions defined in utils.c
44 extern void examples_common_init (int argc, char **argv);
45 extern void examples_common_del (void);
46 extern void examples_common_process (aubio_process_func_t process_func,
47 aubio_print_func_t print);
56 const char *prog_name;
59 usage (FILE * stream, int exit_code)
61 fprintf (stream, "usage: %s [ options ] \n", prog_name);
63 " -h --help display this message\n"
64 " -v --verbose be verbose\n"
66 " -j --jack use Jack\n"
68 " -i --input input type\n"
69 " -o --output output type\n"
70 " -r --samplerate select samplerate\n"
71 " -B --bufsize set buffer size\n"
72 " -H --hopsize set hopsize\n"
74 " -O --onset select onset detection algorithm\n"
75 " -t --onset-threshold set onset detection threshold\n"
76 #endif /* PROG_HAS_ONSET */
78 " -p --pitch select pitch detection algorithm\n"
79 " -u --pitch-unit select pitch output unit\n"
80 " -l --pitch-tolerance select pitch tolerance\n"
81 #endif /* PROG_HAS_PITCH */
82 " -s --silence select silence threshold\n"
83 " -m --mix-input mix input signal with output signal\n"
89 parse_args (int argc, char **argv)
91 const char *options = "hv"
98 #endif /* PROG_HAS_ONSET */
101 #endif /* PROG_HAS_PITCH */
104 struct option long_options[] = {
105 {"help", 0, NULL, 'h'},
106 {"verbose", 0, NULL, 'v'},
108 {"jack", 0, NULL, 'j'},
110 {"input", 1, NULL, 'i'},
111 {"output", 1, NULL, 'o'},
112 {"samplerate", 1, NULL, 'r'},
113 {"bufsize", 1, NULL, 'B'},
114 {"hopsize", 1, NULL, 'H'},
115 #ifdef PROG_HAS_ONSET
116 {"onset", 1, NULL, 'O'},
117 {"onset-threshold", 1, NULL, 't'},
118 #endif /* PROG_HAS_ONSET */
119 #ifdef PROG_HAS_PITCH
120 {"pitch", 1, NULL, 'p'},
121 {"pitch-unit", 1, NULL, 'u'},
122 {"pitch-tolerance", 1, NULL, 'l'},
123 #endif /* PROG_HAS_PITCH */
124 {"silence", 1, NULL, 's'},
125 {"mix-input", 0, NULL, 'm'},
134 next_option = getopt_long (argc, argv, options, long_options, NULL);
135 switch (next_option) {
139 case 'v': /* verbose */
152 samplerate = atoi (optarg);
155 buffer_size = atoi (optarg);
158 hop_size = atoi (optarg);
160 case 'O': /*onset type */
161 onset_method = optarg;
163 case 't': /* threshold value for onset */
164 onset_threshold = (smpl_t) atof (optarg);
167 pitch_method = optarg;
173 pitch_tolerance = (smpl_t) atof (optarg);
175 case 's': /* silence threshold */
176 silence = (smpl_t) atof (optarg);
178 case 'm': /* mix_input flag */
181 case '?': /* unknown options */
184 case -1: /* done with options */
186 default: /*something else unexpected */
187 fprintf (stderr, "Error parsing option '%c'\n", next_option);
191 while (next_option != -1);
193 if ( source_uri == NULL ) {
194 if (argc - optind == 1) {
195 source_uri = argv[optind];
196 } else if ( argc - optind > 1 ) {
197 errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]);
200 } else if ( argc - optind > 0 ) {
201 errmsg ("Error: extra non-option argument %s\n", argv[optind]);
205 if (source_uri != NULL) {
206 debug ("Input file : %s\n", source_uri);
207 } else if (source_uri != NULL && sink_uri != NULL) {
208 debug ("Input file : %s\n", source_uri);
209 debug ("Output file : %s\n", sink_uri);
212 debug ("Jack input output\n");
215 errmsg("Error: no arguments given (and no available audio input)\n");