Changeset 633400d for src/notes/notes.c
- Timestamp:
- Dec 5, 2018, 10:34:39 PM (5 years ago)
- Branches:
- feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- 283a619a
- Parents:
- 5b46bc3 (diff), f19db54 (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
-
src/notes/notes.c
r5b46bc3 r633400d 1 1 /* 2 Copyright (C) 2014 Paul Brossier <piem@aubio.org>2 Copyright (C) 2014-2018 Paul Brossier <piem@aubio.org> 3 3 4 4 This file is part of aubio. … … 25 25 #include "notes/notes.h" 26 26 27 #define AUBIO_DEFAULT_NOTES_SILENCE -70. 28 #define AUBIO_DEFAULT_NOTES_RELEASE_DROP 10. 29 // increase to 10. for .1 cent precision 30 // or to 100. for .01 cent precision 31 #define AUBIO_DEFAULT_CENT_PRECISION 1. 32 #define AUBIO_DEFAULT_NOTES_MINIOI_MS 30. 33 27 34 struct _aubio_notes_t { 28 35 … … 51 58 52 59 uint_t isready; 60 61 smpl_t last_onset_level; 62 smpl_t release_drop_level; 53 63 }; 54 64 … … 74 84 75 85 o->onset = new_aubio_onset (onset_method, o->onset_buf_size, o->hop_size, o->samplerate); 86 if (o->onset == NULL) goto fail; 76 87 if (o->onset_threshold != 0.) aubio_onset_set_threshold (o->onset, o->onset_threshold); 77 88 o->onset_output = new_fvec (1); 78 89 79 90 o->pitch = new_aubio_pitch (pitch_method, o->pitch_buf_size, o->hop_size, o->samplerate); 91 if (o->pitch == NULL) goto fail; 80 92 if (o->pitch_tolerance != 0.) aubio_pitch_set_tolerance (o->pitch, o->pitch_tolerance); 93 aubio_pitch_set_unit (o->pitch, "midi"); 81 94 o->pitch_output = new_fvec (1); 82 95 … … 88 101 o->note_buffer2 = new_fvec(o->median); 89 102 103 if (!o->onset_output || !o->pitch_output || 104 !o->note_buffer || !o->note_buffer2) goto fail; 105 90 106 o->curnote = -1.; 91 107 o->newnote = 0.; 92 108 93 o->silence_threshold = -90.; 109 aubio_notes_set_silence(o, AUBIO_DEFAULT_NOTES_SILENCE); 110 aubio_notes_set_minioi_ms (o, AUBIO_DEFAULT_NOTES_MINIOI_MS); 111 112 o->last_onset_level = AUBIO_DEFAULT_NOTES_SILENCE; 113 o->release_drop_level = AUBIO_DEFAULT_NOTES_RELEASE_DROP; 94 114 95 115 return o; … … 98 118 del_aubio_notes(o); 99 119 return NULL; 120 } 121 122 uint_t aubio_notes_set_silence(aubio_notes_t *o, smpl_t silence) 123 { 124 uint_t err = AUBIO_OK; 125 if (aubio_pitch_set_silence(o->pitch, silence) != AUBIO_OK) { 126 err = AUBIO_FAIL; 127 } 128 if (aubio_onset_set_silence(o->onset, silence) != AUBIO_OK) { 129 err = AUBIO_FAIL; 130 } 131 o->silence_threshold = silence; 132 return err; 133 } 134 135 smpl_t aubio_notes_get_silence(const aubio_notes_t *o) 136 { 137 return aubio_pitch_get_silence(o->pitch); 138 } 139 140 uint_t aubio_notes_set_minioi_ms (aubio_notes_t *o, smpl_t minioi_ms) 141 { 142 uint_t err = AUBIO_OK; 143 if (!o->onset || (aubio_onset_set_minioi_ms(o->onset, minioi_ms) != 0)) { 144 err = AUBIO_FAIL; 145 } 146 return err; 147 } 148 149 smpl_t aubio_notes_get_minioi_ms(const aubio_notes_t *o) 150 { 151 return aubio_onset_get_minioi_ms(o->onset); 152 } 153 154 uint_t aubio_notes_set_release_drop(aubio_notes_t *o, smpl_t release_drop_level) 155 { 156 uint_t err = AUBIO_OK; 157 if (release_drop_level <= 0.) { 158 AUBIO_ERR("notes: release_drop should be >= 0, got %f\n", release_drop_level); 159 err = AUBIO_FAIL; 160 } else { 161 o->release_drop_level = release_drop_level; 162 } 163 return err; 164 } 165 166 smpl_t aubio_notes_get_release_drop(const aubio_notes_t *o) 167 { 168 return o->release_drop_level; 100 169 } 101 170 … … 109 178 note_buffer->data[i] = note_buffer->data[i + 1]; 110 179 } 111 note_buffer->data[note_buffer->length - 1] = curnote; 180 //note_buffer->data[note_buffer->length - 1] = ROUND(10.*curnote)/10.; 181 note_buffer->data[note_buffer->length - 1] = ROUND(AUBIO_DEFAULT_CENT_PRECISION*curnote); 112 182 return; 113 183 } 114 184 115 static uint_t185 static smpl_t 116 186 aubio_notes_get_latest_note (aubio_notes_t *o) 117 187 { 118 uint_t i; 119 for (i = 0; i < o->note_buffer->length; i++) { 120 o->note_buffer2->data[i] = o->note_buffer->data[i]; 121 } 122 return fvec_median (o->note_buffer2); 188 fvec_copy(o->note_buffer, o->note_buffer2); 189 return fvec_median (o->note_buffer2) / AUBIO_DEFAULT_CENT_PRECISION; 123 190 } 124 191 … … 146 213 //notes->data[0] = o->curnote; 147 214 //notes->data[1] = 0.; 215 //AUBIO_WRN("notes: sending note-off at onset, not enough level\n"); 148 216 notes->data[2] = o->curnote; 149 217 } else { … … 153 221 /* kill old note */ 154 222 //send_noteon(o->curnote,0, o->samplerate); 223 //AUBIO_WRN("notes: sending note-off at onset, new onset detected\n"); 155 224 notes->data[2] = o->curnote; 156 225 /* get and send new one */ … … 160 229 o->curnote = new_pitch; 161 230 } 231 o->last_onset_level = curlevel; 162 232 } 163 233 } else { 164 if (o->median) { 234 if (curlevel < o->last_onset_level - o->release_drop_level) 235 { 236 // send note off 237 //AUBIO_WRN("notes: sending note-off, release detected\n"); 238 notes->data[0] = 0; 239 notes->data[1] = 0; 240 notes->data[2] = o->curnote; 241 // reset last_onset_level to silence_threshold 242 o->last_onset_level = o->silence_threshold; 243 o->curnote = 0; 244 } 245 else if (o->median) 246 { 165 247 if (o->isready > 0) 166 248 o->isready++; … … 169 251 /* kill old note */ 170 252 //send_noteon(curnote,0); 171 notes->data[2] = o->curnote; 253 if (o->curnote != 0) 254 { 255 //AUBIO_WRN("notes: sending note-off, new note detected\n"); 256 notes->data[2] = o->curnote; 257 } 172 258 o->newnote = aubio_notes_get_latest_note(o); 173 259 o->curnote = o->newnote;
Note: See TracChangeset
for help on using the changeset viewer.