Mercurial > hg > btrack
changeset 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 | 1395895f6cdf |
children | 105999275c2e |
files | src/OnsetDetectionFunction.cpp src/OnsetDetectionFunction.h |
diffstat | 2 files changed, 27 insertions(+), 67 deletions(-) [+] |
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; } //=======================================================================
--- a/src/OnsetDetectionFunction.h Mon Jan 27 23:54:18 2014 +0000 +++ b/src/OnsetDetectionFunction.h Tue Jan 28 00:19:21 2014 +0000 @@ -23,6 +23,7 @@ #define __ONSETDETECTIONFUNCTION_H #include "fftw3.h" +#include <vector> //======================================================================= /** The type of onset detection function to calculate */ @@ -157,19 +158,19 @@ fftw_complex *complexIn; /**< to hold complex fft values for input */ fftw_complex *complexOut; /**< to hold complex fft values for output */ - int initialised; /**< flag indicating whether buffers and FFT plans are initialised */ + bool initialised; /**< flag indicating whether buffers and FFT plans are initialised */ - double *frame; /**< audio frame */ - double *window; /**< window */ + std::vector<double> frame; /**< audio frame */ + std::vector<double> window; /**< window */ double prevEnergySum; /**< to hold the previous energy sum value */ - double *magSpec; /**< magnitude spectrum */ - double *prevMagSpec; /**< previous magnitude spectrum */ + std::vector<double> magSpec; /**< magnitude spectrum */ + std::vector<double> prevMagSpec; /**< previous magnitude spectrum */ - double *phase; /**< FFT phase values */ - double *prevPhase; /**< previous phase values */ - double *prevPhase2; /**< second order previous phase values */ + std::vector<double> phase; /**< FFT phase values */ + std::vector<double> prevPhase; /**< previous phase values */ + std::vector<double> prevPhase2; /**< second order previous phase values */ };