static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { unsigned int i; /*channels*/ unsigned int j; /*frames*/ for (j=0;j<(unsigned)nframes;j++) { if(usejack) { /* write input to datanew */ fvec_write_sample(ibuf, input[0][j], pos); /* put synthnew in output */ output[0][j] = fvec_read_sample(obuf, pos); } /*time for fft*/ if (pos == overlap_size-1) { /* block loop */ aubio_onset_do (o, ibuf, onset); if ( fvec_read_sample(onset, 0) ) { fvec_copy (woodblock, obuf); } else { fvec_zeros (obuf); } /* end of block loop */ pos = -1; /* so it will be zero next j loop */ } pos++; } return 1; }
int main (int argc, char **argv) { uint_t err = 0; if (argc < 2) { err = 2; PRINT_ERR("not enough arguments\n"); PRINT_MSG("read a wave file as a mono vector\n"); PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]); return err; } uint_t samplerate = 0; uint_t win_s = 1024; // window size uint_t hop_size = win_s / 4; uint_t n_frames = 0, read = 0; if ( argc == 3 ) samplerate = atoi(argv[2]); if ( argc == 4 ) hop_size = atoi(argv[3]); char_t *source_path = argv[1]; aubio_source_t * source = new_aubio_source(source_path, samplerate, hop_size); if (!source) { err = 1; goto beach; } if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source); // create some vectors fvec_t * in = new_fvec (hop_size); // input audio buffer fvec_t * out = new_fvec (2); // output position // create onset object aubio_onset_t * o = new_aubio_onset("default", win_s, hop_size, samplerate); do { // put some fresh data in input vector aubio_source_do(source, in, &read); // execute onset aubio_onset_do(o,in,out); // do something with the onsets if (out->data[0] != 0) { PRINT_MSG("onset at %.3fms, %.3fs, frame %d\n", aubio_onset_get_last_ms(o), aubio_onset_get_last_s(o), aubio_onset_get_last(o)); } n_frames += read; } while ( read == hop_size ); PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n", n_frames * 1. / samplerate, n_frames, samplerate, n_frames / hop_size, source_path); // clean up memory del_aubio_onset(o); del_fvec(in); del_fvec(out); beach: aubio_cleanup(); return err; }
void aubio_notes_do (aubio_notes_t *o, const fvec_t * input, fvec_t * notes) { smpl_t new_pitch, curlevel; fvec_zeros(notes); aubio_onset_do(o->onset, input, o->onset_output); aubio_pitch_do (o->pitch, input, o->pitch_output); new_pitch = o->pitch_output->data[0]; if(o->median){ note_append(o->note_buffer, new_pitch); } /* curlevel is negatif or 1 if silence */ curlevel = aubio_level_detection(input, o->silence_threshold); if (o->onset_output->data[0] != 0) { /* test for silence */ if (curlevel == 1.) { if (o->median) o->isready = 0; /* send note off */ //send_noteon(o->curnote,0); //notes->data[0] = o->curnote; //notes->data[1] = 0.; notes->data[2] = o->curnote; } else { if (o->median) { o->isready = 1; } else { /* kill old note */ //send_noteon(o->curnote,0, o->samplerate); notes->data[2] = o->curnote; /* get and send new one */ //send_noteon(new_pitch,127+(int)floor(curlevel), o->samplerate); notes->data[0] = new_pitch; notes->data[1] = 127 + (int)floor(curlevel); o->curnote = new_pitch; } } } else { if (o->median) { if (o->isready > 0) o->isready++; if (o->isready == o->median) { /* kill old note */ //send_noteon(curnote,0); notes->data[2] = o->curnote; o->newnote = aubio_notes_get_latest_note(o); o->curnote = o->newnote; /* get and send new one */ if (o->curnote>45){ //send_noteon(curnote,127+(int)floor(curlevel)); notes->data[0] = o->curnote; notes->data[1] = 127 + (int) floor(curlevel); } } } // if median } }
void Note2midi::process_block (){ smpl_t new_pitch, curlevel; // fvec_zeros(obuf); aubio_onset_do(o, ibuf, onset); aubio_pitch_do (pitch, ibuf, pitch_obuf); new_pitch = fvec_get_sample(pitch_obuf, 0); if(median){ note_append(note_buffer, new_pitch); } /* curlevel is negatif or 1 if silence */ curlevel = aubio_level_detection(ibuf, *_silence_threshold); if (fvec_get_sample(onset, 0)) { /* test for silence */ if (curlevel == 1.) { if (median) isready = 0; /* send note off */ send_noteon(curnote, 0); } else { if (median) { isready = 1; } else { /* kill old note */ send_noteon(curnote, 0); /* get and send new one */ send_noteon(new_pitch, 127+(int)floor(curlevel)); curnote = new_pitch; } } } else { if (median) { if (isready > 0) isready++; if (isready == median){ /* kill old note */ send_noteon(curnote, 0); newnote = get_note(note_buffer, note_buffer2); curnote = newnote; /* get and send new one */ if (curnote>45){ send_noteon(curnote, 127+(int)floor(curlevel)); } } } // if median } // lv2_atom_sequence_append_event(this->out, out_capacity, ¬e.event); }
int main(){ /* allocate some memory */ uint_t win_s = 1024; /* window size */ fvec_t * in = new_fvec (win_s/4); /* input buffer */ fvec_t * out = new_fvec (2); /* input buffer */ aubio_onset_t * onset = new_aubio_onset("complex", win_s, win_s/4, 44100.); uint_t i = 0; while (i < 10) { aubio_onset_do (onset,in,out); i++; }; del_aubio_onset(onset); del_fvec(in); del_fvec(out); aubio_cleanup(); return 0; }
//Creates a list of times which the aubio onset detector thinks are note onset times for the audio Denemo->si->recording //Result is placed in Denemo->si->note_onsets void generate_note_onsets (void) { DenemoRecording *audio = Denemo.project->movement->recording; gint channels = audio->channels; smpl_t threshold = 0.3; smpl_t silence = -90.; uint_t buffer_size = 1024; uint_t overlap_size = 512; uint_t samplerate = 44100; aubio_onset_t *o = new_aubio_onset("default", buffer_size, overlap_size, samplerate); fvec_t *ibuf = new_fvec (overlap_size); fvec_t *onset = new_fvec (2); unsigned int pos = 0; /*frames%dspblocksize */ unsigned int i; /*channels */ unsigned int j; /*frames */ busy_cursor (Denemo.notebook); gtk_window_set_modal (progressbar (_("Analysing Audio"), NULL), TRUE); rewind_audio (); if (audio->notes) { g_list_free_full (audio->notes, g_free); audio->notes = NULL; } for (j = 0; j < (unsigned) audio->nframes; j++) { sf_read_float (audio->sndfile, ibuf->data + pos, 2); //g_debug("\t%f", ibuf->data[0][pos]); if (pos == overlap_size - 1) { /* block loop */ gtk_main_iteration_do (FALSE); aubio_onset_do (o, ibuf, onset); while (gtk_events_pending ()) gtk_main_iteration (); if(onset->data[0] != 0) { DenemoRecordedNote *note = g_malloc0(sizeof(DenemoRecordedNote)); note->timing = aubio_onset_get_last(o);/* aubio_onset_get_delay_s(o) for seconds */ audio->notes = g_list_append (audio->notes, note); } pos = -1; /* so it will be zero next j loop */ } /* end of if pos==overlap_size-1 */ pos++; } del_aubio_onset (o); del_fvec (ibuf); del_fvec (onset); aubio_cleanup (); progressbar_stop (); normal_cursor (Denemo.notebook); }