comparison src/BTrack.cpp @ 115:54c657d621dd

Code style updates
author Adam Stark <adamstark.uk@gmail.com>
date Fri, 18 Aug 2023 20:00:10 +0200
parents 8fb1610c9192
children
comparison
equal deleted inserted replaced
114:d6d9df2db3e1 115:54c657d621dd
149 //======================================================================= 149 //=======================================================================
150 void BTrack::setHopSize (int hop) 150 void BTrack::setHopSize (int hop)
151 { 151 {
152 hopSize = hop; 152 hopSize = hop;
153 onsetDFBufferSize = (512 * 512) / hopSize; // calculate df buffer size 153 onsetDFBufferSize = (512 * 512) / hopSize; // calculate df buffer size
154 beatPeriod = round(60/((((double) hopSize)/44100) * 120.)); 154 beatPeriod = round (60 / ((((double) hopSize) / 44100) * 120.));
155 155
156 // set size of onset detection function buffer 156 // set size of onset detection function buffer
157 onsetDF.resize (onsetDFBufferSize); 157 onsetDF.resize (onsetDFBufferSize);
158 158
159 // set size of cumulative score buffer 159 // set size of cumulative score buffer
322 322
323 // convert tempo from bpm value to integer index of tempo probability 323 // convert tempo from bpm value to integer index of tempo probability
324 int tempoIndex = (int) round((tempo - 80) / 2); 324 int tempoIndex = (int) round((tempo - 80) / 2);
325 325
326 // now set previous fixed previous tempo observation values to zero 326 // now set previous fixed previous tempo observation values to zero
327 for (int i=0;i < 41;i++) 327 for (int i = 0; i < 41; i++)
328 { 328 {
329 prevDeltaFixed[i] = 0; 329 prevDeltaFixed[i] = 0;
330 } 330 }
331 331
332 // set desired tempo index to 1 332 // set desired tempo index to 1
347 void BTrack::resampleOnsetDetectionFunction() 347 void BTrack::resampleOnsetDetectionFunction()
348 { 348 {
349 float output[512]; 349 float output[512];
350 float input[onsetDFBufferSize]; 350 float input[onsetDFBufferSize];
351 351
352 for (int i = 0;i < onsetDFBufferSize;i++) 352 for (int i = 0; i < onsetDFBufferSize; i++)
353 input[i] = (float) onsetDF[i]; 353 input[i] = (float) onsetDF[i];
354 354
355 double ratio = 512.0 / ((double) onsetDFBufferSize); 355 double ratio = 512.0 / ((double) onsetDFBufferSize);
356 int bufferLength = onsetDFBufferSize; 356 int bufferLength = onsetDFBufferSize;
357 int outputLength = 512; 357 int outputLength = 512;
433 } 433 }
434 434
435 beatPeriod = round ((60.0 * 44100.0) / (((2 * maxIndex) + 80) * ((double) hopSize))); 435 beatPeriod = round ((60.0 * 44100.0) / (((2 * maxIndex) + 80) * ((double) hopSize)));
436 436
437 if (beatPeriod > 0) 437 if (beatPeriod > 0)
438 estimatedTempo = 60.0/((((double) hopSize) / 44100.0) * beatPeriod); 438 estimatedTempo = 60.0 / ((((double) hopSize) / 44100.0) * beatPeriod);
439 } 439 }
440 440
441 //======================================================================= 441 //=======================================================================
442 void BTrack::adaptiveThreshold (std::vector<double>& x) 442 void BTrack::adaptiveThreshold (std::vector<double>& x)
443 { 443 {
489 { 489 {
490 for (int a = 1; a <= numCombElements; a++) // number of comb elements 490 for (int a = 1; a <= numCombElements; a++) // number of comb elements
491 { 491 {
492 for (int b = 1 - a; b <= a - 1; b++) // general state using normalisation of comb elements 492 for (int b = 1 - a; b <= a - 1; b++) // general state using normalisation of comb elements
493 { 493 {
494 combFilterBankOutput[i-1] += (acf[(a * i + b) - 1] * weightingVector[i - 1]) / (2 * a - 1); // calculate value for comb filter row 494 combFilterBankOutput[i - 1] += (acf[(a * i + b) - 1] * weightingVector[i - 1]) / (2 * a - 1); // calculate value for comb filter row
495 } 495 }
496 } 496 }
497 } 497 }
498 } 498 }
499 499
520 520
521 // perform the fft 521 // perform the fft
522 fftw_execute (acfForwardFFT); 522 fftw_execute (acfForwardFFT);
523 523
524 // multiply by complex conjugate 524 // multiply by complex conjugate
525 for (int i = 0;i < FFTLengthForACFCalculation;i++) 525 for (int i = 0; i < FFTLengthForACFCalculation; i++)
526 { 526 {
527 complexOut[i][0] = complexOut[i][0] * complexOut[i][0] + complexOut[i][1] * complexOut[i][1]; 527 complexOut[i][0] = complexOut[i][0] * complexOut[i][0] + complexOut[i][1] * complexOut[i][1];
528 complexOut[i][1] = 0.0; 528 complexOut[i][1] = 0.0;
529 } 529 }
530 530
551 551
552 // execute kiss fft 552 // execute kiss fft
553 kiss_fft (cfgForwards, fftIn, fftOut); 553 kiss_fft (cfgForwards, fftIn, fftOut);
554 554
555 // multiply by complex conjugate 555 // multiply by complex conjugate
556 for (int i = 0;i < FFTLengthForACFCalculation;i++) 556 for (int i = 0; i < FFTLengthForACFCalculation; i++)
557 { 557 {
558 fftOut[i].r = fftOut[i].r * fftOut[i].r + fftOut[i].i * fftOut[i].i; 558 fftOut[i].r = fftOut[i].r * fftOut[i].r + fftOut[i].i * fftOut[i].i;
559 fftOut[i].i = 0.0; 559 fftOut[i].i = 0.0;
560 } 560 }
561 561
637 int beatExpectationWindowSize = static_cast<int> (beatPeriod); 637 int beatExpectationWindowSize = static_cast<int> (beatPeriod);
638 double futureCumulativeScore[onsetDFBufferSize + beatExpectationWindowSize]; 638 double futureCumulativeScore[onsetDFBufferSize + beatExpectationWindowSize];
639 double beatExpectationWindow[beatExpectationWindowSize]; 639 double beatExpectationWindow[beatExpectationWindowSize];
640 640
641 // copy cumulativeScore to first part of futureCumulativeScore 641 // copy cumulativeScore to first part of futureCumulativeScore
642 for (int i = 0;i < onsetDFBufferSize;i++) 642 for (int i = 0; i < onsetDFBufferSize; i++)
643 futureCumulativeScore[i] = cumulativeScore[i]; 643 futureCumulativeScore[i] = cumulativeScore[i];
644 644
645 // Create a beat expectation window for predicting future beats from the "future" of the cumulative score. 645 // Create a beat expectation window for predicting future beats from the "future" of the cumulative score.
646 // We are making this beat prediction at the midpoint between beats, and so we make a Gaussian 646 // We are making this beat prediction at the midpoint between beats, and so we make a Gaussian
647 // weighting centred on the most likely beat position (half a beat period into the future) 647 // weighting centred on the most likely beat position (half a beat period into the future)