diff src/OnsetDetectionFunction.cpp @ 64:d3c52c6b3905

Changed all pointers to arrays in OnsetDetectionFunction into vectors
author Adam Stark <adamstark@users.noreply.github.com>
date Tue, 28 Jan 2014 00:19:21 +0000
parents ba3fc238ccad
children bddd59087c36
line wrap: on
line diff
--- a/src/OnsetDetectionFunction.cpp	Mon Jan 27 23:54:18 2014 +0000
+++ b/src/OnsetDetectionFunction.cpp	Tue Jan 28 00:19:21 2014 +0000
@@ -26,7 +26,7 @@
 OnsetDetectionFunction::OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType)
 {	
 	// indicate that we have not initialised yet
-	initialised = 0;		
+	initialised = false;
 	
 	// set pi
 	pi = 3.14159265358979;	
@@ -39,61 +39,25 @@
 //=======================================================================
 OnsetDetectionFunction::~OnsetDetectionFunction()
 {
-	// destroy fft plan
-    fftw_destroy_plan(p);
-	fftw_free(complexIn);
-	fftw_free(complexOut);
-	
-	// deallocate memory
-	delete [] frame;
-	frame = NULL;	
-	delete [] window;
-	window = NULL;
-	delete [] magSpec;
-	magSpec = NULL;
-	delete [] prevMagSpec;
-	prevMagSpec = NULL;
-	delete [] phase;
-	phase = NULL;
-	delete [] prevPhase;
-	prevPhase = NULL;
-	delete [] prevPhase2;
-	prevPhase2 = NULL;
+    if (initialised)
+    {
+        // destroy fft plan
+        fftw_destroy_plan(p);
+        fftw_free(complexIn);
+        fftw_free(complexOut);
+    }
 }
 
 //=======================================================================
 void OnsetDetectionFunction::initialise(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType)
 {
-	if (initialised == 1) // if we have already initialised some buffers and an FFT plan
+	if (initialised) // if we have already initialised FFT plan
 	{
-		//////////////////////////////////
-		// TIDY UP FIRST - If initialise is called after the class has been initialised
-		// then we want to free up memory and cancel existing FFT plans
-	
 		// destroy fft plan
 		fftw_destroy_plan(p);
 		fftw_free(complexIn);
 		fftw_free(complexOut);
-	
-	
-		// deallocate memory
-		delete [] frame;
-		frame = NULL;	
-		delete [] window;
-		window = NULL;									
-		delete [] magSpec;
-		magSpec = NULL;
-		delete [] prevMagSpec;
-		prevMagSpec = NULL;
-		delete [] phase;
-		phase = NULL;
-		delete [] prevPhase;
-		prevPhase = NULL;
-		delete [] prevPhase2;
-		prevPhase2 = NULL;
-	
-		////// END TIDY UP ///////////////
-		//////////////////////////////////
+
 	}
 	
 	hopSize = hopSize_; // set hopsize
@@ -102,15 +66,13 @@
 	onsetDetectionFunctionType = onsetDetectionFunctionType_; // set detection function type
 		
 	// initialise buffers
-	frame = new double[frameSize];
-	window = new double[frameSize];
-	
-	magSpec = new double[frameSize];
-	prevMagSpec = new double[frameSize];
-	
-	phase = new double[frameSize];
-	prevPhase = new double[frameSize];
-	prevPhase2 = new double[frameSize];
+    frame.resize(frameSize);
+    window.resize(frameSize);
+    magSpec.resize(frameSize);
+    prevMagSpec.resize(frameSize);
+    phase.resize(frameSize);
+    prevPhase.resize(frameSize);
+    prevPhase2.resize(frameSize);
 	
 	
 	// set the window to the specified type
@@ -134,9 +96,6 @@
 			calculateHanningWindow();			// DEFAULT: Hanning Window
 	}
 	
-	
-	
-	
 	// initialise previous magnitude spectrum to zero
 	for (int i = 0;i < frameSize;i++)
 	{
@@ -153,7 +112,7 @@
 	complexOut = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * frameSize);	// complex array to hold fft data
 	p = fftw_plan_dft_1d(frameSize, complexIn, complexOut, FFTW_FORWARD, FFTW_ESTIMATE);	// FFT plan initialisation
 	
-	initialised = 1;
+	initialised = true;
 }
 
 //=======================================================================