diff src/timeWarp.h @ 4:f40577e6b30d

revised this to work with onset and chroma and looking now to do sequential DTW
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Wed, 08 Jun 2011 17:35:56 +0100
parents 6842ff391568
children 0d51e93bfe74
line wrap: on
line diff
--- a/src/timeWarp.h	Thu May 19 16:23:49 2011 +0100
+++ b/src/timeWarp.h	Wed Jun 08 17:35:56 2011 +0100
@@ -1,5 +1,5 @@
 /*
- *  timeWarp.h
+ *  TimeWarp.h
  *  chromaReader13
  *
  *  Created by Andrew on 16/05/2011.
@@ -23,33 +23,14 @@
 #define CHROMA_LENGTH 12000
 #define CHROMA_CONVERSION_FACTOR 16 //16 times as many frames in energy as in chroma
 //length in terms of frames (at 512 samples per frame - there are 90 per second) => 900: 10 seconds
+#define ALIGNMENT_FRAMESIZE 128
 
-class timeWarp : public ofBaseApp{
+class TimeWarp : public ofBaseApp{
 	
 public:
-	
-	/*
-	void setup();
-	void update();
-	void draw();
-	
-	void keyPressed  (int key);
-	void keyReleased(int key);
-	void mouseMoved(int x, int y );
-	void mouseDragged(int x, int y, int button);
-	void mousePressed(int x, int y, int button);
-	void mouseReleased(int x, int y, int button);
-	void windowResized(int w, int h);
-	
-	void audioRequested 	(float * input, int bufferSize, int nChannels);
-	void loadSndfile();
-	 */
-	 
-	double getEnergyOfFrame();
-	void putEnergyInFrame();
+	TimeWarp();											// constructor
+	~TimeWarp();
 
-//	void drawChromoGram();
-//	void loadFirstAudioFile();
 	void initialiseVariables();
 
 	//variables
@@ -59,149 +40,86 @@
 	DoubleMatrix chromaMatrix;
 	DoubleMatrix secondMatrix;
 	DoubleMatrix* matrixPtr;
-	
-//	void drawDoubleMatrix(DoubleMatrix* dMatrix);//DoubleMatrix* dMatrix); WOULD BE NICE TO USE POINTER BUT NOT WORKING YET
-//	void drawSpectralDifference(DoubleMatrix* dMatrix);
-	
+
 	DoubleVector firstEnergyVector;
 	DoubleVector secondEnergyVector;	
-		
-	DoubleMatrix similarityMatrix;
-
-	void calculateSimilarityMatrix();
 	
-//	bool drawSimilarity;
-//	void drawSimilarityMatrix();
-//	void printSimilarityMatrix(int sizeToPrint);
+	DoubleMatrix firstChromaEnergyMatrix;
+	DoubleMatrix secondChromaEnergyMatrix;
 	
 	Chromagram chromoGramm;
 	Chromagram secondChromoGramm;
 	
-	
-	DoubleMatrix alignmentMeasureMatrix;//just the choma alignment	
+	DoubleMatrix similarityMatrix;
+	DoubleMatrix tmpSimilarityMatrix;
+	DoubleMatrix alignmentMeasureMatrix;
+	DoubleMatrix tmpAlignmentMeasureMatrix;	
 	DoubleVector minimumAlignmentPath;
 	
-	//new addition
-	DoubleMatrix superAlignmentMeasureMatrix;	//for the onset + chromagram alignment
-	DoubleVector superMinimumAlignmentPath;	
-	
-//	void drawAlignmentPath(int startingChromaXFrame, int startingChromaYFrame);
-	int findStartWidthFrame();	  
-	
-//	void printScoreForRow(int row, int max);
-	
-//	int numberOfScrollWidthsForFirstFile;
-//	int numberOfScrollWidthsForSecondFile;	
-//	void checkIfAudioPositionExceedsWidthForFirstFile();
+	double partAlignmentMeasureMatrix[ALIGNMENT_FRAMESIZE][ALIGNMENT_FRAMESIZE];
 	
 	typedef std::vector<int> IntVector;
 	typedef std::vector<IntVector> IntMatrix;
+	IntMatrix backwardsAlignmentPath;
+	IntMatrix tmpBackwardsPath;
 	
-//	void updateAlignmentPathIndex(int idenifier);
+	int backwardsAlignmentIndex;
 	
