Open loretoparisi opened 10 years ago
I realized that the calculation should be done for each buffer:
while (inFile->eof() == 0)
{
// ....
for(int i=0;i<samples;i++) {
float fSample = output[ i ] / 32768.0f;
floatVect->push_back(fSample);
}
bpmDetect->process((*inFile).getElapsedMS(), *floatVect);
// ....
}
bpm = bpmDetect->winning_bpm;
bpmDetect->reset();
The problem is the same in this case too, bpm = 0
Could it be a buffer problem with the
std::vector<float> floatVect[BUFF_SIZE];
I can't tell from your code what the overall process before the detection is and whether you've cleared the floatVect, what the FFT output is, etc.. but I'll outline the basic idea as reference for everyone.
The input is the current FFT frame, and you'll want to keep the symmetry (don't just take half of the fft result array -- explanation for that is enough for another discussion though) and the time at which it was sampled from.
If you're processing an audio file you'll need to choose your frame rate so that you get enough quality FFT frames per second for your sample rate. For this example we'll assume a function exists that does that called getSamplesBySeconds, which at 29.4 fps for 44100hz would give us 1500 samples per frame.
Some basic pseudo-code for that process is:
timer = 0;
frames_per_second = 29.4;
while (samplesAvailable()) {
// get a second worth of samples
samples = getSamplesBySeconds(1 / frames_per_second);
// get full FFT frame for this sample
fft = getFFT(samples);
// run BeatDetektor
bpmDetect->process(timer, fft);
timer += 1 / frames_per_second; // increment timer
}
I have a wave file. I go through 1025 bytes samples and read the wav
The resulting bpm is always bpm = 0.
Is that right to accumulate the float samples from the FFT and then pass the vector to the process() method with the wav duration expressed in seconds ?