int main(){ /* allocate some memory */ uint_t win_s = 1024; /* window size */ fvec_t * in = new_fvec (win_s); /* input buffer */ fvec_t * out = new_fvec (2); /* input buffer */ aubio_tempo_t * o = new_aubio_tempo("complex", win_s, win_s/4, 44100.); uint_t i = 0; smpl_t curtempo, curtempoconf; while (i < 1000) { aubio_tempo_do(o,in,out); curtempo = aubio_tempo_get_bpm(o); if (curtempo != 0.) { fprintf(stdout,"%f\n",curtempo); return 1; } curtempoconf = aubio_tempo_get_confidence(o); if (curtempoconf != 0.) { fprintf(stdout,"%f\n",curtempo); return 1; } i++; }; del_aubio_tempo(o); del_fvec(in); del_fvec(out); aubio_cleanup(); return 0; }
void process_block(fvec_t * ibuf, fvec_t *obuf) { aubio_tempo_do (tempo, ibuf, tempo_out); is_beat = fvec_get_sample (tempo_out, 0); //smpl_t bpm = aubio_tempo_get_bpm(tempo); //uint_t last_beat = aubio_tempo_get_last(tempo); aubio_pitch_do (pitch, ibuf, pitch_out); smpl_t freq = fvec_get_sample(pitch_out, 0); if (silence_threshold != -90.) is_silence = aubio_silence_detection(ibuf, silence_threshold); fvec_zeros (obuf); if ( is_beat && !is_silence ) { samples_per_beat = total_frames - my_last_beat; my_last_beat = total_frames; aubio_wavetable_play ( wavetable ); } else { aubio_wavetable_stop ( wavetable ); } if (mix_input) aubio_wavetable_do (wavetable, ibuf, obuf); else aubio_wavetable_do (wavetable, obuf, obuf); rgb_music_iterate(my_last_beat, samples_per_beat, total_frames, freq); total_frames += hop_size; }
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] [win_size] [hop_size]\n", argv[0]); return err; } uint_t samplerate = 0; if ( argc >= 3 ) samplerate = atoi(argv[2]); uint_t win_size = 1024; // window size if ( argc >= 4 ) win_size = atoi(argv[3]); uint_t hop_size = win_size / 4; if ( argc >= 5 ) hop_size = atoi(argv[4]); uint_t n_frames = 0, read = 0; 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 (1); // output position // create tempo object aubio_tempo_t * o = new_aubio_tempo("default", win_size, hop_size, samplerate); do { // put some fresh data in input vector aubio_source_do(source, in, &read); // execute tempo aubio_tempo_do(o,in,out); // do something with the beats if (out->data[0] != 0) { PRINT_MSG("beat at %.3fms, %.3fs, frame %d, %.2fbpm with confidence %.2f\n", aubio_tempo_get_last_ms(o), aubio_tempo_get_last_s(o), aubio_tempo_get_last(o), aubio_tempo_get_bpm(o), aubio_tempo_get_confidence(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_tempo(o); del_fvec(in); del_fvec(out); del_aubio_source(source); beach: aubio_cleanup(); return err; }
static GstFlowReturn gst_aubio_tempo_transform_ip (GstBaseTransform * trans, GstBuffer * buf) { uint j; GstAubioTempo *filter = GST_AUBIOTEMPO(trans); GstAudioFilter *audiofilter = GST_AUDIO_FILTER(trans); gint nsamples = GST_BUFFER_SIZE (buf) / (4 * audiofilter->format.channels); /* block loop */ for (j = 0; j < nsamples; j++) { /* copy input to ibuf */ fvec_write_sample(filter->ibuf, ((smpl_t *) GST_BUFFER_DATA(buf))[j], filter->pos); if (filter->pos == filter->hop_size - 1) { aubio_tempo_do(filter->t, filter->ibuf, filter->out); if (filter->out->data[0]> 0.) { gdouble now = GST_BUFFER_OFFSET (buf); // correction of inside buffer time now += (smpl_t)(j - filter->hop_size + 1); // correction of float period now += (filter->out->data[0] - 1.)*(smpl_t)filter->hop_size; if (filter->last_beat != -1 && now > filter->last_beat) { filter->bpm = 60./(GST_FRAMES_TO_CLOCK_TIME(now - filter->last_beat, audiofilter->format.rate))*1.e+9; } else { filter->bpm = 0.; } if (filter->silent == FALSE) { g_print ("beat: %f ", GST_FRAMES_TO_CLOCK_TIME( now, audiofilter->format.rate)*1.e-9); g_print ("| bpm: %f\n", filter->bpm); } GST_LOG_OBJECT (filter, "beat %" GST_TIME_FORMAT ", bpm %3.2f", GST_TIME_ARGS(now), filter->bpm); if (filter->message) { GstMessage *m = gst_aubio_tempo_message_new (filter, now); gst_element_post_message (GST_ELEMENT (filter), m); } filter->last_beat = now; } filter->pos = -1; /* so it will be zero next j loop */ } filter->pos++; } return GST_FLOW_OK; }
void ofxAubioBeat::blockAudioIn() { aubio_tempo_do(tempo, aubio_input, aubio_output); if (aubio_output->data[0]) { //ofLogNotice() << "found beat: " << aubio_output->data[0]; bpm = aubio_tempo_get_bpm(tempo); float last_beat = aubio_tempo_get_last_s(tempo); ofNotifyEvent(gotBeat, last_beat, this); ofNotifyEvent(gotGlobalBeat, last_beat); } }
void process_block(fvec_t * ibuf, fvec_t *obuf) { aubio_tempo_do (tempo, ibuf, tempo_out); is_beat = fvec_get_sample (tempo_out, 0); if (silence_threshold != -90.) is_silence = aubio_silence_detection(ibuf, silence_threshold); fvec_zeros (obuf); if ( is_beat && !is_silence ) { aubio_wavetable_play ( wavetable ); } else { aubio_wavetable_stop ( wavetable ); } if (mix_input) aubio_wavetable_do (wavetable, ibuf, obuf); else aubio_wavetable_do (wavetable, obuf, obuf); }