Skip to content

Commit

Permalink
Made log-gaussian transition window calculated in a function, rather …
Browse files Browse the repository at this point in the history
…than with duplicated code
  • Loading branch information
adamstark committed Sep 11, 2017
1 parent b054ae8 commit b4aa128
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/BTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,23 +628,15 @@ void BTrack::updateCumulativeScore (double onsetDetectionFunctionSample)
int windowEnd = onsetDFBufferSize - round (beatPeriod / 2.);
int windowSize = windowEnd - windowStart + 1;

double w1[windowSize];
double v = -2. * beatPeriod;

// create window
for (int i = 0; i < windowSize; i++)
{
double a = tightness * log (-v / beatPeriod);
w1[i] = exp ((-1. * a * a) / 2.);
v = v + 1.;
}
double logGaussianTransitionWeighting[windowSize];
createLogGaussianTransitionWeighting (logGaussianTransitionWeighting, windowSize, beatPeriod);

// calculate new cumulative score value
double maxValue = 0;
int n = 0;
for (int i = windowStart; i <= windowEnd; i++)
{
double weightedCumulativeScore = cumulativeScore[i] * w1[n];
double weightedCumulativeScore = cumulativeScore[i] * logGaussianTransitionWeighting[n];

if (weightedCumulativeScore > maxValue)
maxValue = weightedCumulativeScore;
Expand Down Expand Up @@ -685,17 +677,13 @@ void BTrack::predictBeat()
// one beat period in the past
// This is W1 in Adam Stark's PhD thesis, equation 3.2, page 60

v = -2 * beatPeriod;

int startIndex = onsetDFBufferSize - round (2 * beatPeriod);
int endIndex = onsetDFBufferSize - round (beatPeriod / 2);
int pastWindowSize = endIndex - startIndex + 1;

double logGaussianTransitionWeighting[pastWindowSize];

for (int i = 0; i < pastWindowSize; i++)
{
logGaussianTransitionWeighting[i] = exp((-1 * pow (tightness * log (-v / beatPeriod), 2) ) / 2);
v = v + 1;
}
createLogGaussianTransitionWeighting (logGaussianTransitionWeighting, pastWindowSize, beatPeriod);

// Calculate the future cumulative score, using the log Gaussian transition weighting

Expand Down Expand Up @@ -741,3 +729,16 @@ void BTrack::predictBeat()
// set next prediction time
m0 = beatCounter + round (beatPeriod / 2);
}

//=======================================================================
void BTrack::createLogGaussianTransitionWeighting (double* weightingArray, int numSamples, double beatPeriod)
{
double v = -2. * beatPeriod;

for (int i = 0; i < numSamples; i++)
{
double a = tightness * log (-v / beatPeriod);
weightingArray[i] = exp ((-1. * a * a) / 2.);
v++;
}
}
4 changes: 4 additions & 0 deletions src/BTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ class BTrack {

/** Calculates the output of the comb filter bank */
void calculateOutputOfCombFilterBank();

void createLogGaussianTransitionWeighting (double* weightingArray, int numSamples, double beatPeriod);



//=======================================================================

Expand Down

0 comments on commit b4aa128

Please sign in to comment.