comparison src/BTrack.cpp @ 108:a6701b3f636f

Tidying up the interface to some functions
author Adam Stark <adamstark.uk@gmail.com>
date Tue, 12 Sep 2017 08:40:16 +0100
parents 6f5ba0250afd
children 8fb1610c9192
comparison
equal deleted inserted replaced
107:e354bb51b875 108:a6701b3f636f
28 28
29 //======================================================================= 29 //=======================================================================
30 BTrack::BTrack() 30 BTrack::BTrack()
31 : odf (512, 1024, ComplexSpectralDifferenceHWR, HanningWindow) 31 : odf (512, 1024, ComplexSpectralDifferenceHWR, HanningWindow)
32 { 32 {
33 initialise (512, 1024); 33 initialise (512);
34 } 34 }
35 35
36 //======================================================================= 36 //=======================================================================
37 BTrack::BTrack (int hopSize_) 37 BTrack::BTrack (int hop)
38 : odf (hopSize_, 2 * hopSize_, ComplexSpectralDifferenceHWR, HanningWindow) 38 : odf (hop, 2 * hop, ComplexSpectralDifferenceHWR, HanningWindow)
39 { 39 {
40 initialise (hopSize_, 2 * hopSize_); 40 initialise (hop);
41 } 41 }
42 42
43 //======================================================================= 43 //=======================================================================
44 BTrack::BTrack (int hopSize_, int frameSize_) 44 BTrack::BTrack (int hop, int frame)
45 : odf (hopSize_, frameSize_, ComplexSpectralDifferenceHWR, HanningWindow) 45 : odf (hop, frame, ComplexSpectralDifferenceHWR, HanningWindow)
46 { 46 {
47 initialise (hopSize_, frameSize_); 47 initialise (hop);
48 } 48 }
49 49
50 //======================================================================= 50 //=======================================================================
51 BTrack::~BTrack() 51 BTrack::~BTrack()
52 { 52 {
65 delete [] fftOut; 65 delete [] fftOut;
66 #endif 66 #endif
67 } 67 }
68 68
69 //======================================================================= 69 //=======================================================================
70 double BTrack::getBeatTimeInSeconds (long frameNumber, int hopSize, int fs) 70 double BTrack::getBeatTimeInSeconds (long frameNumber, int hopSize, int samplingFrequency)
71 { 71 {
72 double hop = (double) hopSize; 72 return ((static_cast<double> (hopSize) / static_cast<double> (samplingFrequency)) * static_cast<double> (frameNumber));
73 double samplingFrequency = (double) fs; 73 }
74 double frameNum = (double) frameNumber; 74
75 75 //=======================================================================
76 return ((hop / samplingFrequency) * frameNum); 76 void BTrack::initialise (int hop)
77 }
78
79 //=======================================================================
80 void BTrack::initialise (int hopSize_, int frameSize_)
81 { 77 {
82 // set vector sizes 78 // set vector sizes
83 resampledOnsetDF.resize (512); 79 resampledOnsetDF.resize (512);
84 acf.resize (512); 80 acf.resize (512);
85 weightingVector.resize (128); 81 weightingVector.resize (128);
89 prevDelta.resize (41); 85 prevDelta.resize (41);
90 prevDeltaFixed.resize (41); 86 prevDeltaFixed.resize (41);
91 87
92 double rayleighParameter = 43; 88 double rayleighParameter = 43;
93 89
94
95 // initialise parameters 90 // initialise parameters
96 tightness = 5; 91 tightness = 5;
97 alpha = 0.9; 92 alpha = 0.9;
98 estimatedTempo = 120.0; 93 estimatedTempo = 120.0;
99 94
127 122
128 // tempo is not fixed 123 // tempo is not fixed
129 tempoFixed = false; 124 tempoFixed = false;
130 125
131 // initialise algorithm given the hopsize 126 // initialise algorithm given the hopsize
132 setHopSize (hopSize_); 127 setHopSize (hop);
133 128
134 // Set up FFT for calculating the auto-correlation function 129 // Set up FFT for calculating the auto-correlation function
135 FFTLengthForACFCalculation = 1024; 130 FFTLengthForACFCalculation = 1024;
136 131
137 #ifdef USE_FFTW 132 #ifdef USE_FFTW
149 cfgBackwards = kiss_fft_alloc (FFTLengthForACFCalculation, 1, 0, 0); 144 cfgBackwards = kiss_fft_alloc (FFTLengthForACFCalculation, 1, 0, 0);
150 #endif 145 #endif
151 } 146 }
152 147
153 //======================================================================= 148 //=======================================================================
154 void BTrack::setHopSize (int hopSize_) 149 void BTrack::setHopSize (int hop)
155 { 150 {
156 hopSize = hopSize_; 151 hopSize = hop;
157 onsetDFBufferSize = (512 * 512) / hopSize; // calculate df buffer size 152 onsetDFBufferSize = (512 * 512) / hopSize; // calculate df buffer size
158 beatPeriod = round(60/((((double) hopSize)/44100) * 120.)); 153 beatPeriod = round(60/((((double) hopSize)/44100) * 120.));
159 154
160 // set size of onset detection function buffer 155 // set size of onset detection function buffer
161 onsetDF.resize (onsetDFBufferSize); 156 onsetDF.resize (onsetDFBufferSize);
175 } 170 }
176 } 171 }
177 } 172 }
178 173
179 //======================================================================= 174 //=======================================================================
180 void BTrack::updateHopAndFrameSize (int hopSize_, int frameSize_) 175 void BTrack::updateHopAndFrameSize (int hop, int frame)
181 { 176 {
182 // update the onset detection function object 177 // update the onset detection function object
183 odf.initialise (hopSize_, frameSize_); 178 odf.initialise (hop, frame);
184 179
185 // update the hop size being used by the beat tracker 180 // update the hop size being used by the beat tracker
186 setHopSize (hopSize_); 181 setHopSize (hop);
187 } 182 }
188 183
189 //======================================================================= 184 //=======================================================================
190 bool BTrack::beatDueInCurrentFrame() 185 bool BTrack::beatDueInCurrentFrame()
191 { 186 {