Mercurial > hg > btrack
comparison src/BTrack.cpp @ 98:3b24b01fbe15
More tidying...
author | Adam Stark <adamstark.uk@gmail.com> |
---|---|
date | Sat, 12 Aug 2017 13:54:35 +0100 |
parents | 6a4dd7478954 |
children | 6aea5918992d |
comparison
equal
deleted
inserted
replaced
97:6a4dd7478954 | 98:3b24b01fbe15 |
---|---|
97 tempoObservationVector.resize (41); | 97 tempoObservationVector.resize (41); |
98 delta.resize (41); | 98 delta.resize (41); |
99 prevDelta.resize (41); | 99 prevDelta.resize (41); |
100 prevDeltaFixed.resize (41); | 100 prevDeltaFixed.resize (41); |
101 | 101 |
102 double rayparam = 43; | 102 double rayleighParameter = 43; |
103 double pi = 3.14159265; | 103 double pi = 3.14159265; |
104 | 104 |
105 | 105 |
106 // initialise parameters | 106 // initialise parameters |
107 tightness = 5; | 107 tightness = 5; |
116 beatDueInFrame = false; | 116 beatDueInFrame = false; |
117 | 117 |
118 | 118 |
119 // create rayleigh weighting vector | 119 // create rayleigh weighting vector |
120 for (int n = 0; n < 128; n++) | 120 for (int n = 0; n < 128; n++) |
121 { | 121 weightingVector[n] = ((double) n / pow (rayleighParameter, 2)) * exp((-1 * pow((double) - n, 2)) / (2 * pow (rayleighParameter, 2))); |
122 weightingVector[n] = ((double) n / pow(rayparam,2)) * exp((-1*pow((double)-n,2)) / (2*pow(rayparam,2))); | |
123 } | |
124 | 122 |
125 // initialise prev_delta | 123 // initialise prev_delta |
126 std::fill (prevDelta.begin(), prevDelta.end(), 1); | 124 std::fill (prevDelta.begin(), prevDelta.end(), 1); |
127 | 125 |
128 double t_mu = 41/2; | 126 double t_mu = 41/2; |
662 } | 660 } |
663 } | 661 } |
664 | 662 |
665 //======================================================================= | 663 //======================================================================= |
666 void BTrack::updateCumulativeScore (double odfSample) | 664 void BTrack::updateCumulativeScore (double odfSample) |
667 { | 665 { |
668 int start, end, winsize; | 666 int start = onsetDFBufferSize - round (2. * beatPeriod); |
669 double max; | 667 int end = onsetDFBufferSize - round (beatPeriod / 2.); |
670 | 668 int windowSize = end - start + 1; |
671 start = onsetDFBufferSize - round (2. * beatPeriod); | 669 |
672 end = onsetDFBufferSize - round (beatPeriod / 2.); | 670 double w1[windowSize]; |
673 winsize = end - start + 1; | |
674 | |
675 double w1[winsize]; | |
676 double v = -2. * beatPeriod; | 671 double v = -2. * beatPeriod; |
677 double wcumscore; | 672 double weightedCumulativeScore; |
678 | 673 |
679 // create window | 674 // create window |
680 for (int i = 0; i < winsize; i++) | 675 for (int i = 0; i < windowSize; i++) |
681 { | 676 { |
682 w1[i] = exp((-1 * pow (tightness * log (-v / beatPeriod), 2)) / 2); | 677 double a = tightness * log (-v / beatPeriod); |
683 v = v + 1; | 678 w1[i] = exp ((-1. * a * a) / 2.); |
679 v = v + 1.; | |
684 } | 680 } |
685 | 681 |
686 // calculate new cumulative score value | 682 // calculate new cumulative score value |
687 max = 0; | 683 double maxValue = 0; |
688 int n = 0; | 684 int n = 0; |
689 for (int i=start; i <= end; i++) | 685 for (int i = start; i <= end; i++) |
690 { | 686 { |
691 wcumscore = cumulativeScore[i]*w1[n]; | 687 weightedCumulativeScore = cumulativeScore[i] * w1[n]; |
692 | 688 |
693 if (wcumscore > max) | 689 if (weightedCumulativeScore > maxValue) |
694 { | 690 maxValue = weightedCumulativeScore; |
695 max = wcumscore; | 691 |
696 } | |
697 n++; | 692 n++; |
698 } | 693 } |
699 | 694 |
700 latestCumulativeScoreValue = ((1 - alpha) * odfSample) + (alpha * max); | 695 latestCumulativeScoreValue = ((1 - alpha) * odfSample) + (alpha * maxValue); |
701 | |
702 cumulativeScore.addSampleToEnd (latestCumulativeScoreValue); | 696 cumulativeScore.addSampleToEnd (latestCumulativeScoreValue); |
703 } | 697 } |
704 | 698 |
705 //======================================================================= | 699 //======================================================================= |
706 void BTrack::predictBeat() | 700 void BTrack::predictBeat() |