Proper Beat detection with AudioTrigger

Post Reply
phoz
Posts: 6
Joined: Mon Apr 11, 2016 4:02 pm
Real Name: Toon SMits

I propose the audio trigger is changed from the currently implemented Schmitt trigger.

A better implementation is to use a a sound energy algorithm where the instant sound energy is compared to the average sound energy.
This link gives a good description on how to detect a beat.

I have looked at the source of current audio trigger and not much modification is needed.
phoz
Posts: 6
Joined: Mon Apr 11, 2016 4:02 pm
Real Name: Toon SMits

I have trouble finding identifying parts of the AudioTrigger.
But where it could be added is at AudioBar::checkWidgetFunctionality() and the AudioBar object/class.

For each subband a register should be assigned that keeps the last values.

Code: Select all

// Initialise
private int pos = 0;
private double *register = new double[registerSize];
private double average = 0;
// Variables that could be changed
private int registerSize = 43;
private double C = 150.0, V = 250.0;

// write all zeros to register

//Example in 
//AudioBar::checkWidgetFunctionality()
// m_value is the new value coming from the audiocapture class
// average contains the average energy of the window
// register[pos] is the oldest  value in the window
average += (m_value - register[pos]) / registerSize;
register[pos] = m_value;
pos = (pos+1)%registerSize;
bool beat = m_value > C * average;


// additional extra check is to use the variance.
double variance = 0;
for(int i = 0; i < registerSize;i++){
	variance +=  (register[i] - average)*(register[i] - average);
}

//then your beat check would be
bool beat = (m_value > C * average) && (variance > V) ;
User could change the C value, the variance threshold V, the size of the memory or the size of the audiocapture window.
phoz
Posts: 6
Joined: Mon Apr 11, 2016 4:02 pm
Real Name: Toon SMits

It is possible to drop that for loop.

Code: Select all

// Initialise
private int pos = 0;
private double *register = new double[registerSize];
private double average = 0.0;
private double sum = 0.0;
// Variables that could be changed
private int registerSize = 43;
private double C = 150.0, V = 250.0;

// write all zeros to register

//Example in 
//AudioBar::checkWidgetFunctionality()
// m_value is the new value coming from the audiocapture class
// average contains the average energy of the window
// sum containt the average of the energy²
// register[pos] is the oldest  value in the window

average += (m_value - register[pos]) / registerSize;
sum += (m_value * m_value - register[pos] * register[pos]) / registerSize

// updating register
register[pos] = m_value;
pos = (pos+1)%registerSize;

bool beat = (m_value > C * average) && (sum - average* average > V) ;
User avatar
mcallegari
Posts: 4711
Joined: Sun Apr 12, 2015 9:09 am
Location: Italy
Real Name: Massimo Callegari
Contact:

Moved to the software development section.

I'll have a look at your observations when I have some time. Thanks
phoz
Posts: 6
Joined: Mon Apr 11, 2016 4:02 pm
Real Name: Toon SMits

I have added the lines to audiobar.cpp but I having issues.

Audiobar objects only get int values between 0 - 255. A lot of information is lost.
I probably need to reduce the windows of the AudioCapture class. Where is this AUDIO_DEFAULT_BUFFER_SIZE located?

Code: Select all

// audiocapture.cpp
int bufferSize = AUDIO_DEFAULT_BUFFER_SIZE;
janosvitok
Posts: 1325
Joined: Mon Apr 13, 2015 7:05 am
Location: Bratislava, Slovakia
Real Name: Jano Svitok
Contact:

phoz,

I keep (update from time to time) doxygen-generated source documentation at http://qlcplus.zvukari.sk/doxygen You can browse classes
and methods and also go to their definition. The constant is documented here: http://qlcplus.zvukari.sk/doxygen/df/db ... ac632e19c1

You may create the same documentation on your hdd:

- install doxygen (http://doxygen.org or apt-get install doxygen) and graphviz (for class diagrams; http://www.graphviz.org/ or apt-get install graphviz)
- go to doxygen dir in qlc+ source tree
- run doxygen qlcplus.dox
- go to doxygen/html and open index.html
phoz
Posts: 6
Joined: Mon Apr 11, 2016 4:02 pm
Real Name: Toon SMits

I am currently using netbeans which also has all those functions?

I just can't seem to find those variables. Not even in the make files.
janosvitok
Posts: 1325
Joined: Mon Apr 13, 2015 7:05 am
Location: Bratislava, Slovakia
Real Name: Jano Svitok
Contact:

phoz
Posts: 6
Joined: Mon Apr 11, 2016 4:02 pm
Real Name: Toon SMits

My bad, thank you
Post Reply