int main(int argc, char **argv) { // override general settings from utils.c buffer_size = 1024; hop_size = 512; examples_common_init(argc,argv); verbmsg ("using source: %s at %dHz\n", source_uri, samplerate); verbmsg ("tempo method: %s, ", tempo_method); verbmsg ("buffer_size: %d, ", buffer_size); verbmsg ("hop_size: %d, ", hop_size); verbmsg ("threshold: %f\n", onset_threshold); tempo_out = new_fvec(2); tempo = new_aubio_tempo(tempo_method, buffer_size, hop_size, samplerate); // set silence threshold very low to output beats even during silence // aubio_tempo_set_silence(tempo, -1000.); if (onset_threshold != 0.) aubio_tempo_set_threshold (tempo, onset_threshold); wavetable = new_aubio_wavetable (samplerate, hop_size); aubio_wavetable_set_freq ( wavetable, 2450.); //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff"); examples_common_process((aubio_process_func_t)process_block,process_print); del_aubio_tempo(tempo); del_aubio_wavetable (wavetable); del_fvec(tempo_out); examples_common_del(); return 0; }
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; }
static void *aubiotempo_tilde_del(t_aubiotempo_tilde *x) { if(x->t) del_aubio_tempo(x->t); if(x->output) del_fvec(x->output); if(x->vec) del_fvec(x->vec); return 0; }
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; }
int main(int argc, char **argv) { // override general settings from utils.c buffer_size = 1024; hop_size = 512; rgb_music_init(); examples_common_init(argc,argv); verbmsg ("using source: %s at %dHz\n", source_uri, samplerate); verbmsg ("tempo method: %s, ", tempo_method); verbmsg ("buffer_size: %d, ", buffer_size); verbmsg ("hop_size: %d, ", hop_size); verbmsg ("threshold: %f\n", onset_threshold); tempo_out = new_fvec(2); tempo = new_aubio_tempo(tempo_method, buffer_size, hop_size, samplerate); if (onset_threshold != 0.) aubio_tempo_set_threshold (tempo, onset_threshold); pitch = new_aubio_pitch (pitch_method, buffer_size, hop_size, samplerate); if (pitch_tolerance != 0.) aubio_pitch_set_tolerance (pitch, pitch_tolerance); if (silence_threshold != -90.) aubio_pitch_set_silence (pitch, silence_threshold); if (pitch_unit != NULL) aubio_pitch_set_unit (pitch, pitch_unit); pitch_out = new_fvec (1); wavetable = new_aubio_wavetable (samplerate, hop_size); aubio_wavetable_set_freq ( wavetable, 2450.); //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff"); examples_common_process((aubio_process_func_t)process_block,process_print); del_aubio_tempo(tempo); del_aubio_wavetable (wavetable); del_fvec(tempo_out); del_aubio_pitch (pitch); del_fvec (pitch_out); examples_common_del(); return 0; }
static void gst_aubio_tempo_finalize (GObject * obj) { GstAubioTempo * aubio_tempo = GST_AUBIOTEMPO (obj); if (aubio_tempo->t) { del_aubio_tempo(aubio_tempo->t); } if (aubio_tempo->ibuf) { del_fvec(aubio_tempo->ibuf); } if (aubio_tempo->out) { del_fvec(aubio_tempo->out); } G_OBJECT_CLASS (parent_class)->finalize (obj); }
int main(int argc, char **argv) { buffer_size = 1024; overlap_size = 512; /* override default settings */ examples_common_init(argc,argv); out = new_fvec(2,channels); bt = new_aubio_tempo(type_onset,buffer_size,overlap_size,channels); examples_common_process(aubio_process,process_print); del_aubio_tempo(bt); del_fvec(out); examples_common_del(); debug("End of program.\n"); fflush(stderr); return 0; }
AubioBeatDetector::AubioBeatDetector(std::unique_ptr<NUClear::Environment> environment) : Reactor(std::move(environment)) { on<Trigger<messages::input::SoundChunkSettings>>([this](const messages::input::SoundChunkSettings& settings) { // Store the settings of the sound chunks m->sampleRate = settings.sampleRate; m->channels = settings.channels; m->chunkSize = settings.chunkSize; // Build our audio tempo tracker can set to (aubio_onset_kl or aubio_onset_complex onset tracking) m->tempoTracker = new_aubio_tempo(aubio_onset_kl, WINDOW_SIZE, HOP_SIZE, m->channels); m->outputData = new_fvec(HOP_SIZE, m->channels); m->inputData = new_fvec(HOP_SIZE, m->channels); }); on<Trigger<messages::input::SoundChunk>>([this](const messages::input::SoundChunk& chunk) { for (size_t i = 0; i < m->chunkSize; ++i) { // Write to our vector size_t index = (i + m->offset) % HOP_SIZE; fvec_write_sample(m->inputData, chunk.data[i * m->channels], 0, index); // If we are done filling this hop chunk if(index == HOP_SIZE - 1) { aubio_tempo(m->tempoTracker, m->inputData, m->outputData); for (int i = 1; i <= m->outputData->data[0][0]; ++i) { auto beatTime = std::make_unique<BeatTime>(); // Work out how many samples from the end we are in total const size_t position = ((i - HOP_SIZE) + (m->outputData->data[0][i])); // Start at our end time and go back beatTime->time = chunk.endTime - NUClear::clock::duration(int(NUClear::clock::period::den * (double(position) / m->sampleRate))); emit(std::move(beatTime)); } } } m->offset = (m->chunkSize + m->offset) % HOP_SIZE; }); on<Trigger<Last<2, BeatTime>>>([this](const std::vector<std::shared_ptr<const BeatTime>>& lastTwoBeats) { if(lastTwoBeats.size() == 2) { auto beat = std::make_unique<messages::audio::Beat>(); beat->time = lastTwoBeats[0]->time; //apparently the latest one is 0 beat->period = lastTwoBeats[0]->time - lastTwoBeats[1]->time; emit(std::move(beat)); } }); on<Trigger<Shutdown>>([this](const Shutdown&) { del_aubio_tempo(m->tempoTracker); del_fvec(m->inputData); del_fvec(m->outputData); }); }
ofxAubioBeat::~ofxAubioBeat() { if (tempo) del_aubio_tempo(tempo); cleanup(); ofLogNotice() << "deleted ofxAubioBeat"; }