2 Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
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.
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.
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/>.
21 #define AUBIO_UNSTABLE 1 // for fvec_median
23 #define PROG_HAS_PITCH 1
24 #define PROG_HAS_ONSET 1
25 #define PROG_HAS_JACK 1
26 // TODO add PROG_HAS_OUTPUT
27 #include "parse_args.h"
43 /** append new note candidate to the note_buffer and return filtered value. we
44 * need to copy the input array as fvec_median destroy its input data.*/
45 void note_append (fvec_t * note_buffer, smpl_t curnote);
46 uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2);
48 void process_block (fvec_t *ibuf, fvec_t *obuf)
50 smpl_t new_pitch, curlevel;
52 aubio_onset_do(o, ibuf, onset);
54 aubio_pitch_do (pitch, ibuf, pitch_obuf);
55 new_pitch = fvec_get_sample(pitch_obuf, 0);
57 note_append(note_buffer, new_pitch);
60 /* curlevel is negatif or 1 if silence */
61 curlevel = aubio_level_detection(ibuf, silence_threshold);
62 if (fvec_get_sample(onset, 0)) {
63 /* test for silence */
65 if (median) isready = 0;
67 send_noteon(curnote,0);
73 send_noteon(curnote,0);
74 /* get and send new one */
75 send_noteon(new_pitch,127+(int)floor(curlevel));
83 if (isready == median)
86 send_noteon(curnote,0);
87 newnote = get_note(note_buffer, note_buffer2);
89 /* get and send new one */
91 send_noteon(curnote,127+(int)floor(curlevel));
98 void process_print (void)
100 //if (verbose) outmsg("%f\n",pitch_obuf->data[0]);
104 note_append (fvec_t * note_buffer, smpl_t curnote)
107 for (i = 0; i < note_buffer->length - 1; i++) {
108 note_buffer->data[i] = note_buffer->data[i + 1];
110 note_buffer->data[note_buffer->length - 1] = curnote;
115 get_note (fvec_t * note_buffer, fvec_t * note_buffer2)
118 for (i = 0; i < note_buffer->length; i++) {
119 note_buffer2->data[i] = note_buffer->data[i];
121 return fvec_median (note_buffer2);
124 int main(int argc, char **argv) {
125 examples_common_init(argc,argv);
127 verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
129 verbmsg ("onset method: %s, ", onset_method);
130 verbmsg ("buffer_size: %d, ", buffer_size);
131 verbmsg ("hop_size: %d, ", hop_size);
132 verbmsg ("threshold: %f\n", onset_threshold);
134 verbmsg ("pitch method: %s, ", pitch_method);
135 verbmsg ("buffer_size: %d, ", buffer_size * 4);
136 verbmsg ("hop_size: %d, ", hop_size);
137 verbmsg ("tolerance: %f\n", pitch_tolerance);
139 o = new_aubio_onset (onset_method, buffer_size, hop_size, samplerate);
140 if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold);
141 onset = new_fvec (1);
143 pitch = new_aubio_pitch (pitch_method, buffer_size * 4, hop_size, samplerate);
144 if (pitch_tolerance != 0.) aubio_pitch_set_tolerance (pitch, pitch_tolerance);
145 pitch_obuf = new_fvec (1);
148 note_buffer = new_fvec (median);
149 note_buffer2 = new_fvec (median);
152 examples_common_process((aubio_process_func_t)process_block, process_print);
154 // send a last note off
155 send_noteon (curnote, 0);
157 del_aubio_pitch (pitch);
159 del_fvec (note_buffer);
160 del_fvec (note_buffer2);
162 del_fvec (pitch_obuf);
164 examples_common_del();