Changeset 35f73b8c for src/onset/onset.c
- Timestamp:
- Mar 15, 2013, 11:48:10 PM (11 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:
- 7e9e311
- Parents:
- f5e0a54
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/onset/onset.c
rf5e0a54 r35f73b8c 39 39 uint_t minioi; /**< minimum inter onset interval */ 40 40 uint_t delay; /**< constant delay, in samples, removed from detected onset times */ 41 fvec_t * wasonset; /**< number of blocks since last onset */42 41 uint_t samplerate; /**< sampling rate of the input signal */ 43 42 uint_t hop_size; /**< number of samples between two runs */ … … 51 50 { 52 51 smpl_t isonset = 0; 53 smpl_t wasonset = 0;54 52 aubio_pvoc_do (o->pv,input, o->fftgrain); 55 53 aubio_specdesc_do (o->od,o->fftgrain, o->of); 56 54 aubio_peakpicker_do(o->pp, o->of, onset); 57 55 isonset = onset->data[0]; 58 wasonset = o->wasonset->data[0];59 56 if (isonset > 0.) { 60 57 if (aubio_silence_detection(input, o->silence)==1) { 61 58 isonset = 0; 62 wasonset++;63 59 } else { 64 if (wasonset > o->minioi) {65 wasonset = 0;66 o->last_onset = o->total_frames + isonset * o->hop_size;60 uint_t new_onset = o->total_frames + isonset * o->hop_size; 61 if (o->last_onset + o->minioi < new_onset) { 62 o->last_onset = new_onset; 67 63 } else { 68 64 isonset = 0; 69 wasonset++;70 65 } 71 66 } 72 67 } else { 73 if (wasonset == -1 && aubio_silence_detection(input, o->silence) == 0) {74 //AUBIO_MSG("beginning of file is not silent, marking as onset\n",75 // wasonset, aubio_silence_detection(input, o->silence));68 // we are at the beginning of the file, and we don't find silence 69 if (o->total_frames == 0 && aubio_silence_detection(input, o->silence) == 0) { 70 //AUBIO_DBG ("beginning of file is not silent, marking as onset\n"); 76 71 isonset = o->delay / o->hop_size; 77 72 o->last_onset = o->delay; 78 wasonset = 0;79 73 } 80 wasonset++;81 74 } 82 o->wasonset->data[0] = wasonset;83 //onset->data[0] = isonset * o->hop_size - o->delay;84 75 onset->data[0] = isonset; 85 // also keep a copy of the offset for use in get_last_onset86 76 o->total_frames += o->hop_size; 87 77 return; … … 103 93 } 104 94 105 smpl_t aubio_onset_get_descriptor(aubio_onset_t * o) {106 return o->of->data[0];107 }108 109 smpl_t aubio_onset_get_thresholded_descriptor(aubio_onset_t * o) {110 fvec_t * thresholded = aubio_peakpicker_get_thresholded_input(o->pp);111 return thresholded->data[0];112 }113 114 95 uint_t aubio_onset_set_silence(aubio_onset_t * o, smpl_t silence) { 115 96 o->silence = silence; … … 124 105 125 106 uint_t aubio_onset_set_minioi(aubio_onset_t * o, uint_t minioi) { 126 o->minioi = FLOOR(minioi / 1000. * o->samplerate / o->hop_size);107 o->minioi = minioi; 127 108 return AUBIO_OK; 128 109 } … … 130 111 uint_t aubio_onset_get_minioi(aubio_onset_t * o) { 131 112 return o->minioi; 113 } 114 115 uint_t aubio_onset_set_minioi_s(aubio_onset_t * o, smpl_t minioi) { 116 return aubio_onset_set_minioi (o, minioi * o->samplerate); 117 } 118 119 smpl_t aubio_onset_get_minioi_s(aubio_onset_t * o) { 120 return aubio_onset_get_minioi (o) / (smpl_t) o->samplerate; 121 } 122 123 uint_t aubio_onset_set_minioi_ms(aubio_onset_t * o, smpl_t minioi) { 124 return aubio_onset_set_minioi_s (o, minioi / 1000.); 125 } 126 127 smpl_t aubio_onset_get_minioi_ms(aubio_onset_t * o) { 128 return aubio_onset_get_minioi_s (o) * 1000.; 132 129 } 133 130 … … 157 154 } 158 155 156 smpl_t aubio_onset_get_descriptor(aubio_onset_t * o) { 157 return o->of->data[0]; 158 } 159 160 smpl_t aubio_onset_get_thresholded_descriptor(aubio_onset_t * o) { 161 fvec_t * thresholded = aubio_peakpicker_get_thresholded_input(o->pp); 162 return thresholded->data[0]; 163 } 164 159 165 /* Allocate memory for an onset detection */ 160 166 aubio_onset_t * new_aubio_onset (char_t * onset_mode, … … 163 169 aubio_onset_t * o = AUBIO_NEW(aubio_onset_t); 164 170 /** set some default parameter */ 171 o->samplerate = samplerate; 172 o->hop_size = hop_size; 165 173 o->last_onset = 0; 166 174 o->threshold = 0.3; 167 175 o->delay = 4.3 * hop_size; 168 o->minioi = 5 ;176 o->minioi = 5 * hop_size; 169 177 o->silence = -70; 170 o->wasonset = new_fvec(1);171 o->wasonset->data[0] = -1.;172 178 o->total_frames = 0; 173 o->samplerate = samplerate; 174 o->hop_size = hop_size; 175 o->pv = new_aubio_pvoc(buf_size, hop_size); 179 o->pv = new_aubio_pvoc(buf_size, o->hop_size); 176 180 o->pp = new_aubio_peakpicker(); 177 181 aubio_peakpicker_set_threshold (o->pp, o->threshold); … … 179 183 o->fftgrain = new_cvec(buf_size); 180 184 o->of = new_fvec(1); 181 /*if (usedoubled) {182 o2 = new_aubio_specdesc(onset_type2,buffer_size);183 onset2 = new_fvec(1);184 }*/185 185 return o; 186 186 } … … 192 192 del_aubio_pvoc(o->pv); 193 193 del_fvec(o->of); 194 del_fvec(o->wasonset);195 194 del_cvec(o->fftgrain); 196 195 AUBIO_FREE(o);
Note: See TracChangeset
for help on using the changeset viewer.