changeset 66:b387d8327729

Overloaded initialise in OnsetDetectionFunction so the hopSize and frameSize can be set independently of the window type and onset detection function type
author Adam Stark <adamstark@users.noreply.github.com>
date Tue, 28 Jan 2014 00:49:53 +0000
parents 105999275c2e
children ae3ec9b14092
files src/BTrack.cpp src/OnsetDetectionFunction.cpp src/OnsetDetectionFunction.h
diffstat 3 files changed, 45 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/BTrack.cpp	Tue Jan 28 00:31:17 2014 +0000
+++ b/src/BTrack.cpp	Tue Jan 28 00:49:53 2014 +0000
@@ -152,7 +152,7 @@
 void BTrack::updateHopAndFrameSize(int hopSize_,int frameSize_)
 {
     // update the onset detection function object
-    odf.initialise(hopSize_, frameSize_, ComplexSpectralDifferenceHWR, HanningWindow);
+    odf.initialise(hopSize_, frameSize_);
     
     // update the hop size being used by the beat tracker
     setHopSize(hopSize_);
--- a/src/OnsetDetectionFunction.cpp	Tue Jan 28 00:31:17 2014 +0000
+++ b/src/OnsetDetectionFunction.cpp	Tue Jan 28 00:49:53 2014 +0000
@@ -22,8 +22,22 @@
 #include <math.h>
 #include "OnsetDetectionFunction.h"
 
+
 //=======================================================================
-OnsetDetectionFunction::OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType)
+OnsetDetectionFunction::OnsetDetectionFunction(int hopSize_,int frameSize_) : onsetDetectionFunctionType(ComplexSpectralDifferenceHWR), windowType(HanningWindow)
+{
+    // indicate that we have not initialised yet
+	initialised = false;
+	
+	// set pi
+	pi = 3.14159265358979;
+	
+	// initialise with arguments to constructor
+	initialise(hopSize_,frameSize_,ComplexSpectralDifferenceHWR,HanningWindow);
+}
+
+//=======================================================================
+OnsetDetectionFunction::OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType_) : onsetDetectionFunctionType(ComplexSpectralDifferenceHWR), windowType(HanningWindow)
 {	
 	// indicate that we have not initialised yet
 	initialised = false;
@@ -32,7 +46,7 @@
 	pi = 3.14159265358979;	
 	
 	// initialise with arguments to constructor
-	initialise(hopSize_,frameSize_,onsetDetectionFunctionType_,windowType);
+	initialise(hopSize_,frameSize_,onsetDetectionFunctionType_,windowType_);
 }
 
 
@@ -49,7 +63,15 @@
 }
 
 //=======================================================================
-void OnsetDetectionFunction::initialise(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType)
+void OnsetDetectionFunction::initialise(int hopSize_,int frameSize_)
+{
+    // use the already initialised onset detection function and window type and
+    // pass the new frame and hop size to the main initialisation function
+    initialise(hopSize_, frameSize_, onsetDetectionFunctionType, windowType);
+}
+
+//=======================================================================
+void OnsetDetectionFunction::initialise(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType_)
 {
 	if (initialised) // if we have already initialised FFT plan
 	{
@@ -64,6 +86,7 @@
 	frameSize = frameSize_; // set framesize
 	
 	onsetDetectionFunctionType = onsetDetectionFunctionType_; // set detection function type
+    windowType = windowType_; // set window type
 		
 	// initialise buffers
     frame.resize(frameSize);
--- a/src/OnsetDetectionFunction.h	Tue Jan 28 00:31:17 2014 +0000
+++ b/src/OnsetDetectionFunction.h	Tue Jan 28 00:49:53 2014 +0000
@@ -58,24 +58,39 @@
 {
 public:
     
+    /** Constructor that defaults the onset detection function type to ComplexSpectralDifferenceHWR
+     * and the window type to HanningWindow
+     * @param hopSize_ the hop size in audio samples
+     * @param frameSize_ the frame size in audio samples
+     */
+	OnsetDetectionFunction(int hopSize_,int frameSize_);
+    
+    
     /** Constructor 
      * @param hopSize_ the hop size in audio samples
      * @param frameSize_ the frame size in audio samples
      * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType)
      * @param windowType the type of window to use (see WindowType)
      */
-	OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
+	OnsetDetectionFunction(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType_);
     
     /** Destructor */
 	~OnsetDetectionFunction();
     
+    /** Initialisation function for only updating hop size and frame size (and not window type 
+     * or onset detection function type
+     * @param hopSize_ the hop size in audio samples
+     * @param frameSize_ the frame size in audio samples
+     */
+	void initialise(int hopSize_,int frameSize_);
+    
     /** Initialisation Function 
      * @param hopSize_ the hop size in audio samples
      * @param frameSize_ the frame size in audio samples
      * @param onsetDetectionFunctionType_ the type of onset detection function to use - (see OnsetDetectionFunctionType)
      * @param windowType the type of window to use (see WindowType)
      */
-	void initialise(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType);
+	void initialise(int hopSize_,int frameSize_,int onsetDetectionFunctionType_,int windowType_);
 	
     /** Process input frame and calculate detection function sample 
      * @param buffer a pointer to an array containing the audio samples to be processed
@@ -153,6 +168,7 @@
 	int frameSize;						/**< audio framesize */
 	int hopSize;						/**< audio hopsize */
 	int onsetDetectionFunctionType;		/**< type of detection function */
+    int windowType;                     /**< type of window used in calculations */
 	
 	fftw_plan p;						/**< fftw plan */
 	fftw_complex *complexIn;			/**< to hold complex fft values for input */