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.
31 const char * output_filename = NULL;
32 const char * input_filename = NULL;
34 const char * onset_filename = "/usr/share/sounds/aubio/woodblock.aiff";
39 int aubio_process(float **input, float **output, int nframes);
43 /* energy,specdiff,hfc,complexdomain,phase */
44 aubio_onsetdetection_type type_onset;
45 smpl_t threshold = 0.1;
47 smpl_t threshold2 = -80.;
49 int buffer_size = 1024;
50 int overlap_size = 512;
52 int samplerate = 44100;
63 aubio_onsetdetection_t *o;
72 aubio_pickpeak_t * parms;
74 int aubio_process(float **input, float **output, int nframes) {
75 unsigned int i; /*channels*/
76 unsigned int j; /*frames*/
77 unsigned int pos = 0; /*frames%dspblocksize*/
78 //unsigned int ons = 0; /*onset counter*/
79 for (j=0;j<nframes;j++) {
81 for (i=0;i<channels;i++) {
82 /* write input to datanew */
83 fvec_write_sample(ibuf, input[i][j], i, pos);
84 /* put synthnew in output */
85 output[i][j] = fvec_read_sample(obuf, i, pos);
88 if (pos == overlap_size-1) {
89 aubio_pvoc_do (pv,ibuf, fftgrain);
90 aubio_onsetdetection(o,fftgrain, onset);
91 fprintf(stderr,"onsetfunc: %f\n",onset->data[0][0]);
92 isonset = aubio_peakpick_pimrt(onset,parms);
94 /* test for silence */
95 if (aubio_silence_detection(ibuf, threshold2)==1)
98 for (pos = 0; pos < overlap_size; pos++)
100 woodblock->data[0][pos];
102 for (pos = 0; pos < overlap_size; pos++)
103 obuf->data[0][pos] = 0.;
105 //aubio_pvoc_rdo(pv,fftgrain, obuf);
106 pos = -1; /* so it will be zero next j loop */
113 int main (int argc, char **argv) {
117 aubio_file_t * file = NULL;
118 aubio_file_t * fileout = NULL;
120 aubio_file_t * onsetfile = new_file_ro(onset_filename);
121 parse_args(argc, argv);
125 debug("Opening files ...\n");
126 file = new_file_ro (input_filename);
128 channels = aubio_file_channels(file);
129 if (output_filename != NULL)
130 fileout = new_file_wo(file, output_filename);
133 ibuf = new_fvec(overlap_size, channels);
134 obuf = new_fvec(overlap_size, channels);
135 woodblock = new_fvec(buffer_size,1);
136 fftgrain = new_cvec(buffer_size, channels);
138 file_read(onsetfile, overlap_size, woodblock);
141 debug("Phase voc init ... \n");
142 pv = new_aubio_pvoc(buffer_size, overlap_size, channels);
145 debug("type_onset: %d\n", (int)type_onset);
146 debug("threshold : %f\n", threshold);
147 parms = new_aubio_peakpicker(threshold);
149 o = new_aubio_onsetdetection(type_onset,buffer_size,channels);
150 /*onset = new_fvec(overlap_size, channels);
151 for (frames=0;frames<overlap_size;frames++){
152 onset->data[0][frames] = 0.;
154 onset = new_fvec(0, channels);
156 //onset_keep = new_fvec(post+pre+1, channels);
157 //onset_proc = new_fvec(post+pre+1, channels);
159 // command line argument parsing
162 aubio_jack_t * jack_setup;
163 debug("Jack init ...\n");
164 jack_setup = new_aubio_jack(channels, channels,
165 (aubio_process_func_t)aubio_process);
167 /* initialise fftgrain */
168 aubio_pvoc_do (pv,ibuf, fftgrain);
170 debug("Jack activation ...\n");
171 aubio_jack_activate(jack_setup);
173 debug("Processing (Ctrl+C to quit) ...\n");
176 aubio_jack_close(jack_setup);
184 inputbuf = new_fvec(overlap_size, channels);
185 outputbuf = new_fvec(overlap_size, channels);
187 debug("Processing ...\n");
189 /** \bug phasevoc not initialized yet */
190 /* initialise fftgrain and input bug */
191 for (frames=0;frames<2;frames++) {
192 aubio_pvoc_do (pv,inputbuf, fftgrain);
195 /** start filling the phasevoc */
196 //for (frames=0;frames<1;frames++) {
197 //file_read(file, overlap_size, inputbuf);
198 //aubio_pvoc_do (pv,inputbuf, fftgrain);
199 /** \bug onset is still badly initialized */
200 //aubio_onsetdetection(o,fftgrain, onset);
205 while ((overlap_size == file_read(file, overlap_size, inputbuf)) )
208 aubio_process(inputbuf->data, outputbuf->data, overlap_size);
210 /*output times in seconds*/
211 //errmsg("%f\n",(frames-1)*overlap_size/(float)samplerate);
212 errmsg("%f\n",(frames-3)*overlap_size/(float)samplerate);
214 if (output_filename != NULL)
215 file_write(fileout,overlap_size,outputbuf);
218 debug("Processed %d frames of %d samples.\n", frames, buffer_size);
220 if (output_filename != NULL)
229 //del_fvec(onset_keep);
230 //del_fvec(onset_proc);
233 debug("End of program.\n");