Changeset fc117d0 for examples/utils.c
- Timestamp:
- Feb 11, 2013, 11:06:28 AM (11 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 050a8f3
- Parents:
- 5314432 (diff), 88fc249 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/utils.c
r5314432 rfc117d0 42 42 43 43 /* settings */ 44 const char *output_filename = NULL; 45 const char *input_filename = NULL; 46 const char *onset_filename = 47 AUBIO_PREFIX "/share/sounds/" PACKAGE "/woodblock.aiff"; 44 const char *sink_uri = NULL; 45 const char *source_uri = NULL; 48 46 int frames = 0; 49 47 int verbose = 0; … … 63 61 uint_t samplerate = 44100; 64 62 65 66 #ifdef HAVE_SNDFILE 67 aubio_sndfile_t *file = NULL; 68 aubio_sndfile_t *fileout = NULL; 69 #else 70 void *file = NULL; 71 void *fileout = NULL; 72 #endif 63 aubio_source_t *this_source = NULL; 64 aubio_sink_t *this_sink = NULL; 73 65 74 66 fvec_t *ibuf; … … 136 128 switch (next_option) { 137 129 case 'o': 138 output_filename= optarg;130 sink_uri = optarg; 139 131 break; 140 132 case 'i': 141 input_filename= optarg;133 source_uri = optarg; 142 134 break; 143 135 case 'h': /* help */ … … 183 175 while (next_option != -1); 184 176 185 if ( input_filename!= NULL) {186 debug ("Input file : %s\n", input_filename);187 } else if ( input_filename != NULL && output_filename!= NULL) {188 debug ("Input file : %s\n", input_filename);189 debug ("Output file : %s\n", output_filename);177 if (source_uri != NULL) { 178 debug ("Input file : %s\n", source_uri); 179 } else if (source_uri != NULL && sink_uri != NULL) { 180 debug ("Input file : %s\n", source_uri); 181 debug ("Output file : %s\n", sink_uri); 190 182 } else { 191 183 #if HAVE_JACK … … 193 185 usejack = 1; 194 186 #else 195 debug 196 ("Error: Could not switch to jack mode\n aubio was compiled without jack support\n"); 197 exit (1); 187 errmsg("Error: no arguments given (and no available audio input)\n"); 188 usage ( stderr, 1 ); 198 189 #endif 199 190 } … … 202 193 } 203 194 204 #ifdef HAVE_SNDFILE205 206 195 void 207 196 examples_common_init (int argc, char **argv) 208 197 { 209 198 210 uint_t found_wood = 0;211 212 aubio_sndfile_t *onsetfile = NULL;213 199 /* parse command line arguments */ 214 200 parse_args (argc, argv); … … 216 202 if (!usejack) { 217 203 debug ("Opening files ...\n"); 218 file = new_aubio_sndfile_ro (input_filename);219 if ( file == NULL) {220 outmsg ("Could not open input file %s.\n", input_filename);204 this_source = new_aubio_source ((char_t*)source_uri, 0, overlap_size); 205 if (this_source == NULL) { 206 outmsg ("Could not open input file %s.\n", source_uri); 221 207 exit (1); 222 208 } 223 if (verbose) 224 aubio_sndfile_info (file); 225 samplerate = aubio_sndfile_samplerate (file); 226 if (output_filename != NULL) 227 fileout = new_aubio_sndfile_wo (file, output_filename); 209 samplerate = aubio_source_get_samplerate(this_source); 210 if (sink_uri != NULL) { 211 this_sink = new_aubio_sink ((char_t*)sink_uri, samplerate); 212 if (this_sink == NULL) { 213 outmsg ("Could not open output file %s.\n", sink_uri); 214 exit (1); 215 } 216 } 228 217 } 229 218 #ifdef HAVE_LASH … … 246 235 247 236 woodblock = new_fvec (overlap_size); 248 if (output_filename || usejack) { 249 /* dummy assignement to keep egcs happy */ 250 found_wood = (onsetfile = new_aubio_sndfile_ro (onset_filename)) || 251 (onsetfile = new_aubio_sndfile_ro ("sounds/woodblock.aiff")) || 252 (onsetfile = new_aubio_sndfile_ro ("../sounds/woodblock.aiff")); 253 if (onsetfile == NULL) { 254 outmsg ("Could not find woodblock.aiff\n"); 255 exit (1); 256 } 257 } 258 if (onsetfile) { 259 /* read the output sound once */ 260 aubio_sndfile_read_mono (onsetfile, overlap_size, woodblock); 261 } 237 //TODO create woodblock sound 262 238 263 239 ibuf = new_fvec (overlap_size); … … 266 242 } 267 243 268 #else /* HAVE_SNDFILE */269 270 void271 examples_common_init (int argc, char **argv)272 {273 outmsg ("Error, compiled without sndfile, nothing to do for now!\n");274 }275 276 277 #endif /* HAVE_SNDFILE */278 279 280 244 void 281 245 examples_common_del (void) 282 246 { 283 #if HAVE_SNDFILE284 247 del_fvec (ibuf); 285 248 del_fvec (obuf); 286 249 del_fvec (woodblock); 287 #endif288 250 aubio_cleanup (); 289 251 } … … 293 255 #endif 294 256 295 #if HAVE_SNDFILE296 297 257 void 298 258 examples_common_process (aubio_process_func_t process_func, 299 259 aubio_print_func_t print) 300 260 { 261 262 uint_t read = 0; 301 263 if (usejack) { 302 264 … … 321 283 frames = 0; 322 284 323 while ((signed) overlap_size ==324 aubio_sndfile_read_mono (file, overlap_size, ibuf)) {285 do { 286 aubio_source_do (this_source, ibuf, &read); 325 287 process_func (&ibuf->data, &obuf->data, overlap_size); 326 288 print (); 327 if ( output_filename != NULL) {328 aubio_s ndfile_write (fileout, overlap_size, &obuf);289 if (this_sink) { 290 aubio_sink_do (this_sink, obuf, overlap_size); 329 291 } 330 292 frames++; 331 } 293 } while (read == overlap_size); 332 294 333 295 debug ("Processed %d frames of %d samples.\n", frames, buffer_size); 334 296 335 297 flush_process (process_func, print); 336 del_aubio_sndfile (file); 337 338 if (output_filename != NULL) 339 del_aubio_sndfile (fileout); 340 341 } 342 } 343 344 #else /* HAVE_SNDFILE */ 345 346 void 347 examples_common_process (aubio_process_func_t process_func, 348 aubio_print_func_t print) 349 { 350 } 351 352 #endif /* HAVE_SNDFILE */ 298 del_aubio_source (this_source); 299 del_aubio_sink (this_sink); 300 301 } 302 } 353 303 354 304 void
Note: See TracChangeset
for help on using the changeset viewer.