Changeset 155cc10 for examples/aubionotes.c
- Timestamp:
- Mar 10, 2017, 2:26:32 PM (7 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, sampler
- Children:
- ee8a57c
- Parents:
- 00d0275 (diff), 67b6618 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/aubionotes.c
r00d0275 r155cc10 19 19 */ 20 20 21 #define AUBIO_UNSTABLE 1 // for fvec_median22 21 #include "utils.h" 23 22 #define PROG_HAS_PITCH 1 24 23 #define PROG_HAS_ONSET 1 24 #define PROG_HAS_SILENCE 1 25 25 #define PROG_HAS_JACK 1 26 26 // TODO add PROG_HAS_OUTPUT 27 27 #include "parse_args.h" 28 28 29 uint_t median = 6; 30 31 fvec_t *note_buffer; 32 fvec_t *note_buffer2; 33 34 smpl_t curnote = 0.; 35 smpl_t newnote = 0.; 36 uint_t isready = 0; 37 38 aubio_pitch_t *pitch; 39 aubio_onset_t *o; 40 fvec_t *onset; 41 fvec_t *pitch_obuf; 42 43 /** append new note candidate to the note_buffer and return filtered value. we 44 * need to copy the input array as fvec_median destroy its input data.*/ 45 void note_append (fvec_t * note_buffer, smpl_t curnote); 46 uint_t get_note (fvec_t * note_buffer, fvec_t * note_buffer2); 29 aubio_notes_t *notes; 30 smpl_t lastmidi = 0.; 47 31 48 32 void process_block (fvec_t *ibuf, fvec_t *obuf) 49 33 { 50 smpl_t new_pitch, curlevel; 51 fvec_zeros(obuf); 52 aubio_onset_do(o, ibuf, onset); 53 54 aubio_pitch_do (pitch, ibuf, pitch_obuf); 55 new_pitch = fvec_get_sample(pitch_obuf, 0); 56 if(median){ 57 note_append(note_buffer, new_pitch); 34 aubio_notes_do (notes, ibuf, obuf); 35 // did we get a note off? 36 if (obuf->data[2] != 0) { 37 lastmidi = obuf->data[2]; 38 send_noteon(lastmidi, 0); 58 39 } 59 60 /* curlevel is negatif or 1 if silence */ 61 curlevel = aubio_level_detection(ibuf, silence_threshold); 62 if (fvec_get_sample(onset, 0)) { 63 /* test for silence */ 64 if (curlevel == 1.) { 65 if (median) isready = 0; 66 /* send note off */ 67 send_noteon(curnote,0); 68 } else { 69 if (median) { 70 isready = 1; 71 } else { 72 /* kill old note */ 73 send_noteon(curnote,0); 74 /* get and send new one */ 75 send_noteon(new_pitch,127+(int)floor(curlevel)); 76 curnote = new_pitch; 77 } 78 } 79 } else { 80 if (median) { 81 if (isready > 0) 82 isready++; 83 if (isready == median) 84 { 85 /* kill old note */ 86 send_noteon(curnote,0); 87 newnote = get_note(note_buffer, note_buffer2); 88 curnote = newnote; 89 /* get and send new one */ 90 if (curnote>45){ 91 send_noteon(curnote,127+(int)floor(curlevel)); 92 } 93 } 94 } // if median 40 // did we get a note on? 41 if (obuf->data[0] != 0) { 42 lastmidi = obuf->data[0]; 43 send_noteon(lastmidi, obuf->data[1]); 95 44 } 96 45 } … … 101 50 } 102 51 103 void 104 note_append (fvec_t * note_buffer, smpl_t curnote) 105 { 106 uint_t i = 0; 107 for (i = 0; i < note_buffer->length - 1; i++) { 108 note_buffer->data[i] = note_buffer->data[i + 1]; 109 } 110 note_buffer->data[note_buffer->length - 1] = curnote; 111 return; 112 } 52 int main(int argc, char **argv) { 53 int ret = 0; 113 54 114 uint_t115 get_note (fvec_t * note_buffer, fvec_t * note_buffer2)116 {117 uint_t i;118 for (i = 0; i < note_buffer->length; i++) {119 note_buffer2->data[i] = note_buffer->data[i];120 }121 return fvec_median (note_buffer2);122 }123 124 int main(int argc, char **argv) {125 55 examples_common_init(argc,argv); 126 56 … … 137 67 verbmsg ("tolerance: %f\n", pitch_tolerance); 138 68 139 o = new_aubio_onset (onset_method, buffer_size, hop_size, samplerate); 140 if (onset_threshold != 0.) aubio_onset_set_threshold (o, onset_threshold); 141 onset = new_fvec (1); 69 notes = new_aubio_notes ("default", buffer_size, hop_size, samplerate); 70 if (notes == NULL) { ret = 1; goto beach; } 142 71 143 pitch = new_aubio_pitch (pitch_method, buffer_size * 4, hop_size, samplerate); 144 if (pitch_tolerance != 0.) aubio_pitch_set_tolerance (pitch, pitch_tolerance); 145 pitch_obuf = new_fvec (1); 146 147 if (median) { 148 note_buffer = new_fvec (median); 149 note_buffer2 = new_fvec (median); 72 if (onset_minioi != 0.) { 73 aubio_notes_set_minioi_ms(notes, onset_minioi); 74 } 75 if (onset_threshold != 0.) { 76 errmsg ("warning: onset threshold not supported yet\n"); 77 //aubio_onset_set_threshold(aubio_notes_get_aubio_onset(o), onset_threshold); 78 } 79 if (silence_threshold != -90.) { 80 if (aubio_notes_set_silence (notes, silence_threshold) != 0) { 81 errmsg ("failed setting notes silence threshold to %.2f\n", 82 silence_threshold); 83 } 150 84 } 151 85 152 86 examples_common_process((aubio_process_func_t)process_block, process_print); 153 87 154 // send a last note off 155 send_noteon (curnote, 0); 88 // send a last note off if required 89 if (lastmidi) { 90 send_noteon (lastmidi, 0); 91 } 156 92 157 del_aubio_pitch (pitch); 158 if (median) { 159 del_fvec (note_buffer); 160 del_fvec (note_buffer2); 161 } 162 del_fvec (pitch_obuf); 93 del_aubio_notes (notes); 163 94 95 beach: 164 96 examples_common_del(); 165 return 0;97 return ret; 166 98 } 167
Note: See TracChangeset
for help on using the changeset viewer.