1 | /* |
---|
2 | Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> |
---|
3 | |
---|
4 | This file is part of aubio. |
---|
5 | |
---|
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. |
---|
10 | |
---|
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. |
---|
15 | |
---|
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/>. |
---|
18 | |
---|
19 | */ |
---|
20 | |
---|
21 | extern int verbose; |
---|
22 | // input / output |
---|
23 | extern int usejack; |
---|
24 | extern char_t *source_uri; |
---|
25 | extern char_t *sink_uri; |
---|
26 | // general stuff |
---|
27 | extern uint_t samplerate; |
---|
28 | extern uint_t buffer_size; |
---|
29 | extern uint_t hop_size; |
---|
30 | // onset stuff |
---|
31 | extern char_t * onset_method; |
---|
32 | extern smpl_t onset_threshold; |
---|
33 | // pitch stuff |
---|
34 | extern char_t * pitch_method; |
---|
35 | extern char_t * pitch_unit; |
---|
36 | extern smpl_t pitch_tolerance; |
---|
37 | // tempo stuff |
---|
38 | extern char_t * tempo_method; |
---|
39 | // more general stuff |
---|
40 | extern smpl_t silence; |
---|
41 | extern uint_t mix_input; |
---|
42 | |
---|
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); |
---|
48 | |
---|
49 | // internal stuff |
---|
50 | extern int blocks; |
---|
51 | |
---|
52 | extern fvec_t *ibuf; |
---|
53 | extern fvec_t *obuf; |
---|
54 | |
---|
55 | |
---|
56 | const char *prog_name; |
---|
57 | |
---|
58 | void |
---|
59 | usage (FILE * stream, int exit_code) |
---|
60 | { |
---|
61 | fprintf (stream, "usage: %s [ options ] \n", prog_name); |
---|
62 | fprintf (stream, |
---|
63 | " -h --help display this message\n" |
---|
64 | " -v --verbose be verbose\n" |
---|
65 | #ifdef PROG_HAS_JACK |
---|
66 | " -j --jack use Jack\n" |
---|
67 | #endif |
---|
68 | " -i --input input type\n" |
---|
69 | #ifdef PROG_HAS_OUTPUT |
---|
70 | " -o --output output type\n" |
---|
71 | #endif |
---|
72 | " -r --samplerate select samplerate\n" |
---|
73 | " -B --bufsize set buffer size\n" |
---|
74 | " -H --hopsize set hopsize\n" |
---|
75 | #ifdef PROG_HAS_ONSET |
---|
76 | " -O --onset select onset detection algorithm\n" |
---|
77 | " -t --onset-threshold set onset detection threshold\n" |
---|
78 | #endif /* PROG_HAS_ONSET */ |
---|
79 | #ifdef PROG_HAS_PITCH |
---|
80 | " -p --pitch select pitch detection algorithm\n" |
---|
81 | " -u --pitch-unit select pitch output unit\n" |
---|
82 | " -l --pitch-tolerance select pitch tolerance\n" |
---|
83 | #endif /* PROG_HAS_PITCH */ |
---|
84 | " -s --silence select silence threshold\n" |
---|
85 | #ifdef PROG_HAS_OUTPUT |
---|
86 | " -m --mix-input mix input signal with output signal\n" |
---|
87 | #endif |
---|
88 | ); |
---|
89 | exit (exit_code); |
---|
90 | } |
---|
91 | |
---|
92 | int |
---|
93 | parse_args (int argc, char **argv) |
---|
94 | { |
---|
95 | const char *options = "hv" |
---|
96 | "i:r:B:H:" |
---|
97 | #ifdef PROG_HAS_JACK |
---|
98 | "j" |
---|
99 | #endif /* PROG_HAS_JACK */ |
---|
100 | #ifdef PROG_HAS_OUTPUT |
---|
101 | "o:" |
---|
102 | #endif /* PROG_HAS_OUTPUT */ |
---|
103 | #ifdef PROG_HAS_ONSET |
---|
104 | "O:t:" |
---|
105 | #endif /* PROG_HAS_ONSET */ |
---|
106 | #ifdef PROG_HAS_PITCH |
---|
107 | "p:u:l:" |
---|
108 | #endif /* PROG_HAS_PITCH */ |
---|
109 | "s:m"; |
---|
110 | int next_option; |
---|
111 | struct option long_options[] = { |
---|
112 | {"help", 0, NULL, 'h'}, |
---|
113 | {"verbose", 0, NULL, 'v'}, |
---|
114 | {"input", 1, NULL, 'i'}, |
---|
115 | {"samplerate", 1, NULL, 'r'}, |
---|
116 | {"bufsize", 1, NULL, 'B'}, |
---|
117 | {"hopsize", 1, NULL, 'H'}, |
---|
118 | #ifdef PROG_HAS_JACK |
---|
119 | {"jack", 0, NULL, 'j'}, |
---|
120 | #endif /* PROG_HAS_JACK */ |
---|
121 | #ifdef PROG_HAS_OUTPUT |
---|
122 | {"output", 1, NULL, 'o'}, |
---|
123 | #endif /* PROG_HAS_OUTPUT */ |
---|
124 | #ifdef PROG_HAS_ONSET |
---|
125 | {"onset", 1, NULL, 'O'}, |
---|
126 | {"onset-threshold", 1, NULL, 't'}, |
---|
127 | #endif /* PROG_HAS_ONSET */ |
---|
128 | #ifdef PROG_HAS_PITCH |
---|
129 | {"pitch", 1, NULL, 'p'}, |
---|
130 | {"pitch-unit", 1, NULL, 'u'}, |
---|
131 | {"pitch-tolerance", 1, NULL, 'l'}, |
---|
132 | #endif /* PROG_HAS_PITCH */ |
---|
133 | {"silence", 1, NULL, 's'}, |
---|
134 | {"mix-input", 0, NULL, 'm'}, |
---|
135 | {NULL, 0, NULL, 0} |
---|
136 | }; |
---|
137 | prog_name = argv[0]; |
---|
138 | if (argc < 1) { |
---|
139 | usage (stderr, 1); |
---|
140 | return -1; |
---|
141 | } |
---|
142 | do { |
---|
143 | next_option = getopt_long (argc, argv, options, long_options, NULL); |
---|
144 | switch (next_option) { |
---|
145 | case 'h': /* help */ |
---|
146 | usage (stdout, 0); |
---|
147 | return -1; |
---|
148 | case 'v': /* verbose */ |
---|
149 | verbose = 1; |
---|
150 | break; |
---|
151 | case 'j': |
---|
152 | usejack = 1; |
---|
153 | break; |
---|
154 | case 'i': |
---|
155 | source_uri = optarg; |
---|
156 | break; |
---|
157 | case 'o': |
---|
158 | sink_uri = optarg; |
---|
159 | break; |
---|
160 | case 'r': |
---|
161 | samplerate = atoi (optarg); |
---|
162 | break; |
---|
163 | case 'B': |
---|
164 | buffer_size = atoi (optarg); |
---|
165 | break; |
---|
166 | case 'H': |
---|
167 | hop_size = atoi (optarg); |
---|
168 | break; |
---|
169 | case 'O': /*onset type */ |
---|
170 | onset_method = optarg; |
---|
171 | break; |
---|
172 | case 't': /* threshold value for onset */ |
---|
173 | onset_threshold = (smpl_t) atof (optarg); |
---|
174 | break; |
---|
175 | case 'p': |
---|
176 | pitch_method = optarg; |
---|
177 | break; |
---|
178 | case 'u': |
---|
179 | pitch_unit = optarg; |
---|
180 | break; |
---|
181 | case 'l': |
---|
182 | pitch_tolerance = (smpl_t) atof (optarg); |
---|
183 | break; |
---|
184 | case 's': /* silence threshold */ |
---|
185 | silence = (smpl_t) atof (optarg); |
---|
186 | break; |
---|
187 | case 'm': /* mix_input flag */ |
---|
188 | mix_input = 1; |
---|
189 | break; |
---|
190 | case '?': /* unknown options */ |
---|
191 | usage (stderr, 1); |
---|
192 | break; |
---|
193 | case -1: /* done with options */ |
---|
194 | break; |
---|
195 | default: /*something else unexpected */ |
---|
196 | fprintf (stderr, "Error parsing option '%c'\n", next_option); |
---|
197 | abort (); |
---|
198 | } |
---|
199 | } |
---|
200 | while (next_option != -1); |
---|
201 | |
---|
202 | // if unique, use the non option argument as the source |
---|
203 | if ( source_uri == NULL ) { |
---|
204 | if (argc - optind == 1) { |
---|
205 | source_uri = argv[optind]; |
---|
206 | } else if ( argc - optind > 1 ) { |
---|
207 | errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]); |
---|
208 | usage ( stderr, 1 ); |
---|
209 | } |
---|
210 | } else if ( argc - optind > 0 ) { |
---|
211 | errmsg ("Error: extra non-option argument %s\n", argv[optind]); |
---|
212 | usage ( stderr, 1 ); |
---|
213 | } |
---|
214 | |
---|
215 | // if no source, show a message |
---|
216 | if (source_uri == NULL) { |
---|
217 | #if HAVE_JACK |
---|
218 | verbmsg("No input source given, using jack\n"); |
---|
219 | usejack = 1; |
---|
220 | #else |
---|
221 | errmsg("Error: no arguments given (and no available audio input)\n"); |
---|
222 | usage ( stderr, 1 ); |
---|
223 | #endif |
---|
224 | } |
---|
225 | |
---|
226 | return 0; |
---|
227 | } |
---|