source: examples/aubiotrack.c @ 43938de

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 43938de was b1aab3a, checked in by Paul Brossier <piem@altern.org>, 19 years ago

added peak picker configuration example
added peak picker configuration example

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2   Copyright (C) 2003 Paul Brossier
3
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.
8
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.
13
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.
17*/
18
19#include "utils.h"
20#include "beattracking.h"
21
22unsigned int pos          = 0;    /* frames%dspblocksize */
23unsigned int pos2         = 0;    /* frames%dspblocksize */
24uint_t usepitch           = 0;
25fvec_t * dfframe          = NULL;
26fvec_t * out              = NULL;
27aubio_beattracking_t * bt = NULL;
28uint_t winlen             = 512;
29uint_t step               = 0;
30uint_t istactus           = 0;
31
32int aubio_process(float **input, float **output, int nframes);
33int 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++) {
38    if(usejack) {
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);
44      }
45    }
46    /*time for fft*/
47    if (pos == overlap_size-1) {         
48      /* block loop */
49      aubio_pvoc_do (pv,ibuf, fftgrain);
50      aubio_onsetdetection(o,fftgrain, onset);
51      if (usedoubled) {
52        aubio_onsetdetection(o2,fftgrain, onset2);
53        onset->data[0][0] *= onset2->data[0][0];
54      }
55      /* execute every overlap_size*step */
56      if (pos2 == step -1 ) {
57             
58        /* check dfframe */
59        /*
60        outmsg("\n");
61        for (i = 0; i < winlen; i++ )
62                outmsg("%f,", dfframe->data[0][i]);
63        outmsg("\n");
64        */
65                       
66        aubio_beattracking_do(bt,dfframe,out);
67
68        /* rotate dfframe */
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.;
73               
74        pos2 = -1;
75      }
76      pos2++;
77      isonset = aubio_peakpick_pimrt_wt(onset,parms,&(dfframe->data[0][winlen - step + pos2]));
78      /* end of second level loop */
79      istactus = 0;
80      i=0;
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) {
88                              isonset  = 0;
89                              istactus = 0;
90                      } else {
91                              istactus = 1;
92                      }
93              }
94      }
95
96      if (istactus ==1) {
97              for (pos = 0; pos < overlap_size; pos++)
98                      obuf->data[0][pos] = woodblock->data[0][pos];
99      } else {
100              for (pos = 0; pos < overlap_size; pos++)
101                      obuf->data[0][pos] = 0.;
102      }
103      /* end of block loop */
104      pos = -1; /* so it will be zero next j loop */
105    }
106    pos++;
107  }
108  return 1;
109}
110
111void process_print (void);
112void process_print (void) {
113        if (output_filename == NULL) {
114                if (istactus)
115                        outmsg("%f\n",(frames)*overlap_size/(float)samplerate); 
116                if (isonset && verbose)
117                        outmsg(" \t \t%f\n",(frames)*overlap_size/(float)samplerate);
118        }
119}
120
121int main(int argc, char **argv) {
122 
123  buffer_size = 1024;
124  overlap_size = 512;
125  /* override default settings */
126  examples_common_init(argc,argv);
127  /* configure peak picker */
128  //aubio_peakpicker_set_thresholdfn(parms,vec_mean);
129  //aubio_peakpicker_set_threshold(parms,0.);
130  winlen = SQR(512)/overlap_size;
131
132  dfframe = new_fvec(winlen,channels);
133  step = winlen/4;
134  out = new_fvec(step,channels);
135
136  /* test input : impulses starting from 15, at intervals of 50 samples */
137  //for(i=0;i<16;i++){
138  //        dfframe->data[0][50*i+14] = 1.;
139  //}
140
141  bt = new_aubio_beattracking(winlen,channels);
142
143  examples_common_process(aubio_process,process_print);
144
145  examples_common_del();
146
147  debug("End of program.\n");
148
149  fflush(stderr);
150
151  return 0;
152}
153
Note: See TracBrowser for help on using the repository browser.