- Timestamp:
- Oct 16, 2009, 11:03:08 PM (15 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 6107f4c
- Parents:
- 2828382
- Location:
- examples
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/aubiomfcc.c
r2828382 rd4c5de7 23 23 fvec_t * mfcc_out; 24 24 aubio_mfcc_t * mfcc; 25 aubio_pvoc_t *pv; 26 cvec_t *fftgrain; 25 27 26 28 uint_t n_filters = 40; … … 28 30 29 31 unsigned int pos = 0; /*frames%dspblocksize*/ 30 uint_t usepitch = 0;31 32 32 int aubio_process(smpl_t **input, smpl_t **output, int nframes); 33 int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 33 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 34 34 unsigned int i; /*channels*/ 35 35 unsigned int j; /*frames*/ … … 62 62 } 63 63 64 void process_print (void); 65 void process_print (void) { 64 static void process_print (void) { 66 65 /* output times in seconds 67 66 write extracted mfccs … … 84 83 85 84 examples_common_init(argc,argv); 85 86 /* phase vocoder */ 87 pv = new_aubio_pvoc (buffer_size, overlap_size, channels); 88 89 fftgrain = new_cvec (buffer_size, channels); 90 91 //populating the filter 92 mfcc = new_aubio_mfcc(buffer_size, n_filters, n_coefs, samplerate); 93 86 94 mfcc_out = new_fvec(n_coefs,channels); 87 88 89 //populating the filter90 mfcc = new_aubio_mfcc(buffer_size, samplerate, n_filters, n_coefs);91 95 92 96 //process … … 94 98 95 99 //destroying mfcc 100 del_aubio_pvoc (pv); 101 del_cvec (fftgrain); 96 102 del_aubio_mfcc(mfcc); 97 103 del_fvec(mfcc_out); -
examples/aubionotes.c
r2828382 rd4c5de7 19 19 #include "utils.h" 20 20 21 /* pitch objects */ 22 smpl_t pitch = 0.; 23 24 uint_t median = 6; 25 smpl_t curlevel = 0.; 26 27 aubio_pitchdetection_t *pitchdet; 28 29 fvec_t *note_buffer = NULL; 30 fvec_t *note_buffer2 = NULL; 31 32 smpl_t curnote = 0.; 33 smpl_t newnote = 0.; 34 uint_t isready = 0; 21 35 unsigned int pos = 0; /*frames%dspblocksize*/ 22 uint_t usepitch = 1;23 36 24 int aubio_process(smpl_t **input, smpl_t **output, int nframes); 25 int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 37 aubio_pitchdetection_t *pitchdet; 38 aubio_onset_t *o; 39 fvec_t *onset; 40 fvec_t *pitch_obuf; 41 42 /** append new note candidate to the note_buffer and return filtered value. we 43 * need to copy the input array as fvec_median destroy its input data.*/ 44 void note_append (fvec_t * note_buffer, smpl_t curnote); 45 uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2); 46 47 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 26 48 unsigned int i; /*channels*/ 27 49 unsigned int j; /*frames*/ … … 38 60 if (pos == overlap_size-1) { 39 61 /* block loop */ 40 aubio_pvoc_do (pv,ibuf, fftgrain); 41 aubio_onsetdetection_do(o,fftgrain, onset); 42 isonset = aubio_peakpicker_do(parms, onset); 62 aubio_onset_do(o, ibuf, onset); 43 63 44 64 aubio_pitchdetection_do (pitchdet, ibuf, pitch_obuf); … … 50 70 /* curlevel is negatif or 1 if silence */ 51 71 curlevel = aubio_level_detection(ibuf, silence); 52 if ( isonset) {72 if (fvec_read_sample(onset, 0, 0)) { 53 73 /* test for silence */ 54 74 if (curlevel == 1.) { 55 isonset=0;56 75 if (median) isready = 0; 57 76 /* send note off */ … … 99 118 } 100 119 101 void process_print (void); 102 void process_print (void) { 120 static void process_print (void) { 103 121 if (verbose) outmsg("%f\n",pitch); 122 } 123 124 void 125 note_append (fvec_t * note_buffer, smpl_t curnote) 126 { 127 uint_t i = 0; 128 for (i = 0; i < note_buffer->length - 1; i++) { 129 note_buffer->data[0][i] = note_buffer->data[0][i + 1]; 130 } 131 note_buffer->data[0][note_buffer->length - 1] = curnote; 132 return; 133 } 134 135 uint_t 136 get_note (fvec_t * note_buffer, fvec_t * note_buffer2) 137 { 138 uint_t i = 0; 139 for (i = 0; i < note_buffer->length; i++) { 140 note_buffer2->data[0][i] = note_buffer->data[0][i]; 141 } 142 return fvec_median (note_buffer2); 104 143 } 105 144 106 145 int main(int argc, char **argv) { 107 146 examples_common_init(argc,argv); 147 148 o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels, 149 samplerate); 150 onset = new_fvec (1, channels); 151 152 pitchdet = new_aubio_pitchdetection (pitch_mode, buffer_size * 4, 153 overlap_size, channels, samplerate); 154 aubio_pitchdetection_set_tolerance (pitchdet, 0.7); 155 pitch_obuf = new_fvec (1, channels); 156 if (median) { 157 note_buffer = new_fvec (median, 1); 158 note_buffer2 = new_fvec (median, 1); 159 } 160 108 161 examples_common_process(aubio_process, process_print); 162 163 send_noteon (curnote, 0); 164 del_aubio_pitchdetection (pitchdet); 165 if (median) { 166 del_fvec (note_buffer); 167 del_fvec (note_buffer2); 168 } 169 del_fvec (pitch_obuf); 170 109 171 examples_common_del(); 110 172 debug("End of program.\n"); -
examples/aubioonset.c
r2828382 rd4c5de7 20 20 21 21 unsigned int pos = 0; /*frames%dspblocksize*/ 22 uint_t usepitch = 0;23 22 24 int aubio_process(smpl_t **input, smpl_t **output, int nframes); 25 int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 23 aubio_onset_t *o; 24 fvec_t *onset; 25 26 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 26 27 unsigned int i; /*channels*/ 27 28 unsigned int j; /*frames*/ … … 38 39 if (pos == overlap_size-1) { 39 40 /* block loop */ 40 aubio_pvoc_do (pv,ibuf, fftgrain); 41 aubio_onsetdetection_do (o,fftgrain, onset); 42 isonset = aubio_peakpicker_do(parms, onset); 43 if (isonset) { 44 /* test for silence */ 45 if (aubio_silence_detection(ibuf, silence)==1) 46 isonset=0.; 47 else 48 for (pos = 0; pos < overlap_size; pos++){ 49 obuf->data[0][pos] = woodblock->data[0][pos]; 50 } 41 aubio_onset_do (o, ibuf, onset); 42 if (fvec_read_sample(onset, 0, 0)) { 43 for (pos = 0; pos < overlap_size; pos++){ 44 obuf->data[0][pos] = woodblock->data[0][pos]; 45 } 51 46 } else { 52 for (pos = 0; pos < overlap_size; pos++) 47 for (pos = 0; pos < overlap_size; pos++) { 53 48 obuf->data[0][pos] = 0.; 49 } 54 50 } 55 51 /* end of block loop */ … … 61 57 } 62 58 63 void process_print (void); 64 void process_print (void) { 59 static void process_print (void) { 65 60 /* output times in seconds, taking back some 66 61 * delay to ensure the label is _before_ the 67 62 * actual onset */ 68 if (isonset && output_filename == NULL) { 63 if (!verbose && usejack) return; 64 smpl_t onset_found = fvec_read_sample(onset, 0, 0); 65 if (onset_found) { 69 66 if(frames >= 4) { 70 outmsg("%f\n",(frames - frames_delay + isonset)*overlap_size/(float)samplerate); 67 outmsg("%f\n",(frames - frames_delay + onset_found) 68 *overlap_size/(float)samplerate); 71 69 } else if (frames < frames_delay) { 72 70 outmsg("%f\n",0.); … … 78 76 frames_delay = 3; 79 77 examples_common_init(argc,argv); 78 79 o = new_aubio_onset (onset_mode, buffer_size, overlap_size, channels, 80 samplerate); 81 onset = new_fvec (1, channels); 82 80 83 examples_common_process(aubio_process,process_print); 84 85 del_aubio_onset (o); 86 del_fvec (onset); 87 81 88 examples_common_del(); 82 89 debug("End of program.\n"); -
examples/aubioquiet.c
r2828382 rd4c5de7 21 21 unsigned int pos = 0; /*frames%dspblocksize*/ 22 22 sint_t wassilence = 1, issilence; 23 uint_t usepitch = 0;24 23 25 24 int aubio_process(smpl_t **input, smpl_t **output, int nframes); … … 56 55 } 57 56 58 void process_print (void); 59 void process_print (void) { 57 static void process_print (void) { 60 58 int curframes = (frames - 4) > 0 ? frames -4 : 0; 61 59 if (issilence == -1) { -
examples/aubiotrack.c
r2828382 rd4c5de7 20 20 #include "utils.h" 21 21 22 u nsigned int pos= 0; /* frames%dspblocksize */23 uint_t usepitch = 0;24 fvec_t * out= NULL;25 aubio_tempo_t * bt = NULL;26 smpl_t is tactus= 0;22 uint_t pos = 0; /* frames%dspblocksize */ 23 fvec_t * tempo_out = NULL; 24 aubio_tempo_t * bt = NULL; 25 smpl_t istactus = 0; 26 smpl_t isonset = 0; 27 27 28 int aubio_process(smpl_t **input, smpl_t **output, int nframes); 29 int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 28 static int aubio_process(smpl_t **input, smpl_t **output, int nframes) { 30 29 unsigned int i; /*channels*/ 31 30 unsigned int j; /*frames*/ … … 42 41 if (pos == overlap_size-1) { 43 42 /* block loop */ 44 aubio_tempo_do (bt,ibuf, out);45 if ( out->data[0][0]>=1)46 istactus = out->data[0][0];43 aubio_tempo_do (bt,ibuf,tempo_out); 44 if (tempo_out->data[0][0]>0) 45 istactus = tempo_out->data[0][0]; 47 46 else 48 47 istactus = 0; 48 if (tempo_out->data[0][1]>0) 49 isonset = tempo_out->data[0][0]; 50 else 51 isonset = 0; 49 52 if (istactus) { 50 53 for (pos = 0; pos < overlap_size; pos++) … … 62 65 } 63 66 64 void process_print (void); 65 void process_print (void) { 67 static void process_print (void) { 66 68 if (output_filename == NULL) { 67 69 if (istactus) { … … 80 82 examples_common_init(argc,argv); 81 83 82 out = new_fvec(2,channels);83 bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size,channels);84 tempo_out = new_fvec(2,channels); 85 bt = new_aubio_tempo(onset_mode,buffer_size,overlap_size,channels, samplerate); 84 86 85 87 examples_common_process(aubio_process,process_print); 86 88 87 89 del_aubio_tempo(bt); 88 del_fvec( out);90 del_fvec(tempo_out); 89 91 90 92 examples_common_del(); -
examples/utils.c
r2828382 rd4c5de7 16 16 You should have received a copy of the GNU General Public License 17 17 along with aubio. If not, see <http://www.gnu.org/licenses/>. 18 19 */ 20 21 /** 22 23 This file includes some tools common to all examples. Code specific to the 24 algorithm performed by each program should go in the source file of that 25 program instead. 18 26 19 27 */ … … 41 49 int verbose = 0; 42 50 int usejack = 0; 43 int usedoubled = 1;44 51 int frames_delay = 0; 45 52 53 54 char_t * pitch_unit = "default"; 55 char_t * pitch_mode = "default"; 46 56 47 57 /* energy,specdiff,hfc,complexdomain,phase */ … … 58 68 aubio_sndfile_t *fileout = NULL; 59 69 60 aubio_pvoc_t *pv;61 70 fvec_t *ibuf; 62 71 fvec_t *obuf; 63 fvec_t *pitch_obuf;64 cvec_t *fftgrain;65 72 fvec_t *woodblock; 66 aubio_onsetdetection_t *o;67 fvec_t *onset;68 fvec_t *onset2;69 smpl_t isonset = 0;70 aubio_peakpicker_t *parms;71 72 73 /* pitch objects */74 smpl_t pitch = 0.;75 aubio_pitchdetection_t *pitchdet;76 char_t * pitch_unit = "default";77 char_t * pitch_mode = "default";78 uint_t median = 6;79 80 fvec_t *note_buffer = NULL;81 fvec_t *note_buffer2 = NULL;82 smpl_t curlevel = 0.;83 smpl_t maxonset = 0.;84 85 smpl_t curnote = 0.;86 smpl_t newnote = 0.;87 uint_t isready = 0;88 89 90 73 91 74 /* badly redeclare some things */ … … 93 76 smpl_t averaging; 94 77 const char *prog_name; 78 79 void flush_process (aubio_process_func_t process_func, 80 aubio_print_func_t print); 95 81 96 82 void … … 222 208 { 223 209 210 uint_t found_wood = 0; 224 211 225 212 aubio_sndfile_t *onsetfile = NULL; … … 230 217 if (output_filename || usejack) { 231 218 /* dummy assignement to keep egcs happy */ 232 isonset= (onsetfile = new_aubio_sndfile_ro (onset_filename)) ||219 found_wood = (onsetfile = new_aubio_sndfile_ro (onset_filename)) || 233 220 (onsetfile = new_aubio_sndfile_ro ("sounds/woodblock.aiff")) || 234 221 (onsetfile = new_aubio_sndfile_ro ("../sounds/woodblock.aiff")); … … 277 264 ibuf = new_fvec (overlap_size, channels); 278 265 obuf = new_fvec (overlap_size, channels); 279 fftgrain = new_cvec (buffer_size, channels);280 281 if (usepitch) {282 pitchdet = new_aubio_pitchdetection (pitch_mode, buffer_size * 4,283 overlap_size, channels, samplerate);284 aubio_pitchdetection_set_tolerance (pitchdet, 0.7);285 pitch_obuf = new_fvec (1, channels);286 287 if (median) {288 note_buffer = new_fvec (median, 1);289 note_buffer2 = new_fvec (median, 1);290 }291 }292 /* phase vocoder */293 pv = new_aubio_pvoc (buffer_size, overlap_size, channels);294 /* onsets */295 parms = new_aubio_peakpicker (threshold);296 o = new_aubio_onsetdetection (onset_mode, buffer_size, channels);297 onset = new_fvec (1, channels);298 266 299 267 } … … 303 271 examples_common_del (void) 304 272 { 305 if (usepitch) { 306 send_noteon (curnote, 0); 307 del_aubio_pitchdetection (pitchdet); 308 if (median) { 309 del_fvec (note_buffer); 310 del_fvec (note_buffer2); 311 } 312 del_fvec (pitch_obuf); 313 } 314 del_aubio_onsetdetection (o); 315 del_aubio_peakpicker (parms); 316 del_aubio_pvoc (pv); 273 del_fvec (ibuf); 317 274 del_fvec (obuf); 318 del_fvec (ibuf);319 del_cvec (fftgrain);320 del_fvec (onset);321 275 del_fvec (woodblock); 322 276 aubio_cleanup (); … … 355 309 while ((signed) overlap_size == aubio_sndfile_read (file, overlap_size, 356 310 ibuf)) { 357 isonset = 0;358 311 process_func (ibuf->data, obuf->data, overlap_size); 359 312 print (); … … 416 369 417 370 418 void419 note_append (fvec_t * note_buffer, smpl_t curnote)420 {421 uint_t i = 0;422 for (i = 0; i < note_buffer->length - 1; i++) {423 note_buffer->data[0][i] = note_buffer->data[0][i + 1];424 }425 note_buffer->data[0][note_buffer->length - 1] = curnote;426 return;427 }428 429 uint_t430 get_note (fvec_t * note_buffer, fvec_t * note_buffer2)431 {432 uint_t i = 0;433 for (i = 0; i < note_buffer->length; i++) {434 note_buffer2->data[0][i] = note_buffer->data[0][i];435 }436 return fvec_median (note_buffer2);437 }438 439 371 #if HAVE_LASH 440 372 -
examples/utils.h
r2828382 rd4c5de7 43 43 extern int verbose; 44 44 extern int usejack; 45 extern int usedoubled;46 45 extern int frames_delay; 47 extern unsigned int median;48 extern const char *output_filename;49 extern const char *input_filename;50 46 /* defined in utils.c */ 51 47 void usage (FILE * stream, int exit_code); … … 60 56 void examples_common_process (aubio_process_func_t process_func, 61 57 aubio_print_func_t print); 62 void flush_process (aubio_process_func_t process_func,63 aubio_print_func_t print);64 58 59 extern char_t * pitch_unit; 60 extern char_t * pitch_mode; 65 61 66 62 void send_noteon (int pitch, int velo); 67 /** append new note candidate to the note_buffer and return filtered value. we68 * need to copy the input array as fvec_median destroy its input data.*/69 void note_append (fvec_t * note_buffer, smpl_t curnote);70 uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2);71 63 72 64 extern const char *output_filename; 73 extern const char *input_filename;74 extern const char *onset_filename;75 extern int verbose;76 extern int usejack;77 extern int usedoubled;78 79 80 /* energy,specdiff,hfc,complexdomain,phase */81 65 extern char_t * onset_mode; 82 66 extern smpl_t threshold; 83 67 extern smpl_t silence; 68 extern int verbose; 69 extern int usejack; 84 70 extern uint_t buffer_size; 85 71 extern uint_t overlap_size; … … 87 73 extern uint_t samplerate; 88 74 89 90 extern aubio_sndfile_t *file;91 extern aubio_sndfile_t *fileout;92 93 extern aubio_pvoc_t *pv;94 75 extern fvec_t *ibuf; 95 76 extern fvec_t *obuf; 96 extern fvec_t *pitch_obuf;97 extern cvec_t *fftgrain;98 77 extern fvec_t *woodblock; 99 extern aubio_onsetdetection_t *o;100 extern aubio_onsetdetection_t *o2;101 extern fvec_t *onset;102 extern fvec_t *onset2;103 extern smpl_t isonset;104 extern aubio_peakpicker_t *parms;105 106 107 /* pitch objects */108 extern smpl_t pitch;109 extern aubio_pitchdetection_t *pitchdet;110 extern uint_t median;111 112 extern fvec_t *note_buffer;113 extern fvec_t *note_buffer2;114 extern smpl_t curlevel;115 extern smpl_t maxonset;116 117 extern smpl_t curnote;118 extern smpl_t newnote;119 extern uint_t isready;120 121 /* per example param */122 extern uint_t usepitch;
Note: See TracChangeset
for help on using the changeset viewer.