Mercurial > hg > btrack
comparison src/BTrack.cpp @ 22:a8e3e95d14e4 develop
Renamed many variables, functions and arguments so they have more sensible names. Also removed an apparently redundant variable in OnsetDetectionFunction called wframe
| author | Adam <adamstark.uk@gmail.com> | 
|---|---|
| date | Fri, 24 Jan 2014 21:45:55 +0000 | 
| parents | ef4721e7466c | 
| children | 92ee4ace9d46 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 21:ef4721e7466c | 22:a8e3e95d14e4 | 
|---|---|
| 72 // initialise parameters | 72 // initialise parameters | 
| 73 tightness = 5; | 73 tightness = 5; | 
| 74 alpha = 0.9; | 74 alpha = 0.9; | 
| 75 tempo = 120; | 75 tempo = 120; | 
| 76 estimatedTempo = 120.0; | 76 estimatedTempo = 120.0; | 
| 77 p_fact = 60.*44100./512.; | 77 tempoToLagFactor = 60.*44100./512.; | 
| 78 | 78 | 
| 79 m0 = 10; | 79 m0 = 10; | 
| 80 beatCounter = -1; | 80 beatCounter = -1; | 
| 81 | 81 | 
| 82 beatDueInFrame = false; | 82 beatDueInFrame = false; | 
| 166 | 166 | 
| 167 //======================================================================= | 167 //======================================================================= | 
| 168 void BTrack::processAudioFrame(double *frame) | 168 void BTrack::processAudioFrame(double *frame) | 
| 169 { | 169 { | 
| 170 // calculate the onset detection function sample for the frame | 170 // calculate the onset detection function sample for the frame | 
| 171 double sample = odf.getDFsample(frame); | 171 double sample = odf.calculateOnsetDetectionFunctionSample(frame); | 
| 172 | 172 | 
| 173 | 173 | 
| 174 | 174 | 
| 175 // process the new onset detection function sample in the beat tracking algorithm | 175 // process the new onset detection function sample in the beat tracking algorithm | 
| 176 processOnsetDetectionFunctionSample(sample); | 176 processOnsetDetectionFunctionSample(sample); | 
| 376 adaptiveThreshold(combFilterBankOutput,128); | 376 adaptiveThreshold(combFilterBankOutput,128); | 
| 377 | 377 | 
| 378 | 378 | 
| 379 int t_index; | 379 int t_index; | 
| 380 int t_index2; | 380 int t_index2; | 
| 381 // calculate tempo observation vector from bperiod observation vector | 381 // calculate tempo observation vector from beat period observation vector | 
| 382 for (int i = 0;i < 41;i++) | 382 for (int i = 0;i < 41;i++) | 
| 383 { | 383 { | 
| 384 t_index = (int) round(p_fact / ((double) ((2*i)+80))); | 384 t_index = (int) round(tempoToLagFactor / ((double) ((2*i)+80))); | 
| 385 t_index2 = (int) round(p_fact / ((double) ((4*i)+160))); | 385 t_index2 = (int) round(tempoToLagFactor / ((double) ((4*i)+160))); | 
| 386 | 386 | 
| 387 | 387 | 
| 388 tempoObservationVector[i] = combFilterBankOutput[t_index-1] + combFilterBankOutput[t_index2-1]; | 388 tempoObservationVector[i] = combFilterBankOutput[t_index-1] + combFilterBankOutput[t_index2-1]; | 
| 389 } | 389 } | 
| 390 | 390 | 
| 444 } | 444 } | 
| 445 | 445 | 
| 446 //======================================================================= | 446 //======================================================================= | 
| 447 void BTrack::adaptiveThreshold(double *x,int N) | 447 void BTrack::adaptiveThreshold(double *x,int N) | 
| 448 { | 448 { | 
| 449 //int N = 512; // length of df | |
| 450 int i = 0; | 449 int i = 0; | 
| 451 int k,t = 0; | 450 int k,t = 0; | 
| 452 double x_thresh[N]; | 451 double x_thresh[N]; | 
| 453 | 452 | 
| 454 int p_post = 7; | 453 int p_post = 7; | 
| 530 acf[l] = sum / (512-l); // weight by number of mults and add to acf buffer | 529 acf[l] = sum / (512-l); // weight by number of mults and add to acf buffer | 
| 531 } | 530 } | 
| 532 } | 531 } | 
| 533 | 532 | 
| 534 //======================================================================= | 533 //======================================================================= | 
| 535 double BTrack::calculateMeanOfArray(double *array,int start,int end) | 534 double BTrack::calculateMeanOfArray(double *array,int startIndex,int endIndex) | 
| 536 { | 535 { | 
| 537 int i; | 536 int i; | 
| 538 double sum = 0; | 537 double sum = 0; | 
| 539 | 538 | 
| 540 int length = end - start; | 539 int length = endIndex - startIndex; | 
| 541 | 540 | 
| 542 // find sum | 541 // find sum | 
| 543 for (i = start;i < end;i++) | 542 for (i = startIndex;i < endIndex;i++) | 
| 544 { | 543 { | 
| 545 sum = sum + array[i]; | 544 sum = sum + array[i]; | 
| 546 } | 545 } | 
| 547 | 546 | 
| 548 if (length > 0) | 547 if (length > 0) | 
| 576 } | 575 } | 
| 577 } | 576 } | 
| 578 } | 577 } | 
| 579 | 578 | 
| 580 //======================================================================= | 579 //======================================================================= | 
| 581 void BTrack::updateCumulativeScore(double df_sample) | 580 void BTrack::updateCumulativeScore(double odfSample) | 
| 582 { | 581 { | 
| 583 int start, end, winsize; | 582 int start, end, winsize; | 
| 584 double max; | 583 double max; | 
| 585 | 584 | 
| 586 start = onsetDFBufferSize - round(2*beatPeriod); | 585 start = onsetDFBufferSize - round(2*beatPeriod); | 
| 619 { | 618 { | 
| 620 cumulativeScore[i] = cumulativeScore[i+1]; | 619 cumulativeScore[i] = cumulativeScore[i+1]; | 
| 621 } | 620 } | 
| 622 | 621 | 
| 623 // add new value to cumulative score | 622 // add new value to cumulative score | 
| 624 cumulativeScore[onsetDFBufferSize-1] = ((1-alpha)*df_sample) + (alpha*max); | 623 cumulativeScore[onsetDFBufferSize-1] = ((1-alpha)*odfSample) + (alpha*max); | 
| 625 | 624 | 
| 626 latestCumulativeScoreValue = cumulativeScore[onsetDFBufferSize-1]; | 625 latestCumulativeScoreValue = cumulativeScore[onsetDFBufferSize-1]; | 
| 627 | 626 | 
| 628 } | 627 } | 
| 629 | 628 | 
