[1b25a70] | 1 | /* |
---|
[466dff3] | 2 | Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> |
---|
[1b25a70] | 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; |
---|
[466dff3] | 29 | extern uint_t hop_size; |
---|
[1b25a70] | 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 |
---|
[ce6186a] | 40 | extern smpl_t silence_threshold; |
---|
[1b25a70] | 41 | extern uint_t mix_input; |
---|
| 42 | |
---|
[0a509c6] | 43 | extern uint_t force_overwrite; |
---|
| 44 | |
---|
[1b25a70] | 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); |
---|
[d389e23] | 50 | int parse_args (int argc, char **argv); |
---|
[1b25a70] | 51 | |
---|
| 52 | // internal stuff |
---|
[466dff3] | 53 | extern int blocks; |
---|
[1b25a70] | 54 | |
---|
| 55 | extern fvec_t *ibuf; |
---|
| 56 | extern fvec_t *obuf; |
---|
| 57 | |
---|
| 58 | const char *prog_name; |
---|
| 59 | |
---|
[d389e23] | 60 | void usage (FILE * stream, int exit_code); |
---|
| 61 | |
---|
| 62 | void usage (FILE * stream, int exit_code) |
---|
[1b25a70] | 63 | { |
---|
| 64 | fprintf (stream, "usage: %s [ options ] \n", prog_name); |
---|
| 65 | fprintf (stream, |
---|
[c7ec2c6] | 66 | " -i --input input file\n" |
---|
[3da8187] | 67 | #ifdef PROG_HAS_OUTPUT |
---|
[c7ec2c6] | 68 | " -o --output output file\n" |
---|
[3da8187] | 69 | #endif |
---|
[1b25a70] | 70 | " -r --samplerate select samplerate\n" |
---|
[d28a26a] | 71 | " use 0 to use input source samplerate, or 32000 to force 32kHz\n" |
---|
[1b25a70] | 72 | " -B --bufsize set buffer size\n" |
---|
[d28a26a] | 73 | " number of frames to run the analysis on\n" |
---|
[1b25a70] | 74 | " -H --hopsize set hopsize\n" |
---|
[d28a26a] | 75 | " number of frames to read from source before each analysis\n" |
---|
[1b25a70] | 76 | #ifdef PROG_HAS_ONSET |
---|
| 77 | " -O --onset select onset detection algorithm\n" |
---|
[d28a26a] | 78 | " <default|energy|hfc|complex|phase|specdiff|kl|mkl|specflux>;\n" |
---|
| 79 | " default=hfc\n" |
---|
[1b25a70] | 80 | " -t --onset-threshold set onset detection threshold\n" |
---|
[d28a26a] | 81 | " a value between 0.1 (more detections) and 1 (less); default=0.3\n" |
---|
[1b25a70] | 82 | #endif /* PROG_HAS_ONSET */ |
---|
| 83 | #ifdef PROG_HAS_PITCH |
---|
| 84 | " -p --pitch select pitch detection algorithm\n" |
---|
[d28a26a] | 85 | " <default|yinfft|yin|mcomb|fcomb|schmitt>; default=yinfft\n" |
---|
[1b25a70] | 86 | " -u --pitch-unit select pitch output unit\n" |
---|
[d28a26a] | 87 | " <default|freq|hertz|Hz|midi|cent|bin>; default=freq\n" |
---|
[1b25a70] | 88 | " -l --pitch-tolerance select pitch tolerance\n" |
---|
[d28a26a] | 89 | " (yin, yinfft only) a value between 0.1 and 0.7; default=0.3\n" |
---|
[1b25a70] | 90 | #endif /* PROG_HAS_PITCH */ |
---|
| 91 | " -s --silence select silence threshold\n" |
---|
[d28a26a] | 92 | " a value in dB, for instance -70, or -100; default=-90\n" |
---|
[3da8187] | 93 | #ifdef PROG_HAS_OUTPUT |
---|
[1b25a70] | 94 | " -m --mix-input mix input signal with output signal\n" |
---|
[d28a26a] | 95 | " input signal will be added to output synthesis\n" |
---|
[0a7f424] | 96 | " -f --force-overwrite overwrite output file if needed\n" |
---|
[d28a26a] | 97 | " do not fail if output file already exists\n" |
---|
[3da8187] | 98 | #endif |
---|
[3826e0b] | 99 | #ifdef PROG_HAS_JACK |
---|
| 100 | " -j --jack use Jack\n" |
---|
| 101 | #endif |
---|
| 102 | " -v --verbose be verbose\n" |
---|
| 103 | " -h --help display this message\n" |
---|
[1b25a70] | 104 | ); |
---|
| 105 | exit (exit_code); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | int |
---|
| 109 | parse_args (int argc, char **argv) |
---|
| 110 | { |
---|
| 111 | const char *options = "hv" |
---|
[3da8187] | 112 | "i:r:B:H:" |
---|
| 113 | #ifdef PROG_HAS_JACK |
---|
[1b25a70] | 114 | "j" |
---|
[3da8187] | 115 | #endif /* PROG_HAS_JACK */ |
---|
| 116 | #ifdef PROG_HAS_OUTPUT |
---|
| 117 | "o:" |
---|
| 118 | #endif /* PROG_HAS_OUTPUT */ |
---|
[1b25a70] | 119 | #ifdef PROG_HAS_ONSET |
---|
| 120 | "O:t:" |
---|
| 121 | #endif /* PROG_HAS_ONSET */ |
---|
| 122 | #ifdef PROG_HAS_PITCH |
---|
| 123 | "p:u:l:" |
---|
| 124 | #endif /* PROG_HAS_PITCH */ |
---|
[0a509c6] | 125 | "s:mf"; |
---|
[1b25a70] | 126 | int next_option; |
---|
| 127 | struct option long_options[] = { |
---|
| 128 | {"help", 0, NULL, 'h'}, |
---|
| 129 | {"verbose", 0, NULL, 'v'}, |
---|
| 130 | {"input", 1, NULL, 'i'}, |
---|
| 131 | {"samplerate", 1, NULL, 'r'}, |
---|
| 132 | {"bufsize", 1, NULL, 'B'}, |
---|
| 133 | {"hopsize", 1, NULL, 'H'}, |
---|
[3da8187] | 134 | #ifdef PROG_HAS_JACK |
---|
| 135 | {"jack", 0, NULL, 'j'}, |
---|
| 136 | #endif /* PROG_HAS_JACK */ |
---|
| 137 | #ifdef PROG_HAS_OUTPUT |
---|
| 138 | {"output", 1, NULL, 'o'}, |
---|
| 139 | #endif /* PROG_HAS_OUTPUT */ |
---|
[1b25a70] | 140 | #ifdef PROG_HAS_ONSET |
---|
| 141 | {"onset", 1, NULL, 'O'}, |
---|
| 142 | {"onset-threshold", 1, NULL, 't'}, |
---|
| 143 | #endif /* PROG_HAS_ONSET */ |
---|
| 144 | #ifdef PROG_HAS_PITCH |
---|
| 145 | {"pitch", 1, NULL, 'p'}, |
---|
| 146 | {"pitch-unit", 1, NULL, 'u'}, |
---|
| 147 | {"pitch-tolerance", 1, NULL, 'l'}, |
---|
| 148 | #endif /* PROG_HAS_PITCH */ |
---|
| 149 | {"silence", 1, NULL, 's'}, |
---|
| 150 | {"mix-input", 0, NULL, 'm'}, |
---|
[0a509c6] | 151 | {"force-overwrite", 0, NULL, 'f'}, |
---|
[1b25a70] | 152 | {NULL, 0, NULL, 0} |
---|
| 153 | }; |
---|
| 154 | prog_name = argv[0]; |
---|
| 155 | if (argc < 1) { |
---|
| 156 | usage (stderr, 1); |
---|
| 157 | return -1; |
---|
| 158 | } |
---|
| 159 | do { |
---|
| 160 | next_option = getopt_long (argc, argv, options, long_options, NULL); |
---|
| 161 | switch (next_option) { |
---|
| 162 | case 'h': /* help */ |
---|
| 163 | usage (stdout, 0); |
---|
| 164 | return -1; |
---|
| 165 | case 'v': /* verbose */ |
---|
| 166 | verbose = 1; |
---|
| 167 | break; |
---|
| 168 | case 'j': |
---|
| 169 | usejack = 1; |
---|
| 170 | break; |
---|
| 171 | case 'i': |
---|
| 172 | source_uri = optarg; |
---|
| 173 | break; |
---|
| 174 | case 'o': |
---|
| 175 | sink_uri = optarg; |
---|
| 176 | break; |
---|
[0a509c6] | 177 | case 'f': /* force_overwrite flag */ |
---|
| 178 | force_overwrite = 1; |
---|
| 179 | break; |
---|
[1b25a70] | 180 | case 'r': |
---|
| 181 | samplerate = atoi (optarg); |
---|
| 182 | break; |
---|
| 183 | case 'B': |
---|
| 184 | buffer_size = atoi (optarg); |
---|
| 185 | break; |
---|
| 186 | case 'H': |
---|
[466dff3] | 187 | hop_size = atoi (optarg); |
---|
[1b25a70] | 188 | break; |
---|
[c7ec2c6] | 189 | case 'O': /*onset method */ |
---|
[1b25a70] | 190 | onset_method = optarg; |
---|
| 191 | break; |
---|
| 192 | case 't': /* threshold value for onset */ |
---|
| 193 | onset_threshold = (smpl_t) atof (optarg); |
---|
| 194 | break; |
---|
| 195 | case 'p': |
---|
| 196 | pitch_method = optarg; |
---|
| 197 | break; |
---|
| 198 | case 'u': |
---|
| 199 | pitch_unit = optarg; |
---|
| 200 | break; |
---|
| 201 | case 'l': |
---|
| 202 | pitch_tolerance = (smpl_t) atof (optarg); |
---|
| 203 | break; |
---|
| 204 | case 's': /* silence threshold */ |
---|
[ce6186a] | 205 | silence_threshold = (smpl_t) atof (optarg); |
---|
[1b25a70] | 206 | break; |
---|
| 207 | case 'm': /* mix_input flag */ |
---|
| 208 | mix_input = 1; |
---|
| 209 | break; |
---|
| 210 | case '?': /* unknown options */ |
---|
| 211 | usage (stderr, 1); |
---|
| 212 | break; |
---|
| 213 | case -1: /* done with options */ |
---|
| 214 | break; |
---|
| 215 | default: /*something else unexpected */ |
---|
| 216 | fprintf (stderr, "Error parsing option '%c'\n", next_option); |
---|
| 217 | abort (); |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | while (next_option != -1); |
---|
| 221 | |
---|
[3da8187] | 222 | // if unique, use the non option argument as the source |
---|
[1b25a70] | 223 | if ( source_uri == NULL ) { |
---|
| 224 | if (argc - optind == 1) { |
---|
| 225 | source_uri = argv[optind]; |
---|
| 226 | } else if ( argc - optind > 1 ) { |
---|
| 227 | errmsg ("Error: too many non-option arguments `%s'\n", argv[argc - 1]); |
---|
| 228 | usage ( stderr, 1 ); |
---|
| 229 | } |
---|
| 230 | } else if ( argc - optind > 0 ) { |
---|
| 231 | errmsg ("Error: extra non-option argument %s\n", argv[optind]); |
---|
| 232 | usage ( stderr, 1 ); |
---|
| 233 | } |
---|
| 234 | |
---|
[3da8187] | 235 | // if no source, show a message |
---|
| 236 | if (source_uri == NULL) { |
---|
[8a22fc4] | 237 | #ifdef PROG_HAS_JACK |
---|
[1b25a70] | 238 | #if HAVE_JACK |
---|
[3da8187] | 239 | verbmsg("No input source given, using jack\n"); |
---|
[1b25a70] | 240 | usejack = 1; |
---|
| 241 | #else |
---|
| 242 | errmsg("Error: no arguments given (and no available audio input)\n"); |
---|
| 243 | usage ( stderr, 1 ); |
---|
[8a22fc4] | 244 | #endif /* HAVE_JACK */ |
---|
| 245 | #else |
---|
| 246 | errmsg("Error: no arguments given\n"); |
---|
| 247 | usage ( stderr, 1 ); |
---|
| 248 | #endif /* PROG_HAS_JACK */ |
---|
[1b25a70] | 249 | } |
---|
| 250 | |
---|
[0a7f424] | 251 | if ((sint_t)hop_size < 1) { |
---|
[0428150] | 252 | errmsg("Error: got hop_size %d, but can not be < 1\n", hop_size); |
---|
| 253 | usage ( stderr, 1 ); |
---|
[0a7f424] | 254 | } else if ((sint_t)buffer_size < 2) { |
---|
[0428150] | 255 | errmsg("Error: got buffer_size %d, but can not be < 2\n", buffer_size); |
---|
| 256 | usage ( stderr, 1 ); |
---|
[bafa767] | 257 | } else if ((sint_t)buffer_size < (sint_t)hop_size) { |
---|
| 258 | errmsg("Error: hop size (%d) is larger than win size (%d)\n", |
---|
[0a7f424] | 259 | hop_size, buffer_size); |
---|
| 260 | usage ( stderr, 1 ); |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | if ((sint_t)samplerate < 0) { |
---|
| 264 | errmsg("Error: got samplerate %d, but can not be < 0\n", samplerate); |
---|
[0428150] | 265 | usage ( stderr, 1 ); |
---|
| 266 | } |
---|
| 267 | |
---|
[1b25a70] | 268 | return 0; |
---|
| 269 | } |
---|