Changeset d4c5de7 for examples/aubionotes.c
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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");
Note: See TracChangeset
for help on using the changeset viewer.