Skip to content

Commit

Permalink
Tidying up the interface to some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstark committed Sep 12, 2017
1 parent 00af694 commit 0af432b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
37 changes: 16 additions & 21 deletions src/BTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@
BTrack::BTrack()
: odf (512, 1024, ComplexSpectralDifferenceHWR, HanningWindow)
{
initialise (512, 1024);
initialise (512);
}

//=======================================================================
BTrack::BTrack (int hopSize_)
: odf (hopSize_, 2 * hopSize_, ComplexSpectralDifferenceHWR, HanningWindow)
BTrack::BTrack (int hop)
: odf (hop, 2 * hop, ComplexSpectralDifferenceHWR, HanningWindow)
{
initialise (hopSize_, 2 * hopSize_);
initialise (hop);
}

//=======================================================================
BTrack::BTrack (int hopSize_, int frameSize_)
: odf (hopSize_, frameSize_, ComplexSpectralDifferenceHWR, HanningWindow)
BTrack::BTrack (int hop, int frame)
: odf (hop, frame, ComplexSpectralDifferenceHWR, HanningWindow)
{
initialise (hopSize_, frameSize_);
initialise (hop);
}

//=======================================================================
Expand All @@ -67,17 +67,13 @@ BTrack::~BTrack()
}

//=======================================================================
double BTrack::getBeatTimeInSeconds (long frameNumber, int hopSize, int fs)
double BTrack::getBeatTimeInSeconds (long frameNumber, int hopSize, int samplingFrequency)
{
double hop = (double) hopSize;
double samplingFrequency = (double) fs;
double frameNum = (double) frameNumber;

return ((hop / samplingFrequency) * frameNum);
return ((static_cast<double> (hopSize) / static_cast<double> (samplingFrequency)) * static_cast<double> (frameNumber));
}

//=======================================================================
void BTrack::initialise (int hopSize_, int frameSize_)
void BTrack::initialise (int hop)
{
// set vector sizes
resampledOnsetDF.resize (512);
Expand All @@ -91,7 +87,6 @@ void BTrack::initialise (int hopSize_, int frameSize_)

double rayleighParameter = 43;


// initialise parameters
tightness = 5;
alpha = 0.9;
Expand Down Expand Up @@ -129,7 +124,7 @@ void BTrack::initialise (int hopSize_, int frameSize_)
tempoFixed = false;

// initialise algorithm given the hopsize
setHopSize (hopSize_);
setHopSize (hop);

// Set up FFT for calculating the auto-correlation function
FFTLengthForACFCalculation = 1024;
Expand All @@ -151,9 +146,9 @@ void BTrack::initialise (int hopSize_, int frameSize_)
}

//=======================================================================
void BTrack::setHopSize (int hopSize_)
void BTrack::setHopSize (int hop)
{
hopSize = hopSize_;
hopSize = hop;
onsetDFBufferSize = (512 * 512) / hopSize; // calculate df buffer size
beatPeriod = round(60/((((double) hopSize)/44100) * 120.));

Expand All @@ -177,13 +172,13 @@ void BTrack::setHopSize (int hopSize_)
}

//=======================================================================
void BTrack::updateHopAndFrameSize (int hopSize_, int frameSize_)
void BTrack::updateHopAndFrameSize (int hop, int frame)
{
// update the onset detection function object
odf.initialise (hopSize_, frameSize_);
odf.initialise (hop, frame);

// update the hop size being used by the beat tracker
setHopSize (hopSize_);
setHopSize (hop);
}

//=======================================================================
Expand Down
13 changes: 6 additions & 7 deletions src/BTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class BTrack {
/** Constructor assuming frame size will be double the hopSize
* @param hopSize the hop size in audio samples
*/
BTrack (int hopSize_);
BTrack (int hopSize);

/** Constructor taking both hopSize and frameSize
* @param hopSize the hop size in audio samples
* @param frameSize the frame size in audio samples
*/
BTrack (int hopSize_, int frameSize_);
BTrack (int hopSize, int frameSize);

/** Destructor */
~BTrack();
Expand Down Expand Up @@ -114,15 +114,14 @@ class BTrack {
private:

/** Initialises the algorithm, setting internal parameters and creating weighting vectors
* @param hopSize_ the hop size in audio samples
* @param frameSize_ the frame size in audio samples
* @param hopSize the hop size in audio samples
*/
void initialise (int hopSize_, int frameSize_);
void initialise (int hopSize);

/** Initialise with hop size and set all array sizes accordingly
* @param hopSize_ the hop size in audio samples
* @param hopSize the hop size in audio samples
*/
void setHopSize (int hopSize_);
void setHopSize (int hopSize);

/** Resamples the onset detection function from an arbitrary number of samples to 512 */
void resampleOnsetDetectionFunction();
Expand Down

0 comments on commit 0af432b

Please sign in to comment.