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.
20 #include "beattracking.h"
22 unsigned int pos = 0; /* frames%dspblocksize */
23 unsigned int pos2 = 0; /* frames%dspblocksize */
25 fvec_t * dfframe = NULL;
27 aubio_beattracking_t * bt = NULL;
32 int aubio_process(float **input, float **output, int nframes);
33 int aubio_process(float **input, float **output, int nframes) {
34 unsigned int i; /*channels*/
35 unsigned int j; /*frames*/
36 smpl_t * btoutput = out->data[0];
37 for (j=0;j<nframes;j++) {
39 for (i=0;i<channels;i++) {
40 /* write input to datanew */
41 fvec_write_sample(ibuf, input[i][j], i, pos);
42 /* put synthnew in output */
43 output[i][j] = fvec_read_sample(obuf, i, pos);
47 if (pos == overlap_size-1) {
49 aubio_pvoc_do (pv,ibuf, fftgrain);
50 aubio_onsetdetection(o,fftgrain, onset);
52 aubio_onsetdetection(o2,fftgrain, onset2);
53 onset->data[0][0] *= onset2->data[0][0];
55 /* execute every overlap_size*step */
56 if (pos2 == step -1 ) {
61 for (i = 0; i < winlen; i++ )
62 outmsg("%f,", dfframe->data[0][i]);
66 aubio_beattracking_do(bt,dfframe,out);
69 for (i = 0 ; i < winlen - step; i++ )
70 dfframe->data[0][i] = dfframe->data[0][i+step];
71 for (i = winlen - step ; i < winlen; i++ )
72 dfframe->data[0][i] = 0.;
77 isonset = aubio_peakpick_pimrt_wt(onset,parms,&(dfframe->data[0][winlen - step + pos2]));
78 /* end of second level loop */
81 for (i = 1; i < btoutput[0]; i++ ) {
82 if (pos2 == btoutput[i]) {
83 //printf("pos2: %d\n", pos2);
84 //printf("tempo:\t%3.5f bpm \n",
85 //60.*44100./overlap_size/abs(btoutput[2]-btoutput[1]));
86 /* test for silence */
87 if (aubio_silence_detection(ibuf, threshold2)==1) {
97 for (pos = 0; pos < overlap_size; pos++)
98 obuf->data[0][pos] = woodblock->data[0][pos];
100 for (pos = 0; pos < overlap_size; pos++)
101 obuf->data[0][pos] = 0.;
103 /* end of block loop */
104 pos = -1; /* so it will be zero next j loop */
111 void process_print (void);
112 void process_print (void) {
113 if (output_filename == NULL) {
115 outmsg("%f\n",(frames)*overlap_size/(float)samplerate);
116 if (isonset && verbose)
117 outmsg(" \t \t%f\n",(frames)*overlap_size/(float)samplerate);
121 int main(int argc, char **argv) {
123 /* override default settings */
124 examples_common_init(argc,argv);
125 winlen = SQR(512)/overlap_size;
127 dfframe = new_fvec(winlen,channels);
129 out = new_fvec(step,channels);
131 /* test input : impulses starting from 15, at intervals of 50 samples */
133 // dfframe->data[0][50*i+14] = 1.;
136 bt = new_aubio_beattracking(winlen,channels);
138 examples_common_process(aubio_process,process_print);
140 examples_common_del();
142 debug("End of program.\n");