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) { sint_t err = 0; if (argc < 4) { err = 2; PRINT_ERR("not enough arguments\n"); PRINT_MSG("usage: %s <input_path> <output_path> <sample_path> [samplerate]\n", argv[0]); return err; } uint_t samplerate = 0; // default is the samplerate of input_path uint_t hop_size = 256; uint_t n_frames = 0, read = 0; char_t *source_path = argv[1]; char_t *sink_path = argv[2]; char_t *sample_path = argv[3]; if ( argc == 5 ) samplerate = atoi(argv[4]); fvec_t *vec = new_fvec(hop_size); aubio_source_t *source = new_aubio_source(source_path, samplerate, hop_size); if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source); aubio_sink_t *sink = new_aubio_sink(sink_path, samplerate); aubio_sampler_t * sampler = new_aubio_sampler (samplerate, hop_size); aubio_sampler_load (sampler, sample_path); do { aubio_source_do(source, vec, &read); if (n_frames / hop_size == 10) { aubio_sampler_play ( sampler ); } if (n_frames / hop_size == 40) { aubio_sampler_play ( sampler ); } if (n_frames / hop_size == 70) { aubio_sampler_play ( sampler ); } if (n_frames > 10.0 * samplerate) { aubio_sampler_stop ( sampler ); } aubio_sampler_do (sampler, vec, vec); aubio_sink_do(sink, vec, read); n_frames += read; } while ( read == hop_size ); del_aubio_sampler(sampler); del_aubio_source(source); del_aubio_sink(sink); del_fvec(vec); aubio_cleanup(); return 0; }
int main (int argc, char **argv) { sint_t err = 0; if (argc < 3) { err = 2; PRINT_ERR("not enough arguments\n"); PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]); return err; } char_t *source_path = argv[1]; char_t *sink_path = argv[2]; uint_t samplerate = 0; uint_t hop_size = 256; if ( argc >= 4 ) samplerate = atoi(argv[3]); if ( argc >= 5 ) hop_size = atoi(argv[4]); if ( argc >= 6 ) { err = 2; PRINT_ERR("too many arguments\n"); return err; } fvec_t *vec = new_fvec(hop_size); if (!vec) { err = 1; goto beach_fvec; } aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size); if (!i) { err = 1; goto beach_source; } if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i); aubio_sink_t *o = new_aubio_sink(sink_path, samplerate); if (!o) { err = 1; goto beach_sink; } uint_t n_frames = 0, read = 0; do { aubio_source_do(i, vec, &read); aubio_sink_do(o, vec, read); n_frames += read; } while ( read == hop_size ); PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n", n_frames, samplerate, n_frames / hop_size, source_path, sink_path); del_aubio_sink(o); beach_sink: del_aubio_source(i); beach_source: del_fvec(vec); beach_fvec: return err; }
static int Py_source_init (Py_source * self, PyObject * args, PyObject * kwds) { self->o = new_aubio_source ( self->uri, self->samplerate, self->hop_size ); if (self->o == NULL) { char_t errstr[30 + strlen(self->uri)]; sprintf(errstr, "error creating source with %s", self->uri); PyErr_SetString (PyExc_Exception, errstr); return -1; } self->samplerate = aubio_source_get_samplerate ( self->o ); if (self->channels == 0) { self->channels = aubio_source_get_channels ( self->o ); } return 0; }
static int Py_source_init (Py_source * self, PyObject * args, PyObject * kwds) { self->o = new_aubio_source ( self->uri, self->samplerate, self->hop_size ); if (self->o == NULL) { // PyErr_Format(PyExc_RuntimeError, ...) was set above by new_ which called // AUBIO_ERR when failing return -1; } self->samplerate = aubio_source_get_samplerate ( self->o ); if (self->channels == 0) { self->channels = aubio_source_get_channels ( self->o ); } self->duration = aubio_source_get_duration ( self->o ); self->read_to = new_py_fvec(self->hop_size); self->mread_to = new_py_fmat(self->channels, self->hop_size); return 0; }
void examples_common_init (int argc, char **argv) { /* parse command line arguments */ parse_args (argc, argv); if (!usejack) { debug ("Opening files ...\n"); this_source = new_aubio_source ((char_t*)source_uri, samplerate, hop_size); if (this_source == NULL) { errmsg ("Error: could not open input file %s\n", source_uri); exit (1); } if (samplerate == 0) { samplerate = aubio_source_get_samplerate(this_source); } if (sink_uri != NULL) { uint_t sink_exists = (access(sink_uri, F_OK) == 0 ); if (!force_overwrite && sink_exists) { errmsg ("Error: output file %s already exists, use -f to overwrite.\n", sink_uri); exit (1); } this_sink = new_aubio_sink ((char_t*)sink_uri, samplerate); if (this_sink == NULL) { errmsg ("Error: could not create output file %s\n", sink_uri); exit (1); } } #ifdef HAVE_JACK } else { debug ("Jack init ...\n"); jack_setup = new_aubio_jack (hop_size, 1, 1, 0, 1); samplerate = aubio_jack_get_samplerate (jack_setup); source_uri = "jack"; #endif /* HAVE_JACK */ } ibuf = new_fvec (hop_size); obuf = new_fvec (hop_size); }
int main (int argc, char** argv) { sint_t err = 0; if (argc < 2) { err = 2; PRINT_WRN("no arguments, running tests\n"); err = test_wrong_params(); PRINT_MSG("usage: %s <input_path> [samplerate] [hop_size]\n", argv[0]); return err; } uint_t win_s; // fft size uint_t hop_s = 256; // block size uint_t samplerate = 0; // samplerate uint_t n_filters = 40; // number of filters uint_t n_coeffs = 13; // number of coefficients uint_t read = 0; char_t *source_path = argv[1]; if ( argc >= 3 ) samplerate = atoi(argv[2]); if ( argc >= 4 ) hop_s = atoi(argv[3]); win_s = 2 * hop_s; aubio_source_t *source = 0; aubio_pvoc_t *pv = 0; aubio_mfcc_t *mfcc = 0; fvec_t *in = new_fvec (hop_s); // phase vocoder input cvec_t *fftgrain = new_cvec (win_s); // pvoc output / mfcc input fvec_t *out = new_fvec (n_coeffs); // mfcc output if (!in || !fftgrain || !out) { err = 1; goto failure; } // source source = new_aubio_source(source_path, samplerate, hop_s); if (!source) { err = 1; goto failure; } if (samplerate == 0) samplerate = aubio_source_get_samplerate(source); // phase vocoder pv = new_aubio_pvoc(win_s, hop_s); if (!pv) { err = 1; goto failure; } // mfcc object mfcc = new_aubio_mfcc (win_s, n_filters, n_coeffs, samplerate); if (!mfcc) { err = 1; goto failure; } // processing loop do { aubio_source_do(source, in, &read); aubio_pvoc_do(pv, in, fftgrain); aubio_mfcc_do(mfcc, fftgrain, out); fvec_print(out); } while (read == hop_s); failure: if (mfcc) del_aubio_mfcc(mfcc); if (pv) del_aubio_pvoc(pv); if (source) del_aubio_source(source); if (in) del_fvec(in); if (fftgrain) del_cvec(fftgrain); if (out) del_fvec(out); aubio_cleanup(); return err; }
static PyObject * Pyaubio_source_get_samplerate (Py_source *self, PyObject *unused) { uint_t tmp = aubio_source_get_samplerate (self->o); return (PyObject *)PyLong_FromLong (tmp); }
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]); PRINT_MSG("examples:\n"); PRINT_MSG(" - read file.wav at original samplerate\n"); PRINT_MSG(" %s file.wav\n", argv[0]); PRINT_MSG(" - read file.wav at 32000Hz\n"); PRINT_MSG(" %s file.aif 32000\n", argv[0]); PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n"); PRINT_MSG(" %s file.wav 0 4096 \n", argv[0]); return err; } uint_t samplerate = 0; uint_t hop_size = 256; uint_t n_frames = 0, read = 0; uint_t old_n_frames_1 = 0, old_n_frames_2 = 0, old_n_frames_3 = 0; if ( argc == 3 ) samplerate = atoi(argv[2]); if ( argc == 4 ) hop_size = atoi(argv[3]); char_t *source_path = argv[1]; fvec_t *vec = new_fvec(hop_size); aubio_source_t* s = new_aubio_source(source_path, samplerate, hop_size); if (!s) { err = 1; goto beach; } if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(s); do { aubio_source_do(s, vec, &read); //fvec_print (vec); 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); old_n_frames_1 = n_frames; aubio_source_seek (s, 0); n_frames = 0; do { aubio_source_do(s, vec, &read); //fvec_print (vec); 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); old_n_frames_2 = n_frames; aubio_source_seek (s, old_n_frames_1 / 2); n_frames = 0; do { aubio_source_do(s, vec, &read); //fvec_print (vec); 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); old_n_frames_3 = n_frames; del_aubio_source (s); beach: del_fvec (vec); // check that we got exactly the same number of frames assert ( old_n_frames_2 == old_n_frames_1 ); // check that we got about half the frames, with 3 decimals assert ( roundf(1.e3 * old_n_frames_1 / old_n_frames_3) / 1.e3 == 2.); return err; }