2 Copyright (C) 2003 Paul Brossier
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 aubio_pitch_t *pitchdet;
29 fvec_t *note_buffer = NULL;
30 fvec_t *note_buffer2 = NULL;
35 unsigned int pos = 0; /*frames%dspblocksize*/
37 aubio_pitch_t *pitchdet;
42 /** append new note candidate to the note_buffer and return filtered value. we
43 * need to copy the input array as fvec_median destroy its input data.*/
44 void note_append (fvec_t * note_buffer, smpl_t curnote);
45 uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2);
47 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) {
48 unsigned int i; /*channels*/
49 unsigned int j; /*frames*/
50 for (j=0;j<(unsigned)nframes;j++) {
52 for (i=0;i<channels;i++) {
53 /* write input to datanew */
54 fvec_write_sample(ibuf, input[i][j], i, pos);
55 /* put synthnew in output */
56 output[i][j] = fvec_read_sample(obuf, i, pos);
60 if (pos == overlap_size-1) {
62 aubio_onset_do(o, ibuf, onset);
64 aubio_pitch_do (pitchdet, ibuf, pitch_obuf);
65 pitch = fvec_read_sample(pitch_obuf, 0, 0);
67 note_append(note_buffer, pitch);
70 /* curlevel is negatif or 1 if silence */
71 curlevel = aubio_level_detection(ibuf, silence);
72 if (fvec_read_sample(onset, 0, 0)) {
73 /* test for silence */
75 if (median) isready = 0;
77 send_noteon(curnote,0);
83 send_noteon(curnote,0);
84 /* get and send new one */
85 send_noteon(pitch,127+(int)floor(curlevel));
89 for (pos = 0; pos < overlap_size; pos++){
90 obuf->data[0][pos] = woodblock->data[0][pos];
97 if (isready == median)
100 send_noteon(curnote,0);
101 newnote = get_note(note_buffer, note_buffer2);
103 /* get and send new one */
105 send_noteon(curnote,127+(int)floor(curlevel));
109 for (pos = 0; pos < overlap_size; pos++)
110 obuf->data[0][pos] = 0.;
112 /* end of block loop */
113 pos = -1; /* so it will be zero next j loop */
120 static void process_print (void) {
121 if (verbose) outmsg("%f\n",pitch);
125 note_append (fvec_t * note_buffer, smpl_t curnote)
128 for (i = 0; i < note_buffer->length - 1; i++) {
129 note_buffer->data[0][i] = note_buffer->data[0][i + 1];
131 note_buffer->data[0][note_buffer->length - 1] = curnote;
136 get_note (fvec_t * note_buffer, fvec_t * note_buffer2)
139 for (i = 0; i < note_buffer->length; i++) {
140 note_buffer2->data[0][i] = note_buffer->data[0][i];
142 return fvec_median_channel (note_buffer2, 0);
145 int main(int argc, char **argv) {
146 examples_common_init(argc,argv);
148 o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels,
150 if (threshold != 0.) aubio_onset_set_threshold (o, threshold);
151 onset = new_fvec (1, channels);
153 pitchdet = new_aubio_pitch (pitch_mode, buffer_size * 4,
154 overlap_size, channels, samplerate);
155 aubio_pitch_set_tolerance (pitchdet, 0.7);
156 pitch_obuf = new_fvec (1, channels);
158 note_buffer = new_fvec (median, 1);
159 note_buffer2 = new_fvec (median, 1);
162 examples_common_process(aubio_process, process_print);
164 send_noteon (curnote, 0);
165 del_aubio_pitch (pitchdet);
167 del_fvec (note_buffer);
168 del_fvec (note_buffer2);
170 del_fvec (pitch_obuf);
172 examples_common_del();
173 debug("End of program.\n");