changeset 87:496d12635af8

Merge branch 'release/1.0.3'
author Adam Stark <adamstark.uk@gmail.com>
date Sun, 10 Jan 2016 11:36:52 +0000
parents 3b69082715ea (current diff) 5eeabb24d677 (diff)
children c58f01834337
files README.md
diffstat 4 files changed, 35 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/.gitignore	Tue Nov 25 23:00:13 2014 +0000
+++ b/.gitignore	Sun Jan 10 11:36:52 2016 +0000
@@ -8,4 +8,5 @@
 
 *.xcworkspace
 
-modules-and-plug-ins/max-external/build
\ No newline at end of file
+modules-and-plug-ins/max-external/build
+modules-and-plug-ins/python-module/build
\ No newline at end of file
--- a/README.md	Tue Nov 25 23:00:13 2014 +0000
+++ b/README.md	Sun Jan 10 11:36:52 2016 +0000
@@ -1,7 +1,7 @@
 BTrack - A Real-Time Beat Tracker
 =================================
 
-** Version 1.0.2 **
+** Version 1.0.3 **
 
 *by Adam Stark, Matthew Davies and Mark Plumbley.*
 
@@ -22,6 +22,11 @@
 Versions
 --------
 
+==== 1.0.3 ==== (10th January 2016)
+
+* Fixed implementation error in complex spectral difference (thanks to @zbanks for pointing it out)
+* Small change to python module build script
+
 ==== 1.0.2 ==== (25th November 2014)
 
 * Added updated Max external project and associated files
--- a/modules-and-plug-ins/python-module/setup.py	Tue Nov 25 23:00:13 2014 +0000
+++ b/modules-and-plug-ins/python-module/setup.py	Sun Jan 10 11:36:52 2016 +0000
@@ -12,5 +12,5 @@
 
 setup( name = 'BTrack',
       include_dirs = include_dirs,
-      ext_modules = [Extension(name, sources,libraries = ['fftw3','samplerate'])]
+      ext_modules = [Extension(name, sources,libraries = ['fftw3','samplerate'],library_dirs = ['/usr/local/lib'])]
       )
\ No newline at end of file
--- a/src/OnsetDetectionFunction.cpp	Tue Nov 25 23:00:13 2014 +0000
+++ b/src/OnsetDetectionFunction.cpp	Sun Jan 10 11:36:52 2016 +0000
@@ -435,10 +435,9 @@
 //=======================================================================
 double OnsetDetectionFunction :: complexSpectralDifference()
 {
-	double dev,pdev;
+	double phaseDeviation;
 	double sum;
-	double mag_diff,phase_diff;
-	double value;
+	double csd;
 	
 	// perform the FFT
 	performFFT();
@@ -454,29 +453,14 @@
 		// calculate magnitude value
 		magSpec[i] = sqrt(pow(complexOut[i][0],2) + pow(complexOut[i][1],2));
 		
+		// phase deviation
+		phaseDeviation = phase[i] - (2*prevPhase[i]) + prevPhase2[i];
 		
-		// phase deviation
-		dev = phase[i] - (2*prevPhase[i]) + prevPhase2[i];
-		
-		// wrap into [-pi,pi] range
-		pdev = princarg(dev);	
-		
-		
-		// calculate magnitude difference (real part of Euclidean distance between complex frames)
-		mag_diff = magSpec[i] - prevMagSpec[i];
-		
-		// calculate phase difference (imaginary part of Euclidean distance between complex frames)
-		phase_diff = -magSpec[i]*sin(pdev);
-		
-
-		
-		// square real and imaginary parts, sum and take square root
-		value = sqrt(pow(mag_diff,2) + pow(phase_diff,2));
-	
+        // calculate complex spectral difference for the current spectral bin
+		csd = sqrt(pow(magSpec[i], 2) + pow(prevMagSpec[i], 2) - 2 * magSpec[i] * prevMagSpec[i] * cos(phaseDeviation));
 			
 		// add to sum
-		sum = sum + value;
-		
+		sum = sum + csd;
 		
 		// store values for next calculation
 		prevPhase2[i] = prevPhase[i];
@@ -490,10 +474,10 @@
 //=======================================================================
 double OnsetDetectionFunction :: complexSpectralDifferenceHWR()
 {
-	double dev,pdev;
+	double phaseDeviation;
 	double sum;
-	double mag_diff,phase_diff;
-	double value;
+	double magnitudeDifference;
+	double csd;
 	
 	// perform the FFT
 	performFFT();
@@ -509,30 +493,22 @@
 		// calculate magnitude value
 		magSpec[i] = sqrt(pow(complexOut[i][0],2) + pow(complexOut[i][1],2));
 		
-		
-		// phase deviation
-		dev = phase[i] - (2*prevPhase[i]) + prevPhase2[i];
-		
-		// wrap into [-pi,pi] range
-		pdev = princarg(dev);	
-		
-		
-		// calculate magnitude difference (real part of Euclidean distance between complex frames)
-		mag_diff = magSpec[i] - prevMagSpec[i];
-		
-		// if we have a positive change in magnitude, then include in sum, otherwise ignore (half-wave rectification)
-		if (mag_diff > 0)
-		{
-			// calculate phase difference (imaginary part of Euclidean distance between complex frames)
-			phase_diff = -magSpec[i]*sin(pdev);
-
-			// square real and imaginary parts, sum and take square root
-			value = sqrt(pow(mag_diff,2) + pow(phase_diff,2));
-		
-			// add to sum
-			sum = sum + value;
-		}
-		
+        // phase deviation
+        phaseDeviation = phase[i] - (2*prevPhase[i]) + prevPhase2[i];
+        
+        // calculate magnitude difference (real part of Euclidean distance between complex frames)
+        magnitudeDifference = magSpec[i] - prevMagSpec[i];
+        
+        // if we have a positive change in magnitude, then include in sum, otherwise ignore (half-wave rectification)
+        if (magnitudeDifference > 0)
+        {
+            // calculate complex spectral difference for the current spectral bin
+            csd = sqrt(pow(magSpec[i], 2) + pow(prevMagSpec[i], 2) - 2 * magSpec[i] * prevMagSpec[i] * cos(phaseDeviation));
+        
+            // add to sum
+            sum = sum + csd;
+        }
+        
 		// store values for next calculation
 		prevPhase2[i] = prevPhase[i];
 		prevPhase[i] = phase[i];