TracktionEngine
Loading...
Searching...
No Matches
engine::soundtouch::BPMDetect Class Reference

Class for calculating BPM rate for audio data. More...

#include <tracktion_TempoDetect.h>

Public Member Functions

 BPMDetect (int numChannels, int sampleRate)
 Constructor.
virtual ~BPMDetect ()
 Destructor.
void inputSamples (const soundtouch::SAMPLETYPE *samples, int numSamples)
 Inputs a block of samples for analyzing: Envelopes the samples and then updates the autocorrelation estimation.
float getBpm ()
 Analyzes the results and returns the BPM rate.
int getBeats (float *pos, float *strength, int max_num)
 Get beat position arrays.

Protected Member Functions

void updateXCorr (int process_samples)
 Updates auto-correlation function for given number of decimated samples that are read from the internal 'buffer' pipe (samples aren't removed from the pipe though).
int decimate (soundtouch::SAMPLETYPE *dest, const soundtouch::SAMPLETYPE *src, int numsamples)
 Decimates samples to approx.
void calcEnvelope (soundtouch::SAMPLETYPE *samples, int numsamples)
 Calculates amplitude envelope for the buffer of samples.
void removeBias ()
 remove constant bias from xcorr data
void updateBeatPos (int process_samples)

Protected Attributes

float * xcorr
 Auto-correlation accumulator bins.
int decimateCount
 Sample average counter.
soundtouch::LONG_SAMPLETYPE decimateSum
 Sample average accumulator for FIFO-like decimation.
int decimateBy
 Decimate sound by this coefficient to reach approx. 500 Hz.
int windowLen
 Auto-correlation window length.
int channels
 Number of channels (1 = mono, 2 = stereo).
int sampleRate
 sample rate
int windowStart
 Beginning of auto-correlation window: Autocorrelation isn't being updated for the first these many correlation bins.
float * hamw
 window functions for data preconditioning
float * hamw2
int pos
int peakPos
int beatcorr_ringbuffpos
int init_scaler
float peakVal
float * beatcorr_ringbuff
soundtouch::FIFOSampleBuffer * buffer
 FIFO-buffer for decimated processing samples.
std::vector< BEAT > beats
 Collection of detected beat positions.
IIR2_filter beat_lpf

Detailed Description

Class for calculating BPM rate for audio data.

Constructor & Destructor Documentation

◆ BPMDetect()

engine::soundtouch::BPMDetect::BPMDetect ( int numChannels,
int sampleRate )

Constructor.

Parameters
numChannelsNumber of channels in sample data.
sampleRateSample rate in Hz.

◆ ~BPMDetect()

virtual engine::soundtouch::BPMDetect::~BPMDetect ( )
virtual

Destructor.

Member Function Documentation

◆ updateXCorr()

void engine::soundtouch::BPMDetect::updateXCorr ( int process_samples)
protected

Updates auto-correlation function for given number of decimated samples that are read from the internal 'buffer' pipe (samples aren't removed from the pipe though).

Parameters
process_samplesHow many samples are processed.

◆ decimate()

int engine::soundtouch::BPMDetect::decimate ( soundtouch::SAMPLETYPE * dest,
const soundtouch::SAMPLETYPE * src,
int numsamples )
protected

Decimates samples to approx.

500 Hz.

Returns
Number of output samples.
Parameters
destDestination buffer
srcSource sample buffer
numsamplesNumber of source samples.

◆ calcEnvelope()

void engine::soundtouch::BPMDetect::calcEnvelope ( soundtouch::SAMPLETYPE * samples,
int numsamples )
protected

Calculates amplitude envelope for the buffer of samples.

Result is output to 'samples'.

Parameters
samplesPointer to input/output data buffer
numsamplesNumber of samples in buffer

◆ removeBias()

void engine::soundtouch::BPMDetect::removeBias ( )
protected

remove constant bias from xcorr data

◆ updateBeatPos()

void engine::soundtouch::BPMDetect::updateBeatPos ( int process_samples)
protected

◆ inputSamples()

void engine::soundtouch::BPMDetect::inputSamples ( const soundtouch::SAMPLETYPE * samples,
int numSamples )

Inputs a block of samples for analyzing: Envelopes the samples and then updates the autocorrelation estimation.

When whole song data has been input in smaller blocks using this function, read the resulting bpm with 'getBpm' function.

Notice that data in 'samples' array can be disrupted in processing.

Parameters
samplesPointer to input/working data buffer
numSamplesNumber of samples in buffer

◆ getBpm()

float engine::soundtouch::BPMDetect::getBpm ( )

Analyzes the results and returns the BPM rate.

Use this function to read result after whole song data has been input to the class by consecutive calls of 'inputSamples' function.

Returns
Beats-per-minute rate, or zero if detection failed.

◆ getBeats()

int engine::soundtouch::BPMDetect::getBeats ( float * pos,
float * strength,
int max_num )

Get beat position arrays.

Note: The array includes also really low beat detection values in absence of clear strong beats. Consumer may wish to filter low values away.

  • "pos" receive array of beat positions
  • "values" receive array of beat detection strengths
  • max_num indicates max.size of "pos" and "values" array.

You can query a suitable array sized by calling this with NULL in "pos" & "values".

Returns
number of beats in the arrays.

Member Data Documentation

◆ xcorr

float* engine::soundtouch::BPMDetect::xcorr
protected

Auto-correlation accumulator bins.

◆ decimateCount

int engine::soundtouch::BPMDetect::decimateCount
protected

Sample average counter.

◆ decimateSum

soundtouch::LONG_SAMPLETYPE engine::soundtouch::BPMDetect::decimateSum
protected

Sample average accumulator for FIFO-like decimation.

◆ decimateBy

int engine::soundtouch::BPMDetect::decimateBy
protected

Decimate sound by this coefficient to reach approx. 500 Hz.

◆ windowLen

int engine::soundtouch::BPMDetect::windowLen
protected

Auto-correlation window length.

◆ channels

int engine::soundtouch::BPMDetect::channels
protected

Number of channels (1 = mono, 2 = stereo).

◆ sampleRate

int engine::soundtouch::BPMDetect::sampleRate
protected

sample rate

◆ windowStart

int engine::soundtouch::BPMDetect::windowStart
protected

Beginning of auto-correlation window: Autocorrelation isn't being updated for the first these many correlation bins.

◆ hamw

float* engine::soundtouch::BPMDetect::hamw
protected

window functions for data preconditioning

◆ hamw2

float* engine::soundtouch::BPMDetect::hamw2
protected

◆ pos

int engine::soundtouch::BPMDetect::pos
protected

◆ peakPos

int engine::soundtouch::BPMDetect::peakPos
protected

◆ beatcorr_ringbuffpos

int engine::soundtouch::BPMDetect::beatcorr_ringbuffpos
protected

◆ init_scaler

int engine::soundtouch::BPMDetect::init_scaler
protected

◆ peakVal

float engine::soundtouch::BPMDetect::peakVal
protected

◆ beatcorr_ringbuff

float* engine::soundtouch::BPMDetect::beatcorr_ringbuff
protected

◆ buffer

soundtouch::FIFOSampleBuffer* engine::soundtouch::BPMDetect::buffer
protected

FIFO-buffer for decimated processing samples.

◆ beats

std::vector<BEAT> engine::soundtouch::BPMDetect::beats
protected

Collection of detected beat positions.

◆ beat_lpf

IIR2_filter engine::soundtouch::BPMDetect::beat_lpf
protected

The documentation for this class was generated from the following file: