Mercurial > hg > nnls-chroma
comparison NNLSBase.cpp @ 42:d01f94d58ef0 matthiasm-plugin
* added new parameter that toggles NNLS
author | matthiasm |
---|---|
date | Sun, 24 Oct 2010 20:43:11 +0900 |
parents | d6bb9b43ac1c |
children | 6e76c7710fa1 |
comparison
equal
deleted
inserted
replaced
41:d6bb9b43ac1c | 42:d01f94d58ef0 |
---|---|
48 m_kernelValue(0), | 48 m_kernelValue(0), |
49 m_kernelFftIndex(0), | 49 m_kernelFftIndex(0), |
50 m_kernelNoteIndex(0), | 50 m_kernelNoteIndex(0), |
51 m_dict(0), | 51 m_dict(0), |
52 m_tuneLocal(false), | 52 m_tuneLocal(false), |
53 m_dictID(0), | |
54 m_chorddict(0), | 53 m_chorddict(0), |
55 m_chordnames(0), | 54 m_chordnames(0), |
56 m_doNormalizeChroma(0), | 55 m_doNormalizeChroma(0), |
57 m_rollon(0.0), | 56 m_rollon(0.0), |
58 m_s(0.7) | 57 m_s(0.7), |
58 m_useNNLS(1) | |
59 { | 59 { |
60 if (debug_on) cerr << "--> NNLSBase" << endl; | 60 if (debug_on) cerr << "--> NNLSBase" << endl; |
61 | 61 |
62 // make the *note* dictionary matrix | 62 // make the *note* dictionary matrix |
63 m_dict = new float[nNote * 84]; | 63 m_dict = new float[nNote * 84]; |
143 NNLSBase::ParameterList | 143 NNLSBase::ParameterList |
144 NNLSBase::getParameterDescriptors() const | 144 NNLSBase::getParameterDescriptors() const |
145 { | 145 { |
146 if (debug_on) cerr << "--> getParameterDescriptors" << endl; | 146 if (debug_on) cerr << "--> getParameterDescriptors" << endl; |
147 ParameterList list; | 147 ParameterList list; |
148 | |
149 ParameterDescriptor d; | |
150 d.identifier = "useNNLS"; | |
151 d.name = "use approximate transcription (NNLS)"; | |
152 d.description = "Toggles approximate transcription (NNLS)."; | |
153 d.unit = ""; | |
154 d.minValue = 0.0; | |
155 d.maxValue = 1.0; | |
156 d.defaultValue = 1.0; | |
157 d.isQuantized = true; | |
158 d.quantizeStep = 1.0; | |
159 list.push_back(d); | |
148 | 160 |
149 ParameterDescriptor d0; | 161 ParameterDescriptor d0; |
150 d0.identifier = "rollon"; | 162 d0.identifier = "rollon"; |
151 d0.name = "spectral roll-on"; | 163 d0.name = "spectral roll-on"; |
152 d0.description = "The bins below the spectral roll-on quantile will be set to 0."; | 164 d0.description = "The bins below the spectral roll-on quantile will be set to 0."; |
215 | 227 |
216 float | 228 float |
217 NNLSBase::getParameter(string identifier) const | 229 NNLSBase::getParameter(string identifier) const |
218 { | 230 { |
219 if (debug_on) cerr << "--> getParameter" << endl; | 231 if (debug_on) cerr << "--> getParameter" << endl; |
220 if (identifier == "notedict") { | 232 if (identifier == "useNNLS") { |
221 return m_dictID; | 233 return m_useNNLS; |
222 } | 234 } |
223 | 235 |
224 if (identifier == "whitening") { | 236 if (identifier == "whitening") { |
225 return m_whitening; | 237 return m_whitening; |
226 } | 238 } |
252 | 264 |
253 void | 265 void |
254 NNLSBase::setParameter(string identifier, float value) | 266 NNLSBase::setParameter(string identifier, float value) |
255 { | 267 { |
256 if (debug_on) cerr << "--> setParameter" << endl; | 268 if (debug_on) cerr << "--> setParameter" << endl; |
257 if (identifier == "notedict") { | 269 if (identifier == "useNNLS") { |
258 m_dictID = (int) value; | 270 m_useNNLS = (int) value; |
259 } | 271 } |
260 | 272 |
261 if (identifier == "whitening") { | 273 if (identifier == "whitening") { |
262 m_whitening = value; | 274 m_whitening = value; |
263 } | 275 } |
268 | 280 |
269 if (identifier == "tuningmode") { | 281 if (identifier == "tuningmode") { |
270 m_tuneLocal = (value > 0) ? true : false; | 282 m_tuneLocal = (value > 0) ? true : false; |
271 // cerr << "m_tuneLocal :" << m_tuneLocal << endl; | 283 // cerr << "m_tuneLocal :" << m_tuneLocal << endl; |
272 } | 284 } |
273 if (identifier == "preset") { | 285 // if (identifier == "preset") { |
274 m_preset = value; | 286 // m_preset = value; |
275 if (m_preset == 0.0) { | 287 // if (m_preset == 0.0) { |
276 m_tuneLocal = false; | 288 // m_tuneLocal = false; |
277 m_whitening = 1.0; | 289 // m_whitening = 1.0; |
278 m_dictID = 0.0; | 290 // m_dictID = 0.0; |
279 } | 291 // } |
280 if (m_preset == 1.0) { | 292 // if (m_preset == 1.0) { |
281 m_tuneLocal = false; | 293 // m_tuneLocal = false; |
282 m_whitening = 1.0; | 294 // m_whitening = 1.0; |
283 m_dictID = 1.0; | 295 // m_dictID = 1.0; |
284 } | 296 // } |
285 if (m_preset == 2.0) { | 297 // if (m_preset == 2.0) { |
286 m_tuneLocal = false; | 298 // m_tuneLocal = false; |
287 m_whitening = 0.7; | 299 // m_whitening = 0.7; |
288 m_dictID = 0.0; | 300 // m_dictID = 0.0; |
289 } | 301 // } |
290 } | 302 // } |
291 if (identifier == "chromanormalize") { | 303 if (identifier == "chromanormalize") { |
292 m_doNormalizeChroma = value; | 304 m_doNormalizeChroma = value; |
293 } | 305 } |
294 | 306 |
295 if (identifier == "rollon") { | 307 if (identifier == "rollon") { |
377 { | 389 { |
378 if (debug_on) cerr << "--> reset"; | 390 if (debug_on) cerr << "--> reset"; |
379 | 391 |
380 // Clear buffers, reset stored values, etc | 392 // Clear buffers, reset stored values, etc |
381 m_frameCount = 0; | 393 m_frameCount = 0; |
382 m_dictID = 0; | 394 // m_dictID = 0; |
383 m_logSpectrum.clear(); | 395 m_logSpectrum.clear(); |
384 m_meanTuning0 = 0; | 396 m_meanTuning0 = 0; |
385 m_meanTuning1 = 0; | 397 m_meanTuning1 = 0; |
386 m_meanTuning2 = 0; | 398 m_meanTuning2 = 0; |
387 m_localTuning0 = 0; | 399 m_localTuning0 = 0; |
572 Semitone-spaced log-frequency spectrum derived from the tuned log-freq spectrum above. the spectrum | 584 Semitone-spaced log-frequency spectrum derived from the tuned log-freq spectrum above. the spectrum |
573 is inferred using a non-negative least squares algorithm. | 585 is inferred using a non-negative least squares algorithm. |
574 Three different kinds of chromagram are calculated, "treble", "bass", and "both" (which means | 586 Three different kinds of chromagram are calculated, "treble", "bass", and "both" (which means |
575 bass and treble stacked onto each other). | 587 bass and treble stacked onto each other). |
576 **/ | 588 **/ |
577 if (m_dictID == 1) { | 589 if (m_useNNLS == 0) { |
578 cerr << "[NNLS Chroma Plugin] Mapping to semitone spectrum and chroma ... "; | 590 cerr << "[NNLS Chroma Plugin] Mapping to semitone spectrum and chroma ... "; |
579 } else { | 591 } else { |
580 cerr << "[NNLS Chroma Plugin] Performing NNLS and mapping to chroma ... "; | 592 cerr << "[NNLS Chroma Plugin] Performing NNLS and mapping to chroma ... "; |
581 } | 593 } |
582 | 594 |
626 vector<float> basschroma = vector<float>(12, 0); | 638 vector<float> basschroma = vector<float>(12, 0); |
627 float currval; | 639 float currval; |
628 unsigned iSemitone = 0; | 640 unsigned iSemitone = 0; |
629 | 641 |
630 if (some_b_greater_zero) { | 642 if (some_b_greater_zero) { |
631 if (m_dictID == 1) { | 643 if (m_useNNLS == 0) { |
632 for (unsigned iNote = 2; iNote < nNote - 2; iNote += 3) { | 644 for (unsigned iNote = 2; iNote < nNote - 2; iNote += 3) { |
633 currval = 0; | 645 currval = 0; |
634 currval += b[iNote + 1 + -1] * 0.5; | 646 currval += b[iNote + 1 + -1] * 0.5; |
635 currval += b[iNote + 1 + 0] * 1.0; | 647 currval += b[iNote + 1 + 0] * 1.0; |
636 currval += b[iNote + 1 + 1] * 0.5; | 648 currval += b[iNote + 1 + 1] * 0.5; |