annotate NNLSBase.cpp @ 91:b56dde3417d4 matthiasm-plugin

* Fix the "comparison between signed and unsigned" warnings; remove some ifdef'd-out old code
author Chris Cannam
date Thu, 02 Dec 2010 13:05:23 +0000
parents 7af5312e66f8
children a76598852303
rev   line source
Chris@23 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
matthiasm@0 2
Chris@35 3 /*
Chris@35 4 NNLS-Chroma / Chordino
Chris@35 5
Chris@35 6 Audio feature extraction plugins for chromagram and chord
Chris@35 7 estimation.
Chris@35 8
Chris@35 9 Centre for Digital Music, Queen Mary University of London.
Chris@35 10 This file copyright 2008-2010 Matthias Mauch and QMUL.
Chris@35 11
Chris@35 12 This program is free software; you can redistribute it and/or
Chris@35 13 modify it under the terms of the GNU General Public License as
Chris@35 14 published by the Free Software Foundation; either version 2 of the
Chris@35 15 License, or (at your option) any later version. See the file
Chris@35 16 COPYING included with this distribution for more information.
Chris@35 17 */
Chris@35 18
Chris@35 19 #include "NNLSBase.h"
Chris@27 20
Chris@27 21 #include "chromamethods.h"
Chris@27 22
Chris@27 23 #include <cstdlib>
Chris@27 24 #include <fstream>
matthiasm@0 25 #include <cmath>
matthiasm@9 26
Chris@27 27 #include <algorithm>
matthiasm@0 28
matthiasm@0 29 const bool debug_on = false;
matthiasm@0 30
Chris@35 31 NNLSBase::NNLSBase(float inputSampleRate) :
Chris@23 32 Plugin(inputSampleRate),
mail@89 33 m_frameCount(0),
Chris@35 34 m_logSpectrum(0),
Chris@23 35 m_blockSize(0),
Chris@23 36 m_stepSize(0),
Chris@23 37 m_lengthOfNoteIndex(0),
mail@80 38 m_meanTunings(0),
mail@80 39 m_localTunings(0),
mail@41 40 m_whitening(1.0),
Chris@23 41 m_preset(0.0),
mail@89 42 m_useNNLS(1),
mail@89 43 m_useHMM(1),
Chris@23 44 m_localTuning(0),
Chris@23 45 m_kernelValue(0),
Chris@23 46 m_kernelFftIndex(0),
Chris@23 47 m_kernelNoteIndex(0),
Chris@23 48 m_dict(0),
mail@60 49 m_tuneLocal(0),
Chris@23 50 m_doNormalizeChroma(0),
mail@60 51 m_rollon(0),
mail@89 52 m_boostN(1.1),
matthiasm@42 53 m_s(0.7),
mail@80 54 sinvalues(0),
mail@80 55 cosvalues(0)
matthiasm@0 56 {
Chris@35 57 if (debug_on) cerr << "--> NNLSBase" << endl;
matthiasm@7 58
Chris@23 59 // make the *note* dictionary matrix
Chris@23 60 m_dict = new float[nNote * 84];
Chris@23 61 for (unsigned i = 0; i < nNote * 84; ++i) m_dict[i] = 0.0;
mail@41 62 dictionaryMatrix(m_dict, 0.7);
matthiasm@0 63 }
matthiasm@0 64
matthiasm@0 65
Chris@35 66 NNLSBase::~NNLSBase()
matthiasm@0 67 {
Chris@35 68 if (debug_on) cerr << "--> ~NNLSBase" << endl;
Chris@23 69 delete [] m_dict;
matthiasm@0 70 }
matthiasm@0 71
matthiasm@0 72 string
Chris@35 73 NNLSBase::getMaker() const
matthiasm@0 74 {
Chris@23 75 if (debug_on) cerr << "--> getMaker" << endl;
matthiasm@0 76 // Your name here
matthiasm@0 77 return "Matthias Mauch";
matthiasm@0 78 }
matthiasm@0 79
matthiasm@0 80 int
Chris@35 81 NNLSBase::getPluginVersion() const
matthiasm@0 82 {
Chris@23 83 if (debug_on) cerr << "--> getPluginVersion" << endl;
matthiasm@0 84 // Increment this each time you release a version that behaves
matthiasm@0 85 // differently from the previous one
matthiasm@0 86 return 1;
matthiasm@0 87 }
matthiasm@0 88
matthiasm@0 89 string
Chris@35 90 NNLSBase::getCopyright() const
matthiasm@0 91 {
Chris@23 92 if (debug_on) cerr << "--> getCopyright" << endl;
matthiasm@0 93 // This function is not ideally named. It does not necessarily
matthiasm@0 94 // need to say who made the plugin -- getMaker does that -- but it
matthiasm@0 95 // should indicate the terms under which it is distributed. For
matthiasm@0 96 // example, "Copyright (year). All Rights Reserved", or "GPL"
Chris@35 97 return "GPL";
matthiasm@0 98 }
matthiasm@0 99
Chris@35 100 NNLSBase::InputDomain
Chris@35 101 NNLSBase::getInputDomain() const
matthiasm@0 102 {
Chris@23 103 if (debug_on) cerr << "--> getInputDomain" << endl;
matthiasm@0 104 return FrequencyDomain;
matthiasm@0 105 }
matthiasm@0 106
matthiasm@0 107 size_t
Chris@35 108 NNLSBase::getPreferredBlockSize() const
matthiasm@0 109 {
Chris@23 110 if (debug_on) cerr << "--> getPreferredBlockSize" << endl;
matthiasm@0 111 return 16384; // 0 means "I can handle any block size"
matthiasm@0 112 }
matthiasm@0 113
matthiasm@0 114 size_t
Chris@35 115 NNLSBase::getPreferredStepSize() const
matthiasm@0 116 {
Chris@23 117 if (debug_on) cerr << "--> getPreferredStepSize" << endl;
matthiasm@0 118 return 2048; // 0 means "anything sensible"; in practice this
Chris@23 119 // means the same as the block size for TimeDomain
Chris@23 120 // plugins, or half of it for FrequencyDomain plugins
matthiasm@0 121 }
matthiasm@0 122
matthiasm@0 123 size_t
Chris@35 124 NNLSBase::getMinChannelCount() const
matthiasm@0 125 {
Chris@23 126 if (debug_on) cerr << "--> getMinChannelCount" << endl;
matthiasm@0 127 return 1;
matthiasm@0 128 }
matthiasm@0 129
matthiasm@0 130 size_t
Chris@35 131 NNLSBase::getMaxChannelCount() const
matthiasm@0 132 {
Chris@23 133 if (debug_on) cerr << "--> getMaxChannelCount" << endl;
matthiasm@0 134 return 1;
matthiasm@0 135 }
matthiasm@0 136
Chris@35 137 NNLSBase::ParameterList
Chris@35 138 NNLSBase::getParameterDescriptors() const
matthiasm@0 139 {
Chris@23 140 if (debug_on) cerr << "--> getParameterDescriptors" << endl;
matthiasm@0 141 ParameterList list;
matthiasm@0 142
matthiasm@42 143 ParameterDescriptor d;
matthiasm@42 144 d.identifier = "useNNLS";
matthiasm@42 145 d.name = "use approximate transcription (NNLS)";
matthiasm@42 146 d.description = "Toggles approximate transcription (NNLS).";
matthiasm@42 147 d.unit = "";
matthiasm@42 148 d.minValue = 0.0;
matthiasm@42 149 d.maxValue = 1.0;
matthiasm@42 150 d.defaultValue = 1.0;
matthiasm@42 151 d.isQuantized = true;
matthiasm@42 152 d.quantizeStep = 1.0;
matthiasm@42 153 list.push_back(d);
matthiasm@42 154
mail@41 155 ParameterDescriptor d0;
mail@41 156 d0.identifier = "rollon";
mail@41 157 d0.name = "spectral roll-on";
matthiasm@58 158 d0.description = "Consider the cumulative energy spectrum (from low to high frequencies). All bins below the first bin whose cumulative energy exceeds the quantile [spectral roll on] x [total energy] will be set to 0. A value of 0 means that no bins will be changed.";
matthiasm@59 159 d0.unit = "%";
mail@41 160 d0.minValue = 0;
matthiasm@59 161 d0.maxValue = 5;
mail@41 162 d0.defaultValue = 0;
matthiasm@48 163 d0.isQuantized = true;
matthiasm@59 164 d0.quantizeStep = 0.5;
mail@41 165 list.push_back(d0);
matthiasm@4 166
matthiasm@4 167 ParameterDescriptor d1;
matthiasm@4 168 d1.identifier = "tuningmode";
matthiasm@4 169 d1.name = "tuning mode";
matthiasm@4 170 d1.description = "Tuning can be performed locally or on the whole extraction segment. Local tuning is only advisable when the tuning is likely to change over the audio, for example in podcasts, or in a cappella singing.";
matthiasm@4 171 d1.unit = "";
matthiasm@4 172 d1.minValue = 0;
matthiasm@4 173 d1.maxValue = 1;
matthiasm@4 174 d1.defaultValue = 0;
matthiasm@4 175 d1.isQuantized = true;
matthiasm@4 176 d1.valueNames.push_back("global tuning");
matthiasm@4 177 d1.valueNames.push_back("local tuning");
matthiasm@4 178 d1.quantizeStep = 1.0;
matthiasm@4 179 list.push_back(d1);
matthiasm@4 180
mail@41 181 ParameterDescriptor d2;
mail@41 182 d2.identifier = "whitening";
mail@41 183 d2.name = "spectral whitening";
mail@41 184 d2.description = "Spectral whitening: no whitening - 0; whitening - 1.";
mail@41 185 d2.unit = "";
mail@41 186 d2.isQuantized = true;
mail@41 187 d2.minValue = 0.0;
mail@41 188 d2.maxValue = 1.0;
mail@41 189 d2.defaultValue = 1.0;
mail@41 190 d2.isQuantized = false;
mail@41 191 list.push_back(d2);
mail@41 192
mail@41 193 ParameterDescriptor d3;
mail@41 194 d3.identifier = "s";
mail@41 195 d3.name = "spectral shape";
mail@41 196 d3.description = "Determines how individual notes in the note dictionary look: higher values mean more dominant higher harmonics.";
mail@41 197 d3.unit = "";
mail@41 198 d3.minValue = 0.5;
mail@41 199 d3.maxValue = 0.9;
mail@41 200 d3.defaultValue = 0.7;
mail@41 201 d3.isQuantized = false;
mail@41 202 list.push_back(d3);
mail@41 203
Chris@23 204 ParameterDescriptor d4;
matthiasm@12 205 d4.identifier = "chromanormalize";
matthiasm@12 206 d4.name = "chroma normalization";
matthiasm@12 207 d4.description = "How shall the chroma vector be normalized?";
matthiasm@12 208 d4.unit = "";
matthiasm@12 209 d4.minValue = 0;
matthiasm@13 210 d4.maxValue = 3;
matthiasm@12 211 d4.defaultValue = 0;
matthiasm@12 212 d4.isQuantized = true;
matthiasm@13 213 d4.valueNames.push_back("none");
matthiasm@13 214 d4.valueNames.push_back("maximum norm");
Chris@23 215 d4.valueNames.push_back("L1 norm");
Chris@23 216 d4.valueNames.push_back("L2 norm");
matthiasm@12 217 d4.quantizeStep = 1.0;
matthiasm@12 218 list.push_back(d4);
matthiasm@4 219
matthiasm@0 220 return list;
matthiasm@0 221 }
matthiasm@0 222
matthiasm@0 223 float
Chris@35 224 NNLSBase::getParameter(string identifier) const
matthiasm@0 225 {
Chris@23 226 if (debug_on) cerr << "--> getParameter" << endl;
matthiasm@42 227 if (identifier == "useNNLS") {
matthiasm@42 228 return m_useNNLS;
matthiasm@0 229 }
matthiasm@0 230
mail@41 231 if (identifier == "whitening") {
mail@41 232 return m_whitening;
mail@41 233 }
mail@41 234
mail@41 235 if (identifier == "s") {
mail@41 236 return m_s;
matthiasm@0 237 }
matthiasm@17 238
Chris@23 239 if (identifier == "rollon") {
matthiasm@17 240 return m_rollon;
matthiasm@17 241 }
matthiasm@0 242
mail@89 243 if (identifier == "boostn") {
mail@89 244 return m_boostN;
mail@89 245 }
mail@89 246
matthiasm@0 247 if (identifier == "tuningmode") {
matthiasm@0 248 if (m_tuneLocal) {
matthiasm@0 249 return 1.0;
matthiasm@0 250 } else {
matthiasm@0 251 return 0.0;
matthiasm@0 252 }
matthiasm@0 253 }
Chris@23 254 if (identifier == "preset") {
Chris@23 255 return m_preset;
matthiasm@3 256 }
Chris@23 257 if (identifier == "chromanormalize") {
Chris@23 258 return m_doNormalizeChroma;
matthiasm@12 259 }
matthiasm@50 260
matthiasm@50 261 if (identifier == "useHMM") {
matthiasm@50 262 return m_useHMM;
matthiasm@50 263 }
matthiasm@50 264
matthiasm@0 265 return 0;
matthiasm@0 266
matthiasm@0 267 }
matthiasm@0 268
matthiasm@0 269 void
Chris@35 270 NNLSBase::setParameter(string identifier, float value)
matthiasm@0 271 {
Chris@23 272 if (debug_on) cerr << "--> setParameter" << endl;
matthiasm@42 273 if (identifier == "useNNLS") {
matthiasm@42 274 m_useNNLS = (int) value;
matthiasm@0 275 }
matthiasm@0 276
mail@41 277 if (identifier == "whitening") {
mail@41 278 m_whitening = value;
matthiasm@0 279 }
matthiasm@0 280
mail@41 281 if (identifier == "s") {
mail@41 282 m_s = value;
mail@41 283 }
mail@41 284
matthiasm@50 285 if (identifier == "useHMM") {
matthiasm@50 286 m_useHMM = value;
matthiasm@50 287 }
matthiasm@50 288
mail@89 289 if (identifier == "boostn") {
mail@89 290 m_boostN = value;
mail@89 291 }
mail@89 292
matthiasm@0 293 if (identifier == "tuningmode") {
mail@60 294 // m_tuneLocal = (value > 0) ? true : false;
mail@60 295 m_tuneLocal = value;
matthiasm@0 296 // cerr << "m_tuneLocal :" << m_tuneLocal << endl;
matthiasm@0 297 }
matthiasm@42 298 // if (identifier == "preset") {
matthiasm@42 299 // m_preset = value;
matthiasm@42 300 // if (m_preset == 0.0) {
matthiasm@42 301 // m_tuneLocal = false;
matthiasm@42 302 // m_whitening = 1.0;
matthiasm@42 303 // m_dictID = 0.0;
matthiasm@42 304 // }
matthiasm@42 305 // if (m_preset == 1.0) {
matthiasm@42 306 // m_tuneLocal = false;
matthiasm@42 307 // m_whitening = 1.0;
matthiasm@42 308 // m_dictID = 1.0;
matthiasm@42 309 // }
matthiasm@42 310 // if (m_preset == 2.0) {
matthiasm@42 311 // m_tuneLocal = false;
matthiasm@42 312 // m_whitening = 0.7;
matthiasm@42 313 // m_dictID = 0.0;
matthiasm@42 314 // }
matthiasm@42 315 // }
Chris@23 316 if (identifier == "chromanormalize") {
Chris@23 317 m_doNormalizeChroma = value;
Chris@23 318 }
matthiasm@17 319
Chris@23 320 if (identifier == "rollon") {
Chris@23 321 m_rollon = value;
Chris@23 322 }
matthiasm@0 323 }
matthiasm@0 324
Chris@35 325 NNLSBase::ProgramList
Chris@35 326 NNLSBase::getPrograms() const
matthiasm@0 327 {
Chris@23 328 if (debug_on) cerr << "--> getPrograms" << endl;
matthiasm@0 329 ProgramList list;
matthiasm@0 330
matthiasm@0 331 // If you have no programs, return an empty list (or simply don't
matthiasm@0 332 // implement this function or getCurrentProgram/selectProgram)
matthiasm@0 333
matthiasm@0 334 return list;
matthiasm@0 335 }
matthiasm@0 336
matthiasm@0 337 string
Chris@35 338 NNLSBase::getCurrentProgram() const
matthiasm@0 339 {
Chris@23 340 if (debug_on) cerr << "--> getCurrentProgram" << endl;
matthiasm@0 341 return ""; // no programs
matthiasm@0 342 }
matthiasm@0 343
matthiasm@0 344 void
Chris@35 345 NNLSBase::selectProgram(string name)
matthiasm@0 346 {
Chris@23 347 if (debug_on) cerr << "--> selectProgram" << endl;
matthiasm@0 348 }
matthiasm@0 349
matthiasm@0 350
matthiasm@0 351 bool
Chris@35 352 NNLSBase::initialise(size_t channels, size_t stepSize, size_t blockSize)
matthiasm@0 353 {
Chris@23 354 if (debug_on) {
Chris@23 355 cerr << "--> initialise";
Chris@23 356 }
matthiasm@1 357
mail@80 358 // make things for tuning estimation
mail@80 359 for (int iBPS = 0; iBPS < nBPS; ++iBPS) {
mail@80 360 sinvalues.push_back(sin(2*M_PI*(iBPS*1.0/nBPS)));
mail@80 361 cosvalues.push_back(cos(2*M_PI*(iBPS*1.0/nBPS)));
mail@80 362 }
mail@80 363
mail@80 364
mail@80 365 // make hamming window of length 1/2 octave
mail@76 366 int hamwinlength = nBPS * 6 + 1;
mail@76 367 float hamwinsum = 0;
mail@76 368 for (int i = 0; i < hamwinlength; ++i) {
mail@76 369 hw.push_back(0.54 - 0.46 * cos((2*M_PI*i)/(hamwinlength-1)));
mail@76 370 hamwinsum += 0.54 - 0.46 * cos((2*M_PI*i)/(hamwinlength-1));
mail@76 371 }
mail@77 372 for (int i = 0; i < hamwinlength; ++i) hw[i] = hw[i] / hamwinsum;
mail@80 373
mail@80 374
mail@80 375 // initialise the tuning
mail@80 376 for (int iBPS = 0; iBPS < nBPS; ++iBPS) {
mail@80 377 m_meanTunings.push_back(0);
mail@80 378 m_localTunings.push_back(0);
mail@80 379 }
mail@76 380
matthiasm@0 381 if (channels < getMinChannelCount() ||
matthiasm@0 382 channels > getMaxChannelCount()) return false;
matthiasm@0 383 m_blockSize = blockSize;
matthiasm@0 384 m_stepSize = stepSize;
Chris@35 385 m_frameCount = 0;
mail@77 386 int tempn = nNote * m_blockSize/2;
Chris@23 387 // cerr << "length of tempkernel : " << tempn << endl;
Chris@23 388 float *tempkernel;
matthiasm@1 389
Chris@23 390 tempkernel = new float[tempn];
matthiasm@1 391
Chris@23 392 logFreqMatrix(m_inputSampleRate, m_blockSize, tempkernel);
Chris@23 393 m_kernelValue.clear();
Chris@23 394 m_kernelFftIndex.clear();
Chris@23 395 m_kernelNoteIndex.clear();
Chris@23 396 int countNonzero = 0;
Chris@91 397 for (int iNote = 0; iNote < nNote; ++iNote) { // I don't know if this is wise: manually making a sparse matrix
Chris@91 398 for (int iFFT = 0; iFFT < blockSize/2; ++iFFT) {
Chris@23 399 if (tempkernel[iFFT + blockSize/2 * iNote] > 0) {
Chris@23 400 m_kernelValue.push_back(tempkernel[iFFT + blockSize/2 * iNote]);
Chris@23 401 if (tempkernel[iFFT + blockSize/2 * iNote] > 0) {
Chris@23 402 countNonzero++;
Chris@23 403 }
Chris@23 404 m_kernelFftIndex.push_back(iFFT);
Chris@23 405 m_kernelNoteIndex.push_back(iNote);
Chris@23 406 }
Chris@23 407 }
Chris@23 408 }
Chris@23 409 // cerr << "nonzero count : " << countNonzero << endl;
Chris@23 410 delete [] tempkernel;
Chris@35 411 /*
Chris@23 412 ofstream myfile;
Chris@23 413 myfile.open ("matrix.txt");
matthiasm@3 414 // myfile << "Writing this to a file.\n";
Chris@23 415 for (int i = 0; i < nNote * 84; ++i) {
Chris@23 416 myfile << m_dict[i] << endl;
Chris@23 417 }
matthiasm@3 418 myfile.close();
Chris@35 419 */
matthiasm@0 420 return true;
matthiasm@0 421 }
matthiasm@0 422
matthiasm@0 423 void
Chris@35 424 NNLSBase::reset()
matthiasm@0 425 {
Chris@23 426 if (debug_on) cerr << "--> reset";
matthiasm@4 427
matthiasm@0 428 // Clear buffers, reset stored values, etc
Chris@35 429 m_frameCount = 0;
matthiasm@42 430 // m_dictID = 0;
Chris@35 431 m_logSpectrum.clear();
mail@80 432 for (int iBPS = 0; iBPS < nBPS; ++iBPS) {
mail@80 433 m_meanTunings[iBPS] = 0;
mail@80 434 m_localTunings[iBPS] = 0;
mail@80 435 }
Chris@23 436 m_localTuning.clear();
matthiasm@0 437 }
matthiasm@0 438
Chris@35 439 void
Chris@35 440 NNLSBase::baseProcess(const float *const *inputBuffers, Vamp::RealTime timestamp)
matthiasm@0 441 {
Chris@35 442 m_frameCount++;
Chris@23 443 float *magnitude = new float[m_blockSize/2];
matthiasm@0 444
Chris@23 445 const float *fbuf = inputBuffers[0];
Chris@23 446 float energysum = 0;
Chris@23 447 // make magnitude
Chris@23 448 float maxmag = -10000;
Chris@23 449 for (size_t iBin = 0; iBin < m_blockSize/2; iBin++) {
Chris@23 450 magnitude[iBin] = sqrt(fbuf[2 * iBin] * fbuf[2 * iBin] +
Chris@23 451 fbuf[2 * iBin + 1] * fbuf[2 * iBin + 1]);
Chris@23 452 if (maxmag < magnitude[iBin]) maxmag = magnitude[iBin];
Chris@23 453 if (m_rollon > 0) {
Chris@23 454 energysum += pow(magnitude[iBin],2);
Chris@23 455 }
Chris@23 456 }
matthiasm@14 457
Chris@23 458 float cumenergy = 0;
Chris@23 459 if (m_rollon > 0) {
Chris@23 460 for (size_t iBin = 2; iBin < m_blockSize/2; iBin++) {
Chris@23 461 cumenergy += pow(magnitude[iBin],2);
matthiasm@59 462 if (cumenergy < energysum * m_rollon / 100) magnitude[iBin-2] = 0;
Chris@23 463 else break;
Chris@23 464 }
Chris@23 465 }
matthiasm@17 466
Chris@23 467 if (maxmag < 2) {
Chris@23 468 // cerr << "timestamp " << timestamp << ": very low magnitude, setting magnitude to all zeros" << endl;
Chris@23 469 for (size_t iBin = 0; iBin < m_blockSize/2; iBin++) {
Chris@23 470 magnitude[iBin] = 0;
Chris@23 471 }
Chris@23 472 }
matthiasm@4 473
Chris@23 474 // note magnitude mapping using pre-calculated matrix
Chris@23 475 float *nm = new float[nNote]; // note magnitude
Chris@91 476 for (int iNote = 0; iNote < nNote; iNote++) {
Chris@23 477 nm[iNote] = 0; // initialise as 0
Chris@23 478 }
Chris@23 479 int binCount = 0;
Chris@23 480 for (vector<float>::iterator it = m_kernelValue.begin(); it != m_kernelValue.end(); ++it) {
Chris@23 481 // cerr << ".";
Chris@23 482 nm[m_kernelNoteIndex[binCount]] += magnitude[m_kernelFftIndex[binCount]] * m_kernelValue[binCount];
Chris@23 483 // cerr << m_kernelFftIndex[binCount] << " -- " << magnitude[m_kernelFftIndex[binCount]] << " -- "<< m_kernelValue[binCount] << endl;
Chris@23 484 binCount++;
Chris@23 485 }
Chris@23 486 // cerr << nm[20];
Chris@23 487 // cerr << endl;
matthiasm@0 488
matthiasm@0 489
Chris@35 490 float one_over_N = 1.0/m_frameCount;
matthiasm@0 491 // update means of complex tuning variables
mail@80 492 for (int iBPS = 0; iBPS < nBPS; ++iBPS) m_meanTunings[iBPS] *= float(m_frameCount-1)*one_over_N;
mail@80 493
mail@80 494 for (int iTone = 0; iTone < round(nNote*0.62/nBPS)*nBPS+1; iTone = iTone + nBPS) {
mail@80 495 for (int iBPS = 0; iBPS < nBPS; ++iBPS) m_meanTunings[iBPS] += nm[iTone + iBPS]*one_over_N;
Chris@23 496 float ratioOld = 0.997;
mail@80 497 for (int iBPS = 0; iBPS < nBPS; ++iBPS) {
mail@80 498 m_localTunings[iBPS] *= ratioOld;
mail@80 499 m_localTunings[iBPS] += nm[iTone + iBPS] * (1 - ratioOld);
mail@80 500 }
matthiasm@0 501 }
matthiasm@0 502 // if (m_tuneLocal) {
Chris@23 503 // local tuning
mail@80 504 // float localTuningImag = sinvalue * m_localTunings[1] - sinvalue * m_localTunings[2];
mail@80 505 // float localTuningReal = m_localTunings[0] + cosvalue * m_localTunings[1] + cosvalue * m_localTunings[2];
mail@80 506
mail@80 507 float localTuningImag = 0;
mail@80 508 float localTuningReal = 0;
mail@80 509 for (int iBPS = 0; iBPS < nBPS; ++iBPS) {
mail@80 510 localTuningReal += m_localTunings[iBPS] * cosvalues[iBPS];
mail@80 511 localTuningImag += m_localTunings[iBPS] * sinvalues[iBPS];
mail@80 512 }
mail@80 513
Chris@23 514 float normalisedtuning = atan2(localTuningImag, localTuningReal)/(2*M_PI);
Chris@23 515 m_localTuning.push_back(normalisedtuning);
matthiasm@0 516
Chris@23 517 Feature f1; // logfreqspec
Chris@23 518 f1.hasTimestamp = true;
matthiasm@0 519 f1.timestamp = timestamp;
Chris@91 520 for (int iNote = 0; iNote < nNote; iNote++) {
Chris@23 521 f1.values.push_back(nm[iNote]);
Chris@23 522 }
matthiasm@0 523
matthiasm@0 524 // deletes
matthiasm@0 525 delete[] magnitude;
matthiasm@0 526 delete[] nm;
matthiasm@0 527
Chris@35 528 m_logSpectrum.push_back(f1); // remember note magnitude
matthiasm@0 529 }
matthiasm@0 530