diff options
Diffstat (limited to 'examples/aubionotes.c')
-rw-r--r-- | examples/aubionotes.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/examples/aubionotes.c b/examples/aubionotes.c new file mode 100644 index 0000000..7541098 --- /dev/null +++ b/examples/aubionotes.c @@ -0,0 +1,78 @@ +/* + Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> + + This file is part of aubio. + + aubio is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + aubio is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with aubio. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "utils.h" +#define PROG_HAS_PITCH 1 +#define PROG_HAS_ONSET 1 +#define PROG_HAS_JACK 1 +// TODO add PROG_HAS_OUTPUT +#include "parse_args.h" + +aubio_notes_t *notes; +smpl_t lastmidi = 0.; + +void process_block (fvec_t *ibuf, fvec_t *obuf) +{ + aubio_notes_do (notes, ibuf, obuf); + // did we get a note off? + if (obuf->data[2] != 0) { + lastmidi = aubio_freqtomidi (obuf->data[2]) + .5; + send_noteon(lastmidi, 0); + } + // did we get a note on? + if (obuf->data[0] != 0) { + lastmidi = aubio_freqtomidi (obuf->data[0]) + .5; + send_noteon(lastmidi, obuf->data[1]); + } +} + +void process_print (void) +{ + //if (verbose) outmsg("%f\n",pitch_obuf->data[0]); +} + +int main(int argc, char **argv) { + examples_common_init(argc,argv); + + verbmsg ("using source: %s at %dHz\n", source_uri, samplerate); + + verbmsg ("onset method: %s, ", onset_method); + verbmsg ("buffer_size: %d, ", buffer_size); + verbmsg ("hop_size: %d, ", hop_size); + verbmsg ("threshold: %f\n", onset_threshold); + + verbmsg ("pitch method: %s, ", pitch_method); + verbmsg ("buffer_size: %d, ", buffer_size * 4); + verbmsg ("hop_size: %d, ", hop_size); + verbmsg ("tolerance: %f\n", pitch_tolerance); + + notes = new_aubio_notes ("default", buffer_size, hop_size, samplerate); + + examples_common_process((aubio_process_func_t)process_block, process_print); + + // send a last note off + send_noteon (lastmidi, 0); + + del_aubio_notes (notes); + + examples_common_del(); + return 0; +} + |