Changeset 4b9443c4 for src/notes/notes.c
- Timestamp:
- Jul 1, 2016, 3:26:59 PM (8 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:
- ba303e8
- Parents:
- f264b17
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/notes/notes.c
rf264b17 r4b9443c4 38 38 39 39 aubio_pitch_t *pitch; 40 fvec_t *pitch_output; 41 smpl_t pitch_tolerance; 42 40 43 aubio_onset_t *onset; 41 44 fvec_t *onset_output; 42 fvec_t *pitch_output;45 smpl_t onset_threshold; 43 46 44 47 smpl_t curnote; 45 48 smpl_t newnote; 49 50 smpl_t silence_threshold; 51 52 uint_t isready; 46 53 }; 47 54 48 aubio_notes_t * new_aubio_notes (c har_t * notes_method,55 aubio_notes_t * new_aubio_notes (const char_t * notes_method, 49 56 uint_t buf_size, uint_t hop_size, uint_t samplerate) { 50 57 aubio_notes_t *o = AUBIO_NEW(aubio_notes_t); 58 59 const char_t * onset_method = "default"; 60 const char_t * pitch_method = "default"; 51 61 52 62 o->onset_buf_size = buf_size; … … 54 64 o->hop_size = hop_size; 55 65 66 o->onset_threshold = 0.; 67 o->pitch_tolerance = 0.; 68 56 69 o->samplerate = samplerate; 57 70 58 o->median = 9; 71 o->median = 6; 72 73 o->isready = 0; 74 75 o->onset = new_aubio_onset (onset_method, o->onset_buf_size, o->hop_size, o->samplerate); 76 if (o->onset_threshold != 0.) aubio_onset_set_threshold (o->onset, o->onset_threshold); 77 o->onset_output = new_fvec (1); 78 79 o->pitch = new_aubio_pitch (pitch_method, o->pitch_buf_size, o->hop_size, o->samplerate); 80 if (o->pitch_tolerance != 0.) aubio_pitch_set_tolerance (o->pitch, o->pitch_tolerance); 81 o->pitch_output = new_fvec (1); 59 82 60 83 if (strcmp(notes_method, "default") != 0) { … … 67 90 68 91 o->curnote = -1.; 69 o->newnote = -1.; 92 o->newnote = 0.; 93 94 o->silence_threshold = -90.; 70 95 71 96 return o; … … 76 101 } 77 102 103 /** append new note candidate to the note_buffer and return filtered value. we 104 * need to copy the input array as fvec_median destroy its input data.*/ 105 static void 106 note_append (fvec_t * note_buffer, smpl_t curnote) 107 { 108 uint_t i = 0; 109 for (i = 0; i < note_buffer->length - 1; i++) { 110 note_buffer->data[i] = note_buffer->data[i + 1]; 111 } 112 note_buffer->data[note_buffer->length - 1] = curnote; 113 return; 114 } 115 116 static uint_t 117 aubio_notes_get_latest_note (aubio_notes_t *o) 118 { 119 uint_t i; 120 for (i = 0; i < o->note_buffer->length; i++) { 121 o->note_buffer2->data[i] = o->note_buffer->data[i]; 122 } 123 return fvec_median (o->note_buffer2); 124 } 125 126 127 void aubio_notes_do (aubio_notes_t *o, const fvec_t * input, fvec_t * notes) 128 { 129 smpl_t new_pitch, curlevel; 130 fvec_zeros(notes); 131 aubio_onset_do(o->onset, input, o->onset_output); 132 133 aubio_pitch_do (o->pitch, input, o->pitch_output); 134 new_pitch = o->pitch_output->data[0]; 135 if(o->median){ 136 note_append(o->note_buffer, new_pitch); 137 } 138 139 /* curlevel is negatif or 1 if silence */ 140 curlevel = aubio_level_detection(input, o->silence_threshold); 141 if (o->onset_output->data[0] != 0) { 142 /* test for silence */ 143 if (curlevel == 1.) { 144 if (o->median) o->isready = 0; 145 /* send note off */ 146 //send_noteon(o->curnote,0); 147 //notes->data[0] = o->curnote; 148 //notes->data[1] = 0.; 149 notes->data[2] = o->curnote; 150 } else { 151 if (o->median) { 152 o->isready = 1; 153 } else { 154 /* kill old note */ 155 //send_noteon(o->curnote,0, o->samplerate); 156 notes->data[2] = o->curnote; 157 /* get and send new one */ 158 //send_noteon(new_pitch,127+(int)floor(curlevel), o->samplerate); 159 notes->data[0] = new_pitch; 160 notes->data[1] = 127 + (int)floor(curlevel); 161 o->curnote = new_pitch; 162 } 163 } 164 } else { 165 if (o->median) { 166 if (o->isready > 0) 167 o->isready++; 168 if (o->isready == o->median) 169 { 170 /* kill old note */ 171 //send_noteon(curnote,0); 172 notes->data[2] = o->curnote; 173 notes->data[3] = 0; 174 o->newnote = aubio_notes_get_latest_note(o); 175 o->curnote = o->newnote; 176 /* get and send new one */ 177 if (o->curnote>45){ 178 //send_noteon(curnote,127+(int)floor(curlevel)); 179 notes->data[0] = o->curnote; 180 notes->data[1] = 127 + (int) floor(curlevel); 181 } 182 } 183 } // if median 184 } 185 } 186 78 187 void del_aubio_notes (aubio_notes_t *o) { 79 188 if (o->note_buffer) del_fvec(o->note_buffer); 80 189 if (o->note_buffer2) del_fvec(o->note_buffer2); 190 if (o->pitch_output) del_fvec(o->pitch_output); 191 if (o->pitch) del_aubio_pitch(o->pitch); 192 if (o->onset_output) del_fvec(o->onset_output); 193 if (o->onset) del_aubio_onset(o->onset); 81 194 AUBIO_FREE(o); 82 195 }
Note: See TracChangeset
for help on using the changeset viewer.