mirror of
https://github.com/azahar-emu/soundtouch
synced 2025-11-07 15:40:04 +01:00
Added support for writing bpm analysis debug file
This commit is contained in:
parent
d002b52f2a
commit
1043811c6b
@ -57,6 +57,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "FIFOSampleBuffer.h"
|
#include "FIFOSampleBuffer.h"
|
||||||
#include "PeakFinder.h"
|
#include "PeakFinder.h"
|
||||||
#include "BPMDetect.h"
|
#include "BPMDetect.h"
|
||||||
@ -74,6 +75,37 @@ const float avgdecay = 0.99986f;
|
|||||||
const float avgnorm = (1 - avgdecay);
|
const float avgnorm = (1 - avgdecay);
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Enable following define to create bpm analysis file:
|
||||||
|
|
||||||
|
// #define _CREATE_BPM_DEBUG_FILE
|
||||||
|
|
||||||
|
#ifdef _CREATE_BPM_DEBUG_FILE
|
||||||
|
|
||||||
|
#define DEBUGFILE_NAME "c:\\temp\\soundtouch-bpm-debug.txt"
|
||||||
|
|
||||||
|
static void _SaveDebugData(const float *data, int minpos, int maxpos, double coeff)
|
||||||
|
{
|
||||||
|
FILE *fptr = fopen(DEBUGFILE_NAME, "wt");
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (fptr)
|
||||||
|
{
|
||||||
|
printf("\n\nWriting BPM debug data into file " DEBUGFILE_NAME "\n\n");
|
||||||
|
for (i = minpos; i < maxpos; i ++)
|
||||||
|
{
|
||||||
|
fprintf(fptr, "%d\t%.1lf\t%f\n", i, coeff / (double)i, data[i]);
|
||||||
|
}
|
||||||
|
fclose(fptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define _SaveDebugData(a,b,c,d)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
BPMDetect::BPMDetect(int numChannels, int aSampleRate)
|
BPMDetect::BPMDetect(int numChannels, int aSampleRate)
|
||||||
{
|
{
|
||||||
@ -326,8 +358,14 @@ void BPMDetect::inputSamples(const SAMPLETYPE *samples, int numSamples)
|
|||||||
float BPMDetect::getBpm()
|
float BPMDetect::getBpm()
|
||||||
{
|
{
|
||||||
double peakPos;
|
double peakPos;
|
||||||
|
double coeff;
|
||||||
PeakFinder peakFinder;
|
PeakFinder peakFinder;
|
||||||
|
|
||||||
|
coeff = 60.0 * ((double)sampleRate / (double)decimateBy);
|
||||||
|
|
||||||
|
// save bpm debug analysis data if debug data enabled
|
||||||
|
_SaveDebugData(xcorr, windowStart, windowLen, coeff);
|
||||||
|
|
||||||
// find peak position
|
// find peak position
|
||||||
peakPos = peakFinder.detectPeak(xcorr, windowStart, windowLen);
|
peakPos = peakFinder.detectPeak(xcorr, windowStart, windowLen);
|
||||||
|
|
||||||
@ -335,5 +373,5 @@ float BPMDetect::getBpm()
|
|||||||
if (peakPos < 1e-9) return 0.0; // detection failed.
|
if (peakPos < 1e-9) return 0.0; // detection failed.
|
||||||
|
|
||||||
// calculate BPM
|
// calculate BPM
|
||||||
return (float)(60.0 * (((double)sampleRate / (double)decimateBy) / peakPos));
|
return (float) (coeff / peakPos);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user