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.
28 int aubio_process(float **input, float **output, int nframes);
30 const char * output_filename = NULL;
31 const char * input_filename = NULL;
32 const char * onset_filename = "/usr/share/sounds/aubio/woodblock.aiff";
40 /* energy,specdiff,hfc,complexdomain,phase */
41 aubio_onsetdetection_type type_onset = hfc;
42 aubio_onsetdetection_type type_onset2 = complexdomain;
43 smpl_t threshold = 0.1;
44 smpl_t threshold2 = -90.;
45 uint_t buffer_size = 1024;
46 uint_t overlap_size = 512;
48 uint_t samplerate = 44100;
56 aubio_onsetdetection_t *o;
57 aubio_onsetdetection_t *o2;
61 aubio_pickpeak_t * parms;
62 unsigned int pos = 0; /*frames%dspblocksize*/
64 int aubio_process(float **input, float **output, int nframes) {
65 unsigned int i; /*channels*/
66 unsigned int j; /*frames*/
67 for (j=0;j<nframes;j++) {
69 for (i=0;i<channels;i++) {
70 /* write input to datanew */
71 fvec_write_sample(ibuf, input[i][j], i, pos);
72 /* put synthnew in output */
73 output[i][j] = fvec_read_sample(obuf, i, pos);
77 if (pos == overlap_size-1) {
79 aubio_pvoc_do (pv,ibuf, fftgrain);
80 aubio_onsetdetection(o,fftgrain, onset);
82 aubio_onsetdetection(o2,fftgrain, onset2);
83 onset->data[0][0] *= onset2->data[0][0];
85 isonset = aubio_peakpick_pimrt(onset,parms);
87 /* test for silence */
88 if (aubio_silence_detection(ibuf, threshold2)==1)
91 for (pos = 0; pos < overlap_size; pos++){
92 obuf->data[0][pos] = woodblock->data[0][pos];
95 for (pos = 0; pos < overlap_size; pos++)
96 obuf->data[0][pos] = 0.;
98 //aubio_pvoc_rdo(pv,fftgrain, obuf);
99 /* end of block loop */
100 pos = -1; /* so it will be zero next j loop */
107 int main(int argc, char **argv) {
110 aubio_file_t * file = NULL;
111 aubio_file_t * fileout = NULL;
113 aubio_file_t * onsetfile = new_file_ro(onset_filename);
114 parse_args(argc, argv);
118 debug("Opening files ...\n");
119 file = new_file_ro (input_filename);
120 if (verbose) file_info(file);
121 channels = aubio_file_channels(file);
122 samplerate = aubio_file_samplerate(file);
123 if (output_filename != NULL)
124 fileout = new_file_wo(file, output_filename);
127 ibuf = new_fvec(overlap_size, channels);
128 obuf = new_fvec(overlap_size, channels);
129 woodblock = new_fvec(buffer_size,1);
130 fftgrain = new_cvec(buffer_size, channels);
132 /* read the output sound once */
133 file_read(onsetfile, overlap_size, woodblock);
136 debug("Phase voc init ... \n");
137 pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
140 parms = new_aubio_peakpicker(threshold);
141 o = new_aubio_onsetdetection(type_onset,buffer_size,channels);
142 onset = new_fvec(1, channels);
144 o2 = new_aubio_onsetdetection(type_onset2,buffer_size,channels);
145 onset2 = new_fvec(1 , channels);
150 aubio_jack_t * jack_setup;
151 debug("Jack init ...\n");
152 jack_setup = new_aubio_jack(channels, channels,
153 (aubio_process_func_t)aubio_process);
154 debug("Jack activation ...\n");
155 aubio_jack_activate(jack_setup);
156 debug("Processing (Ctrl+C to quit) ...\n");
158 aubio_jack_close(jack_setup);
160 outmsg("Compiled without jack output, exiting.");
165 debug("Processing ...\n");
169 while (overlap_size == file_read(file, overlap_size, ibuf))
172 aubio_process(ibuf->data, obuf->data, overlap_size);
173 /* output times in seconds, taking back some
174 * delay to ensure the label is _before_ the
176 if (isonset && output_filename == NULL) {
178 outmsg("%f\n",(frames-4)*overlap_size/(float)samplerate);
179 } else if (frames < 4) {
183 if (output_filename != NULL) {
184 file_write(fileout,overlap_size,obuf);
189 debug("Processed %d frames of %d samples.\n", frames, buffer_size);
192 if (output_filename != NULL)
203 debug("End of program.\n");