Changeset bd2f2ab for examples/utils.c
- Timestamp:
- Apr 11, 2005, 6:37:51 PM (19 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:
- dc27a81
- Parents:
- 84941cb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/utils.c
r84941cb rbd2f2ab 18 18 cca_client_t * aubio_cca_client; 19 19 #endif /* LADCCA_SUPPORT */ 20 21 /* settings */ 22 const char * output_filename = NULL; 23 const char * input_filename = NULL; 24 const char * onset_filename = "/usr/share/sounds/aubio/woodblock.aiff"; 25 int frames = 0; 26 int verbose = 0; 27 int usejack = 0; 28 int usedoubled = 1; 29 30 31 /* energy,specdiff,hfc,complexdomain,phase */ 32 aubio_onsetdetection_type type_onset = hfc; 33 aubio_onsetdetection_type type_onset2 = complexdomain; 34 smpl_t threshold = 0.3; 35 smpl_t threshold2 = -90.; 36 uint_t buffer_size = 1024; 37 uint_t overlap_size = 512; 38 uint_t channels = 1; 39 uint_t samplerate = 44100; 40 41 42 aubio_file_t * file = NULL; 43 aubio_file_t * fileout = NULL; 44 45 aubio_pvoc_t * pv; 46 fvec_t * ibuf; 47 fvec_t * obuf; 48 cvec_t * fftgrain; 49 fvec_t * woodblock; 50 aubio_onsetdetection_t *o; 51 aubio_onsetdetection_t *o2; 52 fvec_t *onset; 53 fvec_t *onset2; 54 int isonset = 0; 55 aubio_pickpeak_t * parms; 56 57 58 /* pitch objects */ 59 smpl_t pitch = 0.; 60 aubio_pitchdetection_t * pitchdet; 61 aubio_pitchdetection_type mode = yin; // mcomb 62 uint_t median = 6; 63 64 fvec_t * note_buffer = NULL; 65 fvec_t * note_buffer2 = NULL; 66 smpl_t curlevel = 0.; 67 smpl_t maxonset = 0.; 68 69 /* midi objects */ 70 aubio_midi_player_t * mplay; 71 aubio_midi_driver_t * mdriver; 72 aubio_midi_event_t * event; 73 74 smpl_t curnote = 0.; 75 smpl_t newnote = 0.; 76 uint_t isready = 0; 77 20 78 21 79 … … 136 194 } 137 195 196 void examples_common_init(int argc,char ** argv) { 197 198 199 aubio_file_t * onsetfile = new_file_ro(onset_filename); 200 /* parse command line arguments */ 201 parse_args(argc, argv); 202 203 if(!usejack) 204 { 205 debug("Opening files ...\n"); 206 file = new_file_ro (input_filename); 207 if (verbose) file_info(file); 208 channels = aubio_file_channels(file); 209 samplerate = aubio_file_samplerate(file); 210 if (output_filename != NULL) 211 fileout = new_file_wo(file, output_filename); 212 } 213 214 ibuf = new_fvec(overlap_size, channels); 215 obuf = new_fvec(overlap_size, channels); 216 woodblock = new_fvec(buffer_size,1); 217 fftgrain = new_cvec(buffer_size, channels); 218 219 if (usepitch) { 220 pitchdet = new_aubio_pitchdetection(buffer_size*4, overlap_size, channels, samplerate, mode, freq); 221 222 if (median) { 223 note_buffer = new_fvec(median, 1); 224 note_buffer2= new_fvec(median, 1); 225 } 226 } 227 /* read the output sound once */ 228 file_read(onsetfile, overlap_size, woodblock); 229 /* phase vocoder */ 230 pv = new_aubio_pvoc(buffer_size, overlap_size, channels); 231 /* onsets */ 232 parms = new_aubio_peakpicker(threshold); 233 o = new_aubio_onsetdetection(type_onset,buffer_size,channels); 234 onset = new_fvec(1, channels); 235 if (usedoubled) { 236 o2 = new_aubio_onsetdetection(type_onset2,buffer_size,channels); 237 onset2 = new_fvec(1 , channels); 238 } 239 240 } 241 242 243 void examples_common_del(void){ 244 if (usepitch) { 245 send_noteon(curnote,0); 246 del_aubio_pitchdetection(pitchdet); 247 if (median) { 248 del_fvec(note_buffer); 249 del_fvec(note_buffer2); 250 } 251 } 252 del_aubio_pvoc(pv); 253 del_fvec(obuf); 254 del_fvec(ibuf); 255 del_cvec(fftgrain); 256 del_fvec(onset); 257 } 258 259 void examples_common_process(aubio_process_func_t process_func, aubio_print_func_t print ){ 260 if(usejack) { 261 #ifdef JACK_SUPPORT 262 aubio_jack_t * jack_setup; 263 debug("Jack init ...\n"); 264 jack_setup = new_aubio_jack(channels, channels, 265 (aubio_process_func_t)process_func); 266 if (usepitch) { 267 debug("Midi init ...\n"); 268 mplay = new_aubio_midi_player(); 269 mdriver = new_aubio_midi_driver("alsa_seq", 270 (handle_midi_event_func_t)aubio_midi_send_event, mplay); 271 event = new_aubio_midi_event(); 272 } 273 debug("Jack activation ...\n"); 274 aubio_jack_activate(jack_setup); 275 debug("Processing (Ctrl+C to quit) ...\n"); 276 pause(); 277 aubio_jack_close(jack_setup); 278 if (usepitch) { 279 send_noteon(curnote,0); 280 del_aubio_midi_driver(mdriver); 281 } 282 #else 283 usage(stderr, 1); 284 outmsg("Compiled without jack output, exiting.\n"); 285 #endif 286 287 } else { 288 /* phasevoc */ 289 debug("Processing ...\n"); 290 291 frames = 0; 292 293 while (overlap_size == file_read(file, overlap_size, ibuf)) 294 { 295 isonset=0; 296 process_func(ibuf->data, obuf->data, overlap_size); 297 print(); 298 if (output_filename != NULL) { 299 file_write(fileout,overlap_size,obuf); 300 } 301 frames++; 302 } 303 304 debug("Processed %d frames of %d samples.\n", frames, buffer_size); 305 del_file(file); 306 307 if (output_filename != NULL) 308 del_file(fileout); 309 310 } 311 } 312 313 314 315 void send_noteon(int pitch, int velo) 316 { 317 smpl_t mpitch = (FLOOR)(freqtomidi(pitch)+.5); 318 /* we should check if we use midi here, not jack */ 319 #if ALSA_SUPPORT 320 if (usejack) { 321 if (velo==0) { 322 aubio_midi_event_set_type(event,NOTE_OFF); 323 } else { 324 aubio_midi_event_set_type(event,NOTE_ON); 325 } 326 aubio_midi_event_set_channel(event,0); 327 aubio_midi_event_set_pitch(event,mpitch); 328 aubio_midi_event_set_velocity(event,velo); 329 aubio_midi_direct_output(mdriver,event); 330 } else 331 #endif 332 if (!verbose) 333 { 334 if (velo==0) { 335 outmsg("%f\n",frames*overlap_size/(float)samplerate); 336 } else { 337 outmsg("%f\t%f\t", mpitch, 338 frames*overlap_size/(float)samplerate); 339 } 340 } 341 } 342 343 344 void note_append(fvec_t * note_buffer, smpl_t curnote) { 345 uint_t i = 0; 346 for (i = 0; i < note_buffer->length - 1; i++) { 347 note_buffer->data[0][i] = note_buffer->data[0][i+1]; 348 } 349 note_buffer->data[0][note_buffer->length - 1] = curnote; 350 return; 351 } 352 353 uint_t get_note(fvec_t *note_buffer, fvec_t *note_buffer2){ 354 uint_t i = 0; 355 for (i = 0; i < note_buffer->length; i++) { 356 note_buffer2->data[0][i] = note_buffer->data[0][i]; 357 } 358 return vec_median(note_buffer2); 359 } 360
Note: See TracChangeset
for help on using the changeset viewer.