[96fb8ad] | 1 | /* |
---|
[466dff3] | 2 | Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org> |
---|
[96fb8ad] | 3 | |
---|
[6a2478c] | 4 | This file is part of aubio. |
---|
[96fb8ad] | 5 | |
---|
[6a2478c] | 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/>. |
---|
[96fb8ad] | 18 | |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #include "utils.h" |
---|
[1b25a70] | 22 | #define PROG_HAS_PITCH 1 |
---|
| 23 | #define PROG_HAS_ONSET 1 |
---|
[82ae9d7] | 24 | #define PROG_HAS_SILENCE 1 |
---|
[3da8187] | 25 | #define PROG_HAS_JACK 1 |
---|
| 26 | // TODO add PROG_HAS_OUTPUT |
---|
[1b25a70] | 27 | #include "parse_args.h" |
---|
[96fb8ad] | 28 | |
---|
[ba303e8] | 29 | aubio_notes_t *notes; |
---|
[9562f08] | 30 | smpl_t lastmidi = 0.; |
---|
[d4c5de7] | 31 | |
---|
[d389e23] | 32 | void process_block (fvec_t *ibuf, fvec_t *obuf) |
---|
| 33 | { |
---|
[ba303e8] | 34 | aubio_notes_do (notes, ibuf, obuf); |
---|
| 35 | // did we get a note off? |
---|
| 36 | if (obuf->data[2] != 0) { |
---|
[9562f08] | 37 | lastmidi = aubio_freqtomidi (obuf->data[2]) + .5; |
---|
| 38 | send_noteon(lastmidi, 0); |
---|
[466dff3] | 39 | } |
---|
[ba303e8] | 40 | // did we get a note on? |
---|
| 41 | if (obuf->data[0] != 0) { |
---|
[9562f08] | 42 | lastmidi = aubio_freqtomidi (obuf->data[0]) + .5; |
---|
| 43 | send_noteon(lastmidi, obuf->data[1]); |
---|
[96fb8ad] | 44 | } |
---|
| 45 | } |
---|
| 46 | |
---|
[d389e23] | 47 | void process_print (void) |
---|
| 48 | { |
---|
[466dff3] | 49 | //if (verbose) outmsg("%f\n",pitch_obuf->data[0]); |
---|
[a0fd4e4] | 50 | } |
---|
[96fb8ad] | 51 | |
---|
[bd2f2ab] | 52 | int main(int argc, char **argv) { |
---|
[61a1e5d] | 53 | int ret = 0; |
---|
| 54 | |
---|
[bd2f2ab] | 55 | examples_common_init(argc,argv); |
---|
[d4c5de7] | 56 | |
---|
[466dff3] | 57 | verbmsg ("using source: %s at %dHz\n", source_uri, samplerate); |
---|
| 58 | |
---|
| 59 | verbmsg ("onset method: %s, ", onset_method); |
---|
| 60 | verbmsg ("buffer_size: %d, ", buffer_size); |
---|
| 61 | verbmsg ("hop_size: %d, ", hop_size); |
---|
| 62 | verbmsg ("threshold: %f\n", onset_threshold); |
---|
| 63 | |
---|
| 64 | verbmsg ("pitch method: %s, ", pitch_method); |
---|
| 65 | verbmsg ("buffer_size: %d, ", buffer_size * 4); |
---|
| 66 | verbmsg ("hop_size: %d, ", hop_size); |
---|
| 67 | verbmsg ("tolerance: %f\n", pitch_tolerance); |
---|
| 68 | |
---|
[ba303e8] | 69 | notes = new_aubio_notes ("default", buffer_size, hop_size, samplerate); |
---|
[61a1e5d] | 70 | if (notes == NULL) { ret = 1; goto beach; } |
---|
[d4c5de7] | 71 | |
---|
[ec45138] | 72 | if (onset_minioi != 0.) { |
---|
| 73 | errmsg ("warning: onset minioio not supported yet\n"); |
---|
| 74 | //aubio_onset_set_minioi_ms(aubio_notes_get_aubio_onset(o), onset_minioi); |
---|
| 75 | } |
---|
| 76 | if (onset_threshold != 0.) { |
---|
| 77 | errmsg ("warning: onset threshold not supported yet\n"); |
---|
| 78 | //aubio_onset_set_threshold(aubio_notes_get_aubio_onset(o), onset_threshold); |
---|
| 79 | } |
---|
| 80 | if (silence_threshold != -90.) { |
---|
| 81 | if (aubio_notes_set_silence (notes, silence_threshold) != 0) { |
---|
| 82 | errmsg ("failed setting notes silence threshold to %.2f\n", |
---|
| 83 | silence_threshold); |
---|
| 84 | } |
---|
| 85 | } |
---|
[ab7212f] | 86 | |
---|
[466dff3] | 87 | examples_common_process((aubio_process_func_t)process_block, process_print); |
---|
[d4c5de7] | 88 | |
---|
[466dff3] | 89 | // send a last note off |
---|
[1186c98] | 90 | if (usejack) { |
---|
| 91 | send_noteon (lastmidi, 0); |
---|
| 92 | } |
---|
[466dff3] | 93 | |
---|
[ba303e8] | 94 | del_aubio_notes (notes); |
---|
[d4c5de7] | 95 | |
---|
[61a1e5d] | 96 | beach: |
---|
[bd2f2ab] | 97 | examples_common_del(); |
---|
[61a1e5d] | 98 | return ret; |
---|
[96fb8ad] | 99 | } |
---|