source: examples/aubiotrack.c @ f88a326

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

update beattracking.c
update beattracking.c

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[b78805a]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               = 128;
30uint_t laglen             = 128;
31uint_t rayparam           = 43;
32uint_t istactus           = 0;
33
34int aubio_process(float **input, float **output, int nframes);
35int aubio_process(float **input, float **output, int nframes) {
36  unsigned int i;       /*channels*/
37  unsigned int j;       /*frames*/
38  smpl_t * btoutput = out->data[0];
39  for (j=0;j<nframes;j++) {
40    if(usejack) {
41      for (i=0;i<channels;i++) {
42        /* write input to datanew */
43        fvec_write_sample(ibuf, input[i][j], i, pos);
44        /* put synthnew in output */
45        output[i][j] = fvec_read_sample(obuf, i, pos);
46      }
47    }
48    /*time for fft*/
49    if (pos == overlap_size-1) {         
50      /* block loop */
51      aubio_pvoc_do (pv,ibuf, fftgrain);
52      aubio_onsetdetection(o,fftgrain, onset);
53      if (usedoubled) {
54        aubio_onsetdetection(o2,fftgrain, onset2);
55        onset->data[0][0] *= onset2->data[0][0];
56      }
57      /* execute every overlap_size*step */
58      if (pos2 == step -1 ) {
59             
60        /* check dfframe */
61        /*
62        outmsg("\n");
63        for (i = 0; i < winlen; i++ )
64                outmsg("%f,", dfframe->data[0][i]);
65        outmsg("\n");
66        */
67                       
68        aubio_beattracking_do(bt,dfframe,out);
69
70        /* rotate dfframe */
71        for (i = 0 ; i < winlen - step; i++ ) 
72                dfframe->data[0][i] = dfframe->data[0][i+step];
73        for (i = winlen - step ; i < winlen; i++ ) 
74                dfframe->data[0][i] = 0.;
75               
76        pos2 = -1;
77      }
78      pos2++;
79      isonset = aubio_peakpick_pimrt_wt(onset,parms,&(dfframe->data[0][winlen - step + pos2]));
80      /* end of second level loop */
81      istactus = 0;
82      i=0;
[2cdae81]83      for (i = 1; i < btoutput[0]; i++ ) { 
84              if (pos2 == btoutput[i]) {
[b78805a]85                      //printf("pos2: %d\n", pos2);
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)
[2cdae81]115                        outmsg("%f\n",(frames)*overlap_size/(float)samplerate); 
116                if (isonset && verbose)
[b78805a]117                        outmsg(" \t \t%f\n",(frames)*overlap_size/(float)samplerate);
118        }
119}
120
121int main(int argc, char **argv) {
122 
123  /* override default settings */
124  examples_common_init(argc,argv);
125
126  dfframe = new_fvec(winlen,channels);
127  out = new_fvec(step,channels);
128  /* test input : impulses starting from 15, at intervals of 50 samples */
129  //for(i=0;i<16;i++){
130  //        dfframe->data[0][50*i+14] = 1.;
131  //}
132
133  bt = new_aubio_beattracking(winlen,step, laglen,
134                  rayparam, channels);
135
136  examples_common_process(aubio_process,process_print);
137
138  examples_common_del();
139
140  debug("End of program.\n");
141
142  fflush(stderr);
143
144  return 0;
145}
146
Note: See TracBrowser for help on using the repository browser.