Page 1 of 1
Proper Beat detection with AudioTrigger
Posted: Sun Apr 17, 2016 10:28 pm
by phoz
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.
Re: Proper Beat detection with AudioTrigger
Posted: Mon Apr 18, 2016 1:37 am
by phoz
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.
Re: Proper Beat detection with AudioTrigger
Posted: Mon Apr 18, 2016 1:57 am
by phoz
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) ;
Re: Proper Beat detection with AudioTrigger
Posted: Mon Apr 18, 2016 8:30 am
by mcallegari
Moved to the software development section.
I'll have a look at your observations when I have some time. Thanks
Re: Proper Beat detection with AudioTrigger
Posted: Mon Apr 18, 2016 2:44 pm
by phoz
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;
Re: Proper Beat detection with AudioTrigger
Posted: Mon Apr 18, 2016 7:30 pm
by janosvitok
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
Re: Proper Beat detection with AudioTrigger
Posted: Mon Apr 18, 2016 9:55 pm
by phoz
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.
Re: Proper Beat detection with AudioTrigger
Posted: Tue Apr 19, 2016 5:12 am
by janosvitok
Re: Proper Beat detection with AudioTrigger
Posted: Tue Apr 19, 2016 7:46 am
by phoz
My bad, thank you