/* function Py_source_do */ static PyObject * Py_source_do(Py_source * self, PyObject * args) { /* output vectors prototypes */ fvec_t* read_to; uint_t read; /* creating output read_to as a new_fvec of length self->hop_size */ read_to = new_fvec (self->hop_size); read = 0; /* compute _do function */ aubio_source_do (self->o, read_to, &read); PyObject *outputs = PyList_New(0); PyList_Append( outputs, (PyObject *)PyAubio_CFvecToArray (read_to)); //del_fvec (read_to); PyList_Append( outputs, (PyObject *)PyLong_FromLong (read)); return outputs; }
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; }
void examples_common_process (aubio_process_func_t process_func, aubio_print_func_t print) { uint_t read = 0; if (usejack) { #ifdef HAVE_JACK ev.size = 3; ev.buffer = malloc (3 * sizeof (jack_midi_data_t)); ev.time = 0; // send it now debug ("Jack activation ...\n"); aubio_jack_activate (jack_setup, process_func); debug ("Processing (Ctrl+C to quit) ...\n"); pause (); aubio_jack_close (jack_setup); #else /* HAVE_JACK */ usage (stderr, 1); outmsg ("Compiled without jack output, exiting.\n"); #endif /* HAVE_JACK */ } else { uint_t total_read = 0; blocks = 0; do { aubio_source_do (this_source, ibuf, &read); process_func (ibuf, obuf); // print to console if verbose or no output given if (verbose || sink_uri == NULL) { print(); } if (this_sink) { aubio_sink_do (this_sink, obuf, hop_size); } blocks++; total_read += read; } while (read == hop_size); verbmsg ("read %.2fs (%d samples in %d blocks of %d) from %s at %dHz\n", total_read * 1. / samplerate, total_read, blocks, hop_size, source_uri, samplerate); del_aubio_source (this_source); del_aubio_sink (this_sink); } }
void aubio_sampler_do ( aubio_sampler_t * o, fvec_t * input, fvec_t * output) { uint_t read = 0, i; if (o->playing) { aubio_source_do (o->source, o->source_output, &read); for (i = 0; i < output->length; i++) { output->data[i] += o->source_output->data[i]; } if (read < o->blocksize) o->playing = 0; } if (input && input != output) { for (i = 0; i < output->length; i++) { output->data[i] += input->data[i]; } } }
/* function Py_source_do */ static PyObject * Py_source_do(Py_source * self, PyObject * args) { PyObject *outputs; uint_t read; read = 0; Py_INCREF(self->read_to); if (!PyAubio_ArrayToCFvec(self->read_to, &(self->c_read_to))) { return NULL; } /* compute _do function */ aubio_source_do (self->o, &(self->c_read_to), &read); if (PyErr_Occurred() != NULL) { return NULL; } outputs = PyTuple_New(2); PyTuple_SetItem( outputs, 0, self->read_to ); PyTuple_SetItem( outputs, 1, (PyObject *)PyLong_FromLong(read)); return outputs; }
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; }
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; }