changeset 3:d0242d0a48e8

I've changed timeWarp.h to have a capital T: TimeWarp.h as befits a class. Also added destructor method
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Thu, 19 May 2011 16:23:49 +0100
parents 9ce18f24b266
children f40577e6b30d
files src/timeWarp.cpp
diffstat 1 files changed, 66 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/src/timeWarp.cpp	Thu May 19 11:45:26 2011 +0100
+++ b/src/timeWarp.cpp	Thu May 19 16:23:49 2011 +0100
@@ -1,5 +1,5 @@
 /*
- *  timeWarp.cpp
+ *  TimeWarp.cpp
  *  chromaReader13
  *
  *  Created by Andrew on 16/05/2011.
@@ -7,7 +7,7 @@
  *
  */
 
-#include "timeWarp.h"
+#include "TimeWarp.h"
 
 #include "stdio.h"
 #include "aubio.h"
@@ -31,10 +31,30 @@
 
 //UPDATE START FRAME SO ALIGNMENT IS ALWAYS ON SCREEN
 //--------------------------------------------------------------
+// destructor
+TimeWarp :: TimeWarp(){
+	diagonalPenalty = 2;//penalises diagonal so all path gradients equal weighting
+}	
 
-
-
-void timeWarp::initialiseVariables(){
+// destructor
+TimeWarp :: ~TimeWarp(){
+	chromaMatrix.clear();
+	secondMatrix.clear();
+	//matrixPtr.clear();
+	firstEnergyVector.clear();
+	secondEnergyVector.clear();	
+	similarityMatrix.clear();
+	alignmentMeasureMatrix.clear();
+	
+	
+	//chromoGramm.~ChromoGram();
+	//secondChromoGramm;
+	
+	
+	
+}	
+	
+void TimeWarp::initialiseVariables(){
 	diagonalPenalty = 2;//penalises diagonal so all path gradients equal weighting
 
 	//chromoGramm.initialise(FRAMESIZE,2048);//framesize 512 and hopsize 2048
@@ -42,8 +62,8 @@
 }
 
 
-
-double timeWarp::getEnergyOfFrame(){
+/*
+double TimeWarp::getEnergyOfFrame(){
 	
 	
 	float totalEnergyInFrame = 0;
@@ -57,10 +77,11 @@
 	
 	return totalEnergyInFrame;
 }
+ */
 
 
 
-void timeWarp::calculateSimilarityMatrix(){
+void TimeWarp::calculateSimilarityMatrix(){
 	similarityMatrix.clear();
 	printf("calculating similarity matrix...");
 	//	userInfoString = "calculating similarity matrix...";
@@ -101,7 +122,7 @@
 
 
 
-void timeWarp::calculateAlignmentMatrix(){
+void TimeWarp::calculateAlignmentMatrix(){
 	
 	//initialise alignment
 	alignmentMeasureMatrix.clear();
@@ -124,7 +145,7 @@
 	
 }
 
-bool timeWarp::extendAlignmentUp(){
+bool TimeWarp::extendAlignmentUp(){
 	DoubleVector d;
 	d = alignmentMeasureMatrix[0];//alignmentMatrix[0];//
 	int heightSize = d.size();
@@ -144,7 +165,7 @@
 }
 
 
-bool timeWarp::extendAlignmentAlong(){
+bool TimeWarp::extendAlignmentAlong(){
 	DoubleVector d;
 	int widthSize = alignmentMeasureMatrix.size();
 	if (widthSize < chromaMatrix.size()){
@@ -171,7 +192,7 @@
 }
 
 
-void timeWarp::calculateMinimumAlignmentPath(){
+void TimeWarp::calculateMinimumAlignmentPath(){
 	//this requires one pass of the DTW algorithm and then works backwards from (N,M)
 	//to find the optimal path to (0,0), where N and M are the lengths of the two chromoVectors respectively
 	
@@ -201,7 +222,7 @@
 }
 
 
-bool timeWarp::findPreviousMinimumInBackwardsPath(){
+bool TimeWarp::findPreviousMinimumInBackwardsPath(){
 	int chromaPosition, secondPosition;
 	int i,j;
 	i = backwardsAlignmentPath[0][backwardsAlignmentPath[0].size()-1];
@@ -248,7 +269,7 @@
 
 
 
-bool timeWarp::testForNewAlignmentMinimum(double *previousMinimum, int i, int j){
+bool TimeWarp::testForNewAlignmentMinimum(double *previousMinimum, int i, int j){
 	bool newMinimumFound = false;
 	if (alignmentMeasureMatrix[i][j] < *previousMinimum){
 		*previousMinimum = alignmentMeasureMatrix[i][j];							   
@@ -259,7 +280,7 @@
 }															
 
 
-int timeWarp::findMinimumOfVector(DoubleVector *d){
+int TimeWarp::findMinimumOfVector(DoubleVector *d){
 	int minimumIndex = 0;
 	double minimumValue = (*d)[0];
 	for (int i = 0;i < d->size();i++){
@@ -272,11 +293,11 @@
 	return minimumIndex;
 }
 
-double timeWarp::getDistance(int i, int j){
+double TimeWarp::getDistance(int i, int j){
 	return (1 - similarityMatrix[i][j]);
 }
 
-double timeWarp::getMinimum(int i, int j, float newValue){
+double TimeWarp::getMinimum(int i, int j, float newValue){
 	double minimumValue = 0;
 	
 	if (i > 0){
@@ -296,7 +317,7 @@
 
 //--------------------------------------------------------------
 /*
-void timeWarp::update(){
+void TimeWarp::update(){
 	textString = "energy index [";
 	textString += ofToString(xIndex);
 	textString += "] = ";
@@ -331,7 +352,7 @@
 */
 
 /*
- void timeWarp::updateAlignmentPathIndex(int identifier){
+ void TimeWarp::updateAlignmentPathIndex(int identifier){
 	
 //	int chromaPosition = audioPosition/CHROMA_CONVERSION_FACTOR;
 	
@@ -345,7 +366,7 @@
 
 //--------------------------------------------------------------
 /*
- void timeWarp::draw(){
+ void TimeWarp::draw(){
 	
 	if (drawSimilarity)
 		drawSimilarityMatrix();
@@ -356,7 +377,7 @@
 }
 
 
-void timeWarp::drawEnergyVectorFromPointer(DoubleVector* energyVec){
+void TimeWarp::drawEnergyVectorFromPointer(DoubleVector* energyVec){
 	
 	float screenHeight = ofGetHeight() ;
 	float screenWidth = ofGetWidth();  
@@ -373,7 +394,7 @@
 	}
 }
 
-void timeWarp::drawSpectralDifference(DoubleMatrix* dMatrix){
+void TimeWarp::drawSpectralDifference(DoubleMatrix* dMatrix){
 	if ((*dMatrix).size()>0){
 		
 		float screenHeight = ofGetHeight() ;
@@ -406,7 +427,7 @@
 }
 
 
-void timeWarp::drawChromoGram(){
+void TimeWarp::drawChromoGram(){
 	
 	DoubleMatrix* dptr;
 	DoubleVector* eptr;
@@ -452,7 +473,7 @@
 	
 }
 
-void timeWarp::drawDoubleMatrix(DoubleMatrix* dMatrix){
+void TimeWarp::drawDoubleMatrix(DoubleMatrix* dMatrix){
 	if ((*dMatrix).size()>0){
 		
 		float screenHeight = ofGetHeight() ;
@@ -481,7 +502,7 @@
 }
 
 
-void timeWarp::drawSimilarityMatrix(){
+void TimeWarp::drawSimilarityMatrix(){
 	
 	int simHeight = (similarityMatrix[0]).size();
 	int simWidth = similarityMatrix.size();
@@ -592,7 +613,7 @@
  
  
  
- void timeWarp::drawAlignmentPath(int startingChromaXFrame, int startingChromaYFrame){
+ void TimeWarp::drawAlignmentPath(int startingChromaXFrame, int startingChromaYFrame){
  //draw alignment path
  int endingChromaXFrame = startingChromaXFrame + chromoLength;
  int endingChromaYFrame = startingChromaYFrame + chromoLength;
@@ -670,13 +691,13 @@
  
 */
 /*
-void  timeWarp::checkIfAudioPositionExceedsWidthForFirstFile()
+void  TimeWarp::checkIfAudioPositionExceedsWidthForFirstFile()
 {
 	if (currentPlayingFrame > scrollWidth*(numberOfScrollWidthsForFirstFile+1))
 		numberOfScrollWidthsForFirstFile++;
 }
 
-int timeWarp::findStartWidthFrame(){
+int TimeWarp::findStartWidthFrame(){
 	int startingFrame;
 	startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
 	startingFrame *= scrollWidth;//starting frame in terms of energy frames
@@ -688,7 +709,7 @@
 */
 
 /*
-void timeWarp::loadSoundFiles(){
+void TimeWarp::loadSoundFiles(){
 	
 	//assume libsndfile looks in the folder where the app is run
 	//therefore ../../../ gets to the bin folder
@@ -704,7 +725,7 @@
 	
 }
 
-void timeWarp::loadLibSndFile(const char *infilename){
+void TimeWarp::loadLibSndFile(const char *infilename){
 	
 	if (!sf_close(infile)){
 		printf("closed sndfile okay \n");
@@ -726,7 +747,7 @@
 }
  */
 /*
-void timeWarp::processAudioToDoubleMatrix(Chromagram* chromaG, DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector){
+void TimeWarp::processAudioToDoubleMatrix(Chromagram* chromaG, DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector){
 	//wendy
 	myDoubleMatrix->clear();
 	energyVector->clear();
@@ -805,7 +826,7 @@
 
 //--------------------------------------------------------------
 /*
-void timeWarp::keyPressed  (int key){
+void TimeWarp::keyPressed  (int key){
 	if (key == '-'){
 		volume -= 0.05;
 		volume = MAX(volume, 0);
@@ -912,7 +933,7 @@
 }
 
 //--------------------------------------------------------------
-void timeWarp::keyReleased  (int key){
+void TimeWarp::keyReleased  (int key){
 	if (key == OF_KEY_LEFT || OF_KEY_RIGHT){
 		(*playingAudio).setSpeed(1);
 		backwardsAlignmentIndex = backwardsAlignmentPath[0].size()-1;
@@ -921,7 +942,7 @@
 }
 */
 /*
-void timeWarp::openNewAudioFileWithdialogBox(){
+void TimeWarp::openNewAudioFileWithdialogBox(){
 	
 	//open audio file
 	string *filePtr;
@@ -938,7 +959,7 @@
  */
 /*
 //--------------------------------------------------------------
-void timeWarp::mouseMoved(int x, int y ){
+void TimeWarp::mouseMoved(int x, int y ){
 	width = ofGetWidth();
 	pan = (float)x / (float)width;
 	float height = (float)ofGetHeight();
@@ -949,25 +970,25 @@
 }
 
 //--------------------------------------------------------------
-void timeWarp::mouseDragged(int x, int y, int button){
+void TimeWarp::mouseDragged(int x, int y, int button){
 	width = ofGetWidth();
 	pan = (float)x / (float)width;
 }
 
 //--------------------------------------------------------------
-void timeWarp::mousePressed(int x, int y, int button){
+void TimeWarp::mousePressed(int x, int y, int button){
 	bNoise = true;
 	moveOn = true;
 }
 
 
 //--------------------------------------------------------------
-void timeWarp::mouseReleased(int x, int y, int button){
+void TimeWarp::mouseReleased(int x, int y, int button){
 	bNoise = false;
 }
 
 //--------------------------------------------------------------
-void timeWarp::windowResized(int w, int h){
+void TimeWarp::windowResized(int w, int h){
 	width = w;
 	height = h;
 	screenHeight = ofGetHeight() ;
@@ -979,7 +1000,7 @@
 //--------------------------------------------------------------
 /*
 
-bool timeWarp::getFilenameFromDialogBox(string* fileNameToSave){
+bool TimeWarp::getFilenameFromDialogBox(string* fileNameToSave){
 	//this uses a pointer structure within the loader and returns true if the dialogue box was used successfully
 	// first, create a string that will hold the URL
 	string URL;
@@ -1004,7 +1025,7 @@
 
 
 /*
-void timeWarp::putEnergyInFrame(){
+void TimeWarp::putEnergyInFrame(){
 	
 	
 	float totalEnergyInFrame = 0;
@@ -1027,7 +1048,7 @@
 
 
 /*
-void timeWarp::printAlignmentMatrix(){
+void TimeWarp::printAlignmentMatrix(){
 	
 	int size = alignmentMeasureMatrix.size();
 	printf("\n _ _ _ _\n");
@@ -1054,7 +1075,7 @@
 }
 
 
-void timeWarp::printScoreForRow(int row, int max){
+void TimeWarp::printScoreForRow(int row, int max){
 	printf("alignment scores row %i \n", row);
 	float minimum = alignmentMeasureMatrix[row][0];
 	int minimumIndex = 0;
@@ -1078,7 +1099,7 @@
 
 
 /*
- void timeWarp::swapBetweenPlayingFilesUsingAlignmentMatch(){
+ void TimeWarp::swapBetweenPlayingFilesUsingAlignmentMatch(){
  ofSoundUpdate();
  //swapping between files
  //printf("current playing (energy scale) frame was %i \n", currentPlayingFrame);
@@ -1123,7 +1144,7 @@
  }
  */
 /*
- int timeWarp::findMatchFromAlignment(bool whichFileToTest){
+ int TimeWarp::findMatchFromAlignment(bool whichFileToTest){
  //could use technique from middle of file and go either way to reduce latency for long search? 
  //- (not that this is a problem yet)
  int indicator;