1 | /* |
---|
2 | Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> |
---|
3 | |
---|
4 | This file is part of aubio. |
---|
5 | |
---|
6 | aubio is free software: you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation, either version 3 of the License, or |
---|
9 | (at your option) any later version. |
---|
10 | |
---|
11 | aubio is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with aubio. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | |
---|
19 | */ |
---|
20 | |
---|
21 | #include "utils.h" |
---|
22 | #define PROG_HAS_PITCH 1 |
---|
23 | #define PROG_HAS_ONSET 1 |
---|
24 | #define PROG_HAS_JACK 1 |
---|
25 | // TODO add PROG_HAS_OUTPUT |
---|
26 | #include "parse_args.h" |
---|
27 | |
---|
28 | aubio_notes_t *notes; |
---|
29 | smpl_t lastmidi = 0.; |
---|
30 | |
---|
31 | void process_block (fvec_t *ibuf, fvec_t *obuf) |
---|
32 | { |
---|
33 | aubio_notes_do (notes, ibuf, obuf); |
---|
34 | // did we get a note off? |
---|
35 | if (obuf->data[2] != 0) { |
---|
36 | lastmidi = aubio_freqtomidi (obuf->data[2]) + .5; |
---|
37 | send_noteon(lastmidi, 0); |
---|
38 | } |
---|
39 | // did we get a note on? |
---|
40 | if (obuf->data[0] != 0) { |
---|
41 | lastmidi = aubio_freqtomidi (obuf->data[0]) + .5; |
---|
42 | send_noteon(lastmidi, obuf->data[1]); |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | void process_print (void) |
---|
47 | { |
---|
48 | //if (verbose) outmsg("%f\n",pitch_obuf->data[0]); |
---|
49 | } |
---|
50 | |
---|
51 | int main(int argc, char **argv) { |
---|
52 | examples_common_init(argc,argv); |
---|
53 | |
---|
54 | verbmsg ("using source: %s at %dHz\n", source_uri, samplerate); |
---|
55 | |
---|
56 | verbmsg ("onset method: %s, ", onset_method); |
---|
57 | verbmsg ("buffer_size: %d, ", buffer_size); |
---|
58 | verbmsg ("hop_size: %d, ", hop_size); |
---|
59 | verbmsg ("threshold: %f\n", onset_threshold); |
---|
60 | |
---|
61 | verbmsg ("pitch method: %s, ", pitch_method); |
---|
62 | verbmsg ("buffer_size: %d, ", buffer_size * 4); |
---|
63 | verbmsg ("hop_size: %d, ", hop_size); |
---|
64 | verbmsg ("tolerance: %f\n", pitch_tolerance); |
---|
65 | |
---|
66 | notes = new_aubio_notes ("default", buffer_size, hop_size, samplerate); |
---|
67 | |
---|
68 | examples_common_process((aubio_process_func_t)process_block, process_print); |
---|
69 | |
---|
70 | // send a last note off |
---|
71 | send_noteon (lastmidi, 0); |
---|
72 | |
---|
73 | del_aubio_notes (notes); |
---|
74 | |
---|
75 | examples_common_del(); |
---|
76 | return 0; |
---|
77 | } |
---|
78 | |
---|