andrew@0: /* andrew@4: * TimeWarp.h andrew@0: * chromaReader13 andrew@0: * andrew@0: * Created by Andrew on 16/05/2011. andrew@0: * Copyright 2011 QMUL. All rights reserved. andrew@0: * andrew@0: */ andrew@0: andrew@0: #ifndef _TIME_WARP andrew@0: #define _TIME_WARP andrew@0: andrew@0: andrew@0: #include "ofMain.h" andrew@0: #include "chromaGram.h" andrew@0: #include "ChordDetect.h" andrew@0: #include "sndfile.h" andrew@0: #include "ofxFileDialogOSX.h" andrew@0: andrew@0: andrew@0: #define FRAMESIZE 512 andrew@0: #define ENERGY_LENGTH 80000 andrew@0: #define CHROMA_LENGTH 12000 andrew@0: #define CHROMA_CONVERSION_FACTOR 16 //16 times as many frames in energy as in chroma andrew@0: //length in terms of frames (at 512 samples per frame - there are 90 per second) => 900: 10 seconds andrew@4: #define ALIGNMENT_FRAMESIZE 128 andrew@0: andrew@4: class TimeWarp : public ofBaseApp{ andrew@0: andrew@0: public: andrew@4: TimeWarp(); // constructor andrew@4: ~TimeWarp(); andrew@0: andrew@0: void initialiseVariables(); andrew@0: andrew@0: //variables andrew@0: typedef std::vector DoubleVector; andrew@0: typedef std::vector DoubleMatrix; andrew@0: andrew@0: DoubleMatrix chromaMatrix; andrew@0: DoubleMatrix secondMatrix; andrew@0: DoubleMatrix* matrixPtr; andrew@4: andrew@0: DoubleVector firstEnergyVector; andrew@0: DoubleVector secondEnergyVector; andrew@0: andrew@4: DoubleMatrix firstChromaEnergyMatrix; andrew@4: DoubleMatrix secondChromaEnergyMatrix; andrew@0: andrew@1: Chromagram chromoGramm; andrew@1: Chromagram secondChromoGramm; andrew@1: andrew@4: DoubleMatrix similarityMatrix; andrew@4: DoubleMatrix tmpSimilarityMatrix; andrew@4: DoubleMatrix alignmentMeasureMatrix; andrew@4: DoubleMatrix tmpAlignmentMeasureMatrix; andrew@0: DoubleVector minimumAlignmentPath; andrew@0: andrew@4: double partAlignmentMeasureMatrix[ALIGNMENT_FRAMESIZE][ALIGNMENT_FRAMESIZE]; andrew@0: andrew@0: typedef std::vector IntVector; andrew@0: typedef std::vector IntMatrix; andrew@4: IntMatrix backwardsAlignmentPath; andrew@4: IntMatrix tmpBackwardsPath; andrew@0: andrew@4: int backwardsAlignmentIndex; andrew@0: andrew@4: IntMatrix partBackwardsAlignmentPath; andrew@4: IntMatrix forwardsAlignmentPath; andrew@4: andrew@4: int partBackwardsAlignmentIndex; andrew@4: andrew@4: andrew@4: void createCombinedMatrix(DoubleMatrix myChromaMatrix, DoubleVector energyVector, DoubleMatrix* chromaEnergyMatrix); andrew@4: andrew@4: void calculateSimilarityMatrix(); andrew@4: andrew@4: andrew@4: andrew@4: andrew@4: //new addition andrew@4: void calculateSimilarityMatrixWithPointers(DoubleMatrix firstChromaMatrix, DoubleMatrix secondChromaMatrix, DoubleMatrix* simMatrix); andrew@4: DoubleMatrix superAlignmentMeasureMatrix; //for the onset + chromagram alignment andrew@4: DoubleVector superMinimumAlignmentPath; andrew@4: //end new additions andrew@4: andrew@4: int findStartWidthFrame(); andrew@4: andrew@4: andrew@4: andrew@4: andrew@4: andrew@4: void calculateAlignmentMatrix(DoubleMatrix firstMatrix, DoubleMatrix secondMatrix, DoubleMatrix *alignmentMatrix); andrew@4: double getDistance(int i, int j); andrew@4: andrew@4: double getRestrictedMinimum(int i, int j, float newValue, int minX, int minY); andrew@4: bool extendRestrictedAlignmentUp(int startX, int startY, int endIndexY, DoubleMatrix *alignmentMatrix); andrew@4: bool extendRestrictedAlignmentAlong(int startX, int startY, int endIndexX, DoubleMatrix* alignmentMatrix); andrew@4: andrew@4: double getMinimum(int i, int j, float newValue); andrew@4: bool extendAlignmentUp(int endIndexY, DoubleMatrix *alignmentMatrix); andrew@4: bool extendAlignmentAlong(int endIndexX, DoubleMatrix *alignmentMatrix); andrew@4: void calculateMinimumAlignmentPath(DoubleMatrix alignmentMatrix); andrew@4: void extendForwardAlignmentPath(int endX); andrew@4: andrew@0: andrew@0: bool findPreviousMinimumInBackwardsPath(); andrew@0: bool testForNewAlignmentMinimum(double *previousMinimum, int i, int j); andrew@0: andrew@0: int findMinimumOfVector(DoubleVector *d); andrew@0: andrew@0: andrew@4: void addNewForwardsPath(int indexX); andrew@4: andrew@4: void calculatePartSimilarityMatrix(DoubleMatrix firstChromaMatrix, DoubleMatrix secondChromaMatrix, DoubleMatrix* simMatrix, int startX, int startY, int endX); andrew@0: andrew@4: // void calculatePartAlignmentMatrix(int startIndexX, int startIndexY, int endIndexX, int endIndexY, DoubleMatrix* alignmentMatrix); andrew@4: void calculatePartMinimumAlignmentPath(int startX, int startY, int endX, int endY, DoubleMatrix alignmentMatrix); andrew@4: bool findPreviousMinimumInPartBackwardsPath(); andrew@0: andrew@0: float diagonalPenalty; andrew@0: andrew@0: }; andrew@0: andrew@0: #endif