27 size_t decimationFactor,
30 m_rate(originalSampleRate),
31 m_factor(decimationFactor),
32 m_increment(dfIncrement),
46 (
int((
m_rate / decimationFactor) * 1.3));
164 if (audioLength == 0)
return;
166 for (
size_t i = 0; i + 1 < beats.size(); ++i) {
173 if (beatend >= audioLength) beatend = audioLength - 1;
174 if (beatend < beatstart) beatend = beatstart;
175 size_t beatlen = beatend - beatstart;
186 double mul = 0.5 * (1.0 - cos(
TWO_PI * (
double(j) /
double(beatlen))));
222 oldspec[j] = newspec[j];
229 if (timesig == 0) timesig = 4;
233 for (
int beat = 0; beat < timesig; ++beat) {
238 for (
int beat = 0; beat < timesig; ++beat) {
240 for (
int example = beat-1; example < (int)
m_beatsd.size(); example += timesig) {
241 if (example < 0)
continue;
242 dbcand[beat] += (
m_beatsd[example]) / timesig;
245 if (count > 0) dbcand[beat] /= count;
253 for (
int i = dbind; i < (int)beats.size(); i += timesig) {
254 downbeats.push_back(i);
263 unsigned int SPECSIZE = 512;
264 if (SPECSIZE > oldspec.size()/4) {
265 SPECSIZE = oldspec.size()/4;
273 for (
unsigned int i = 0;i < SPECSIZE;i++)
282 for (
unsigned int i = 0;i < SPECSIZE;i++)
284 newspec[i] /= (sumnew);
285 oldspec[i] /= (sumold);
299 sd1 = 0.5*oldspec[i] + 0.5*newspec[i];
300 SD = SD + (-sd1*log(sd1)) + (0.5*(oldspec[i]*log(oldspec[i]))) + (0.5*(newspec[i]*log(newspec[i])));
309 for (
int i = 0; i < (int)
m_beatsd.size(); ++i) beatsd.push_back(
m_beatsd[i]);
Decimator carries out a fast downsample by a power-of-two factor.
static int getHighestSupportedFactor()
void process(const double *src, double *dst)
Process inLength samples (as supplied to constructor) from src and write inLength / decFactor samples...
DownBeat(float originalSampleRate, size_t decimationFactor, size_t dfIncrement)
Construct a downbeat locator that will operate on audio at the downsampled by the given decimation fa...
const float * getBufferedAudio(size_t &length) const
Retrieve the accumulated audio produced by pushAudioBlock calls.
void pushAudioBlock(const float *audio)
For your downsampling convenience: call this function repeatedly with input audio blocks containing d...
void getBeatSD(vector< double > &beatsd) const
Return the beat spectral difference function.
void findDownBeats(const float *audio, size_t audioLength, const vector< double > &beats, vector< int > &downbeats)
Estimate which beats are down-beats.
void setBeatsPerBar(int bpb)
double measureSpecDiff(d_vec_t oldspec, d_vec_t newspec)
void resetAudioBuffer()
Clear any buffered downsampled audio data.
void forward(const double *realIn, double *realOut, double *imagOut)
Carry out a forward real-to-complex transform of size nsamples, where nsamples is the value provided ...
static int nextPowerOfTwo(int x)
Return the next higher integer power of two from x, e.g.
static void adaptiveThreshold(std::vector< double > &data)
Threshold the input/output vector data against a moving-mean average filter.
static int getMax(double *data, unsigned int length, double *max=0)