Mercurial > hg > btrack
comparison src/BTrack.cpp @ 56:b6d440942ff6
Added some simple unit tests. Removed the destructor from the BTrack class as it was unnecessary.
author | Adam Stark <adamstark@users.noreply.github.com> |
---|---|
date | Thu, 23 Jan 2014 12:17:06 +0000 |
parents | 5e520f59127f |
children | 296af6af6c3d |
comparison
equal
deleted
inserted
replaced
55:5e520f59127f | 56:b6d440942ff6 |
---|---|
41 { | 41 { |
42 initialise(hopSize, frameSize); | 42 initialise(hopSize, frameSize); |
43 } | 43 } |
44 | 44 |
45 //======================================================================= | 45 //======================================================================= |
46 BTrack::~BTrack() | |
47 { | |
48 | |
49 } | |
50 | |
51 //======================================================================= | |
52 double BTrack::getBeatTimeInSeconds(long frameNumber,int hopSize,int fs) | 46 double BTrack::getBeatTimeInSeconds(long frameNumber,int hopSize,int fs) |
53 { | 47 { |
54 double hop = (double) hopSize; | 48 double hop = (double) hopSize; |
55 double samplingFrequency = (double) fs; | 49 double samplingFrequency = (double) fs; |
56 double frameNum = (double) frameNumber; | 50 double frameNum = (double) frameNumber; |
154 void BTrack::processAudioFrame(double *frame) | 148 void BTrack::processAudioFrame(double *frame) |
155 { | 149 { |
156 // calculate the onset detection function sample for the frame | 150 // calculate the onset detection function sample for the frame |
157 double sample = odf.getDFsample(frame); | 151 double sample = odf.getDFsample(frame); |
158 | 152 |
153 | |
154 | |
155 // process the new onset detection function sample in the beat tracking algorithm | |
156 processOnsetDetectionFunctionSample(sample); | |
157 } | |
158 | |
159 //======================================================================= | |
160 void BTrack::processOnsetDetectionFunctionSample(double newSample) | |
161 { | |
162 // we need to ensure that the onset | |
163 // detection function sample is positive | |
164 newSample = fabs(newSample); | |
165 | |
159 // add a tiny constant to the sample to stop it from ever going | 166 // add a tiny constant to the sample to stop it from ever going |
160 // to zero. this is to avoid problems further down the line | 167 // to zero. this is to avoid problems further down the line |
161 sample = sample + 0.0001; | 168 newSample = newSample + 0.0001; |
162 | 169 |
163 // process the new onset detection function sample in the beat tracking algorithm | |
164 processOnsetDetectionFunctionSample(sample); | |
165 } | |
166 | |
167 //======================================================================= | |
168 void BTrack::processOnsetDetectionFunctionSample(double newSample) | |
169 { | |
170 m0--; | 170 m0--; |
171 beat--; | 171 beat--; |
172 playbeat = 0; | 172 playbeat = 0; |
173 | 173 |
174 // move all samples back one step | 174 // move all samples back one step |