-	IntMatrix backwardsAlignmentPath;
-	int backwardsAlignmentIndex;
+	IntMatrix partBackwardsAlignmentPath;
+	IntMatrix forwardsAlignmentPath;
+	
+	int partBackwardsAlignmentIndex;
+
+	
+	void createCombinedMatrix(DoubleMatrix myChromaMatrix, DoubleVector energyVector, DoubleMatrix* chromaEnergyMatrix);
+
+	void calculateSimilarityMatrix();
+
+	
+	
+	
+	//new addition
+	void calculateSimilarityMatrixWithPointers(DoubleMatrix firstChromaMatrix, DoubleMatrix secondChromaMatrix, DoubleMatrix* simMatrix);
+	DoubleMatrix superAlignmentMeasureMatrix;	//for the onset + chromagram alignment
+	DoubleVector superMinimumAlignmentPath;	
+	//end new additions
+	
+	int findStartWidthFrame();	  
+
+	
+
+
+	
+	void calculateAlignmentMatrix(DoubleMatrix firstMatrix, DoubleMatrix secondMatrix, DoubleMatrix *alignmentMatrix);
+	double getDistance(int i, int j);
+
+	double getRestrictedMinimum(int i, int j, float newValue, int minX, int minY);
+	bool extendRestrictedAlignmentUp(int startX, int startY, int endIndexY, DoubleMatrix *alignmentMatrix);
+	bool extendRestrictedAlignmentAlong(int startX, int startY, int endIndexX, DoubleMatrix* alignmentMatrix);
+	
+	double getMinimum(int i, int j, float newValue);
+	bool extendAlignmentUp(int endIndexY, DoubleMatrix *alignmentMatrix);
+	bool extendAlignmentAlong(int endIndexX, DoubleMatrix *alignmentMatrix);
+	void calculateMinimumAlignmentPath(DoubleMatrix alignmentMatrix);
+	void extendForwardAlignmentPath(int endX);
+	
 	
 	bool findPreviousMinimumInBackwardsPath();
 	bool testForNewAlignmentMinimum(double *previousMinimum, int i, int j);	
 	
-	void calculateAlignmentMatrix();
-	double getDistance(int i, int j);
-//	void printAlignmentMatrix();
-	double getMinimum(int i, int j, float newValue);
-	bool extendAlignmentUp();
-	bool extendAlignmentAlong();
-	void calculateMinimumAlignmentPath();
 	int findMinimumOfVector(DoubleVector *d);
-//	void swapBetweenPlayingFilesUsingAlignmentMatch();
-//	int findMatchFromAlignment(bool whichFileToTest);
 	
-//	void drawEnergyVectorFromPointer(DoubleVector* energyVec);
 	
-//	void processAudioToDoubleMatrix(Chromagram* chromaG, DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector);
+	void addNewForwardsPath(int indexX);
+
+	void calculatePartSimilarityMatrix(DoubleMatrix firstChromaMatrix, DoubleMatrix secondChromaMatrix, DoubleMatrix* simMatrix, int startX, int startY, int endX);
 	
-	
-	
-	
-	
-	
-	
-//	void loadNewAudio(string soundFileName);
-//	void loadSecondAudio(string soundFileName);
-	
-//	void loadSoundFiles();
-//	void openFileDialogBox();
-//	void loadLibSndFile(const char * filename);
-//	bool getFilenameFromDialogBox(string* fileNameToSave);
-//	void openNewAudioFileWithdialogBox();		
-	
-	//int* firstAudioLength, secondAudioLength;
-	
-//	string soundFileName, secondFileName;
-	
-//	float screenHeight, screenWidth;
-
-	
-//	bool moveOn;
-//	bool drawSpectralDifferenceFunction;
-
-	float frame[FRAMESIZE]; 
+//	void calculatePartAlignmentMatrix(int startIndexX, int startIndexY, int endIndexX, int endIndexY, DoubleMatrix* alignmentMatrix);
+	void calculatePartMinimumAlignmentPath(int startX, int startY, int endX, int endY, DoubleMatrix alignmentMatrix);
+		bool findPreviousMinimumInPartBackwardsPath();
 	
 	float diagonalPenalty;
 	
-//	int frameIndex;
-	
-//	float chromoGramVector[CHROMA_LENGTH][12];
-//	int rootChord[CHROMA_LENGTH];
-	
-//	int energyIndex;
-//	int totalFrames;
-	
-//	int scrollWidth;// 1600
-//	float chromoLength;
-	
-//	bool audioPlaying, audioPaused;
-//	bool drawSecondMatrix;
-	
-/*
-
-	
-	//------------------- for the simple sine wave synthesis
-	float 	targetFrequency;
-	float 	phase;
-	float 	phaseAdder;
-	float 	phaseAdderTarget;
-	
-	string sndfileInfoString, textString;
-	int xIndex;
-	
-	bool firstAudioFilePlaying;
-	ofSoundPlayer  loadedAudio;
-	ofSoundPlayer secondAudio;
-	ofSoundPlayer *playingAudio;
-	
- */
-//	float audioPosition;
-//	float width, height;
-//	int chromaIndex;	
-//	int totalNumberOfFrames;
-//	int currentPlayingFrame;
-//	int currentChromaFrame ;
-	
-//	string chordString;
-	
-	//Chromagram* chromoGrammPtr;
-	
-	
-	
-	
-//	string userInfoString;
-//	ChordDetect chord;
-	//sndfile part
-//	SNDFILE *infile; // define input and output sound files
-//	SF_INFO sfinfo ; // struct to hold info about sound file
-	
-	
 };
 
 #endif