Mercurial > hg > vamp-aubio-plugins
comparison plugins/Notes.cpp @ 34:0f40399ca1ff
Get Onset and Notes to build against new aubio
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 10 Jul 2012 15:21:35 +0100 |
parents | 8a20f3488d88 |
children | bcb23bb4b7aa |
comparison
equal
deleted
inserted
replaced
33:a2301c902711 | 34:0f40399ca1ff |
---|---|
25 using std::endl; | 25 using std::endl; |
26 | 26 |
27 Notes::Notes(float inputSampleRate) : | 27 Notes::Notes(float inputSampleRate) : |
28 Plugin(inputSampleRate), | 28 Plugin(inputSampleRate), |
29 m_ibuf(0), | 29 m_ibuf(0), |
30 m_fftgrain(0), | |
31 m_onset(0), | 30 m_onset(0), |
32 m_pv(0), | 31 m_pitch(0), |
33 m_peakpick(0), | |
34 m_onsetdet(0), | 32 m_onsetdet(0), |
35 m_onsettype(OnsetComplex), | 33 m_onsettype(OnsetComplex), |
36 m_pitchdet(0), | 34 m_pitchdet(0), |
37 m_pitchtype(PitchYinFFT), | 35 m_pitchtype(PitchYinFFT), |
38 m_threshold(0.3), | 36 m_threshold(0.3), |
39 m_silence(-90), | 37 m_silence(-70), |
38 m_minioi(4), | |
40 m_median(6), | 39 m_median(6), |
41 m_minpitch(27), | 40 m_minpitch(27), |
42 m_maxpitch(95), | 41 m_maxpitch(95), |
43 m_wrapRange(false), | 42 m_wrapRange(false), |
44 m_avoidLeaps(false), | 43 m_avoidLeaps(false), |
50 { | 49 { |
51 if (m_onsetdet) del_aubio_onset(m_onsetdet); | 50 if (m_onsetdet) del_aubio_onset(m_onsetdet); |
52 if (m_pitchdet) del_aubio_pitch(m_pitchdet); | 51 if (m_pitchdet) del_aubio_pitch(m_pitchdet); |
53 if (m_ibuf) del_fvec(m_ibuf); | 52 if (m_ibuf) del_fvec(m_ibuf); |
54 if (m_onset) del_fvec(m_onset); | 53 if (m_onset) del_fvec(m_onset); |
55 if (m_fftgrain) del_cvec(m_fftgrain); | 54 if (m_pitch) del_fvec(m_pitch); |
56 if (m_pv) del_aubio_pvoc(m_pv); | |
57 if (m_peakpick) del_aubio_peakpicker(m_peakpick); | |
58 } | 55 } |
59 | 56 |
60 string | 57 string |
61 Notes::getIdentifier() const | 58 Notes::getIdentifier() const |
62 { | 59 { |
102 } | 99 } |
103 | 100 |
104 m_stepSize = stepSize; | 101 m_stepSize = stepSize; |
105 m_blockSize = blockSize; | 102 m_blockSize = blockSize; |
106 | 103 |
107 size_t processingBlockSize; | |
108 if (m_onsettype == OnsetEnergy || | |
109 m_onsettype == OnsetHFC) { | |
110 processingBlockSize = stepSize * 2; | |
111 } else { | |
112 processingBlockSize = stepSize * 4; | |
113 } | |
114 | |
115 m_ibuf = new_fvec(stepSize); | 104 m_ibuf = new_fvec(stepSize); |
116 m_onset = new_fvec(1); | 105 m_onset = new_fvec(1); |
117 m_fftgrain = new_cvec(processingBlockSize); | 106 m_pitch = new_fvec(1); |
118 m_pv = new_aubio_pvoc(processingBlockSize, stepSize); | 107 |
119 m_peakpick = new_aubio_peakpicker(m_threshold); | 108 m_onsetdet = new_aubio_onset |
120 | 109 (const_cast<char *>(getAubioNameForOnsetType(m_onsettype)), |
121 m_onsetdet = new_aubio_onsetdetection(m_onsettype, processingBlockSize); | 110 blockSize, |
122 | 111 stepSize, |
123 m_pitchdet = new_aubio_pitchdetection(processingBlockSize * 4, | 112 lrintf(m_inputSampleRate)); |
124 stepSize, | 113 |
125 lrintf(m_inputSampleRate), | 114 aubio_onset_set_threshold(m_onsetdet, m_threshold); |
126 m_pitchtype, | 115 aubio_onset_set_silence(m_onsetdet, m_silence); |
127 m_pitchmode); | 116 aubio_onset_set_minioi(m_onsetdet, m_minioi); |
117 | |
118 m_pitchdet = new_aubio_pitch | |
119 (const_cast<char *>(getAubioNameForPitchType(m_pitchtype)), | |
120 blockSize, | |
121 stepSize, | |
122 lrintf(m_inputSampleRate)); | |
123 | |
124 aubio_pitch_set_unit(m_pitchdet, "freq"); | |
128 | 125 |
129 m_count = 0; | 126 m_count = 0; |
130 m_delay = Vamp::RealTime::frame2RealTime((4 + m_median) * m_stepSize, | 127 m_delay = Vamp::RealTime::frame2RealTime((4 + m_median) * m_stepSize, |
131 lrintf(m_inputSampleRate)); | 128 lrintf(m_inputSampleRate)); |
132 m_currentOnset = Vamp::RealTime::zeroTime; | 129 m_currentOnset = Vamp::RealTime::zeroTime; |
160 | 157 |
161 ParameterDescriptor desc; | 158 ParameterDescriptor desc; |
162 desc.identifier = "onsettype"; | 159 desc.identifier = "onsettype"; |
163 desc.name = "Onset Detection Function Type"; | 160 desc.name = "Onset Detection Function Type"; |
164 desc.minValue = 0; | 161 desc.minValue = 0; |
165 desc.maxValue = 6; | 162 desc.maxValue = 7; |
166 desc.defaultValue = (int)aubio_onset_complex; | 163 desc.defaultValue = (int)OnsetComplex; |
167 desc.isQuantized = true; | 164 desc.isQuantized = true; |
168 desc.quantizeStep = 1; | 165 desc.quantizeStep = 1; |
169 desc.valueNames.push_back("Energy Based"); | 166 desc.valueNames.push_back("Energy Based"); |
170 desc.valueNames.push_back("Spectral Difference"); | 167 desc.valueNames.push_back("Spectral Difference"); |
171 desc.valueNames.push_back("High-Frequency Content"); | 168 desc.valueNames.push_back("High-Frequency Content"); |
172 desc.valueNames.push_back("Complex Domain"); | 169 desc.valueNames.push_back("Complex Domain"); |
173 desc.valueNames.push_back("Phase Deviation"); | 170 desc.valueNames.push_back("Phase Deviation"); |
174 desc.valueNames.push_back("Kullback-Liebler"); | 171 desc.valueNames.push_back("Kullback-Liebler"); |
175 desc.valueNames.push_back("Modified Kullback-Liebler"); | 172 desc.valueNames.push_back("Modified Kullback-Liebler"); |
173 desc.valueNames.push_back("Spectral Flux"); | |
176 list.push_back(desc); | 174 list.push_back(desc); |
177 | 175 |
178 desc = ParameterDescriptor(); | 176 desc = ParameterDescriptor(); |
179 desc.identifier = "pitchtype"; | 177 desc.identifier = "pitchtype"; |
180 desc.name = "Pitch Detection Function Type"; | 178 desc.name = "Pitch Detection Function Type"; |
181 desc.minValue = 0; | 179 desc.minValue = 0; |
182 desc.maxValue = 4; | 180 desc.maxValue = 4; |
183 desc.defaultValue = (int)aubio_pitch_yinfft; | 181 desc.defaultValue = (int)PitchYinFFT; |
184 desc.isQuantized = true; | 182 desc.isQuantized = true; |
185 desc.quantizeStep = 1; | 183 desc.quantizeStep = 1; |
186 desc.valueNames.push_back("YIN Frequency Estimator"); | 184 desc.valueNames.push_back("YIN Frequency Estimator"); |
187 desc.valueNames.push_back("Spectral Comb"); | 185 desc.valueNames.push_back("Spectral Comb"); |
188 desc.valueNames.push_back("Schmitt"); | 186 desc.valueNames.push_back("Schmitt"); |
244 desc = ParameterDescriptor(); | 242 desc = ParameterDescriptor(); |
245 desc.identifier = "silencethreshold"; | 243 desc.identifier = "silencethreshold"; |
246 desc.name = "Silence Threshold"; | 244 desc.name = "Silence Threshold"; |
247 desc.minValue = -120; | 245 desc.minValue = -120; |
248 desc.maxValue = 0; | 246 desc.maxValue = 0; |
249 desc.defaultValue = -90; | 247 desc.defaultValue = -70; |
250 desc.unit = "dB"; | 248 desc.unit = "dB"; |
251 desc.isQuantized = false; | 249 desc.isQuantized = false; |
250 list.push_back(desc); | |
251 | |
252 desc = ParameterDescriptor(); | |
253 desc.identifier = "minioi"; | |
254 desc.name = "Minimum Inter-Onset Interval"; | |
255 desc.minValue = 0; | |
256 desc.maxValue = 40; | |
257 desc.defaultValue = 4; | |
258 desc.unit = "ms"; | |
259 desc.isQuantized = true; | |
260 desc.quantizeStep = 1; | |
252 list.push_back(desc); | 261 list.push_back(desc); |
253 | 262 |
254 return list; | 263 return list; |
255 } | 264 } |
256 | 265 |
271 return m_maxpitch; | 280 return m_maxpitch; |
272 } else if (param == "wraprange") { | 281 } else if (param == "wraprange") { |
273 return m_wrapRange ? 1.0 : 0.0; | 282 return m_wrapRange ? 1.0 : 0.0; |
274 } else if (param == "avoidleaps") { | 283 } else if (param == "avoidleaps") { |
275 return m_avoidLeaps ? 1.0 : 0.0; | 284 return m_avoidLeaps ? 1.0 : 0.0; |
285 } else if (param == "minioi") { | |
286 return m_minioi; | |
276 } else { | 287 } else { |
277 return 0.0; | 288 return 0.0; |
278 } | 289 } |
279 } | 290 } |
280 | 291 |
281 void | 292 void |
282 Notes::setParameter(std::string param, float value) | 293 Notes::setParameter(std::string param, float value) |
283 { | 294 { |
284 if (param == "onsettype") { | 295 if (param == "onsettype") { |
285 switch (lrintf(value)) { | 296 switch (lrintf(value)) { |
286 case 0: m_onsettype = aubio_onset_energy; break; | 297 case 0: m_onsettype = OnsetEnergy; break; |
287 case 1: m_onsettype = aubio_onset_specdiff; break; | 298 case 1: m_onsettype = OnsetSpecDiff; break; |
288 case 2: m_onsettype = aubio_onset_hfc; break; | 299 case 2: m_onsettype = OnsetHFC; break; |
289 case 3: m_onsettype = aubio_onset_complex; break; | 300 case 3: m_onsettype = OnsetComplex; break; |
290 case 4: m_onsettype = aubio_onset_phase; break; | 301 case 4: m_onsettype = OnsetPhase; break; |
291 case 5: m_onsettype = aubio_onset_kl; break; | 302 case 5: m_onsettype = OnsetKL; break; |
292 case 6: m_onsettype = aubio_onset_mkl; break; | 303 case 6: m_onsettype = OnsetMKL; break; |
304 case 7: m_onsettype = OnsetSpecFlux; break; | |
293 } | 305 } |
294 } else if (param == "pitchtype") { | 306 } else if (param == "pitchtype") { |
295 switch (lrintf(value)) { | 307 switch (lrintf(value)) { |
296 case 0: m_pitchtype = aubio_pitch_yin; break; | 308 case 0: m_pitchtype = PitchYin; break; |
297 case 1: m_pitchtype = aubio_pitch_mcomb; break; | 309 case 1: m_pitchtype = PitchMComb; break; |
298 case 2: m_pitchtype = aubio_pitch_schmitt; break; | 310 case 2: m_pitchtype = PitchSchmitt; break; |
299 case 3: m_pitchtype = aubio_pitch_fcomb; break; | 311 case 3: m_pitchtype = PitchFComb; break; |
300 case 4: m_pitchtype = aubio_pitch_yinfft; break; | 312 case 4: m_pitchtype = PitchYinFFT; break; |
301 } | 313 } |
302 } else if (param == "peakpickthreshold") { | 314 } else if (param == "peakpickthreshold") { |
303 m_threshold = value; | 315 m_threshold = value; |
304 } else if (param == "silencethreshold") { | 316 } else if (param == "silencethreshold") { |
305 m_silence = value; | 317 m_silence = value; |
309 m_maxpitch = lrintf(value); | 321 m_maxpitch = lrintf(value); |
310 } else if (param == "wraprange") { | 322 } else if (param == "wraprange") { |
311 m_wrapRange = (value > 0.5); | 323 m_wrapRange = (value > 0.5); |
312 } else if (param == "avoidleaps") { | 324 } else if (param == "avoidleaps") { |
313 m_avoidLeaps = (value > 0.5); | 325 m_avoidLeaps = (value > 0.5); |
326 } else if (param == "minioi") { | |
327 m_minioi = value; | |
314 } | 328 } |
315 } | 329 } |
316 | 330 |
317 Notes::OutputList | 331 Notes::OutputList |
318 Notes::getOutputDescriptors() const | 332 Notes::getOutputDescriptors() const |
341 | 355 |
342 Notes::FeatureSet | 356 Notes::FeatureSet |
343 Notes::process(const float *const *inputBuffers, Vamp::RealTime timestamp) | 357 Notes::process(const float *const *inputBuffers, Vamp::RealTime timestamp) |
344 { | 358 { |
345 for (size_t i = 0; i < m_stepSize; ++i) { | 359 for (size_t i = 0; i < m_stepSize; ++i) { |
346 for (size_t j = 0; j < m_channelCount; ++j) { | 360 fvec_write_sample(m_ibuf, inputBuffers[0][i], i); |
347 fvec_write_sample(m_ibuf, inputBuffers[j][i], j, i); | 361 } |
348 } | 362 |
349 } | 363 aubio_onset_do(m_onsetdet, m_ibuf, m_onset); |
350 | 364 aubio_pitch_do(m_pitchdet, m_ibuf, m_pitch); |
351 aubio_pvoc_do(m_pv, m_ibuf, m_fftgrain); | 365 |
352 aubio_onsetdetection(m_onsetdet, m_fftgrain, m_onset); | 366 bool isonset = m_onset->data[0]; |
353 | 367 float frequency = m_pitch->data[0]; |
354 bool isonset = aubio_peakpick_pimrt(m_onset, m_peakpick); | |
355 | |
356 float frequency = aubio_pitchdetection(m_pitchdet, m_ibuf); | |
357 | 368 |
358 m_notebuf.push_back(frequency); | 369 m_notebuf.push_back(frequency); |
359 if (m_notebuf.size() > m_median) m_notebuf.pop_front(); | 370 if (m_notebuf.size() > m_median) m_notebuf.pop_front(); |
360 | 371 |
361 float level = aubio_level_detection(m_ibuf, m_silence); | 372 float level = aubio_level_detection(m_ibuf, m_silence); |