diff options
author | Underground78 <underground78@users.sourceforge.net> | 2011-08-11 01:56:33 +0400 |
---|---|---|
committer | Underground78 <underground78@users.sourceforge.net> | 2011-08-11 01:56:33 +0400 |
commit | 24fc79bfb297d24b091e6950f9277edfe9e88c84 (patch) | |
tree | f9aa2d75218296ce904ffb68c36b2462a67fa1bf /src/thirdparty/SoundTouch/source/BPMDetect.cpp | |
parent | 9c37b8ef1e0ee7e34b4640255c941c52d9387386 (diff) |
Update SoundTouch to v1.6.1pre r130 (vanilla except that MMX is disabled for x64 to fix compilation). Patch by XhmikosR.
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@3642 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/thirdparty/SoundTouch/source/BPMDetect.cpp')
-rw-r--r-- | src/thirdparty/SoundTouch/source/BPMDetect.cpp | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/thirdparty/SoundTouch/source/BPMDetect.cpp b/src/thirdparty/SoundTouch/source/BPMDetect.cpp index 4faa29409..8b3d1c601 100644 --- a/src/thirdparty/SoundTouch/source/BPMDetect.cpp +++ b/src/thirdparty/SoundTouch/source/BPMDetect.cpp @@ -57,6 +57,7 @@ #include <math.h>
#include <assert.h>
#include <string.h>
+#include <stdio.h>
#include "FIFOSampleBuffer.h"
#include "PeakFinder.h"
#include "BPMDetect.h"
@@ -74,6 +75,37 @@ const float avgdecay = 0.99986f; 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)
{
@@ -326,8 +358,14 @@ void BPMDetect::inputSamples(const SAMPLETYPE *samples, int numSamples) float BPMDetect::getBpm()
{
double peakPos;
+ double coeff;
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
peakPos = peakFinder.detectPeak(xcorr, windowStart, windowLen);
@@ -335,5 +373,5 @@ float BPMDetect::getBpm() if (peakPos < 1e-9) return 0.0; // detection failed.
// calculate BPM
- return (float)(60.0 * (((double)sampleRate / (double)decimateBy) / peakPos));
+ return (float) (coeff / peakPos);
}
|