andrew@4
|
1 /*
|
andrew@4
|
2 * TimeWarp.h
|
andrew@4
|
3 * chromaReader13
|
andrew@4
|
4 *
|
andrew@4
|
5 * Created by Andrew on 16/05/2011.
|
andrew@4
|
6 * Copyright 2011 QMUL. All rights reserved.
|
andrew@4
|
7 *
|
andrew@4
|
8 */
|
andrew@4
|
9
|
andrew@4
|
10 #ifndef _TIME_WARP
|
andrew@4
|
11 #define _TIME_WARP
|
andrew@4
|
12
|
andrew@4
|
13
|
andrew@4
|
14 #include "ofMain.h"
|
andrew@4
|
15 #include "chromaGram.h"
|
andrew@4
|
16 #include "ChordDetect.h"
|
andrew@4
|
17 #include "sndfile.h"
|
andrew@4
|
18 #include "ofxFileDialogOSX.h"
|
andrew@4
|
19
|
andrew@8
|
20 //11/2011
|
andrew@8
|
21 //what is similarity and what chromaSimilarity?
|
andrew@4
|
22
|
andrew@4
|
23 #define FRAMESIZE 512
|
andrew@4
|
24 #define ENERGY_LENGTH 80000
|
andrew@4
|
25 #define CHROMA_LENGTH 12000
|
andrew@4
|
26 #define CHROMA_CONVERSION_FACTOR 16 //16 times as many frames in energy as in chroma
|
andrew@4
|
27 //length in terms of frames (at 512 samples per frame - there are 90 per second) => 900: 10 seconds
|
andrew@4
|
28 #define ALIGNMENT_FRAMESIZE 128
|
andrew@4
|
29
|
andrew@4
|
30 class TimeWarp : public ofBaseApp{
|
andrew@4
|
31
|
andrew@4
|
32 public:
|
andrew@4
|
33 TimeWarp(); // constructor
|
andrew@4
|
34 ~TimeWarp();
|
andrew@4
|
35
|
andrew@4
|
36 void initialiseVariables();
|
andrew@8
|
37 void clearVectors();
|
andrew@4
|
38 //variables
|
andrew@4
|
39 typedef std::vector<double> DoubleVector;
|
andrew@4
|
40 typedef std::vector<DoubleVector> DoubleMatrix;
|
andrew@4
|
41
|
andrew@4
|
42 DoubleMatrix chromaMatrix;
|
andrew@4
|
43 DoubleMatrix secondMatrix;
|
andrew@4
|
44 DoubleMatrix* matrixPtr;
|
andrew@4
|
45
|
andrew@4
|
46 DoubleVector firstEnergyVector;
|
andrew@4
|
47 DoubleVector secondEnergyVector;
|
andrew@4
|
48
|
andrew@4
|
49 DoubleMatrix firstChromaEnergyMatrix;
|
andrew@4
|
50 DoubleMatrix secondChromaEnergyMatrix;
|
andrew@4
|
51
|
andrew@4
|
52 Chromagram chromoGramm;
|
andrew@4
|
53 Chromagram secondChromoGramm;
|
andrew@4
|
54
|
andrew@4
|
55 DoubleMatrix similarityMatrix;
|
andrew@4
|
56 DoubleMatrix tmpSimilarityMatrix;
|
andrew@4
|
57 DoubleMatrix alignmentMeasureMatrix;
|
andrew@4
|
58 DoubleMatrix tmpAlignmentMeasureMatrix;
|
andrew@4
|
59 DoubleVector minimumAlignmentPath;
|
andrew@4
|
60
|
andrew@4
|
61 double partAlignmentMeasureMatrix[ALIGNMENT_FRAMESIZE][ALIGNMENT_FRAMESIZE];
|
andrew@4
|
62
|
andrew@4
|
63 typedef std::vector<int> IntVector;
|
andrew@4
|
64 typedef std::vector<IntVector> IntMatrix;
|
andrew@4
|
65 IntMatrix backwardsAlignmentPath;
|
andrew@4
|
66 IntMatrix tmpBackwardsPath;
|
andrew@4
|
67
|
andrew@4
|
68 int backwardsAlignmentIndex;
|
andrew@4
|
69
|
andrew@4
|
70 IntMatrix partBackwardsAlignmentPath;
|
andrew@4
|
71 IntMatrix forwardsAlignmentPath;
|
andrew@10
|
72 IntMatrix anchorPoints;
|
andrew@10
|
73 void addAnchorPoints(const int& startFrameX, const int& startFrameY);
|
andrew@4
|
74
|
andrew@4
|
75 int partBackwardsAlignmentIndex;
|
andrew@4
|
76
|
andrew@4
|
77
|
andrew@4
|
78 void createCombinedMatrix(DoubleMatrix myChromaMatrix, DoubleVector energyVector, DoubleMatrix* chromaEnergyMatrix);
|
andrew@4
|
79
|
andrew@5
|
80 double getChromaSimilarity(int x, int y, DoubleMatrix* firstChromaMatrix, DoubleMatrix* secondChromaMatrix);
|
andrew@15
|
81 double getEuclideanDistance(int x, int y, DoubleMatrix* firstChromaMatrix, DoubleMatrix* secondChromaMatrix);
|
andrew@5
|
82 void calculateChromaSimilarityMatrix(DoubleMatrix* firstChromaMatrix, DoubleMatrix* secondChromaMatrix, DoubleMatrix* simMatrix);
|
andrew@5
|
83
|
andrew@4
|
84 void calculateSimilarityMatrix();
|
andrew@4
|
85
|
andrew@5
|
86 int findMinimumOfMatrixColumn(DoubleMatrix d, int column);
|
andrew@4
|
87
|
andrew@4
|
88
|
andrew@4
|
89 //new addition
|
andrew@5
|
90 void calculateSimilarityMatrixWithPointers(DoubleMatrix* firstChromaMatrix, DoubleMatrix* secondChromaMatrix, DoubleMatrix* simMatrix);
|
andrew@5
|
91
|
andrew@5
|
92 void calculateJointSimilarityMatrix(DoubleVector* energyVectorOne, DoubleVector* energyVectorTwo, DoubleMatrix* chromaSimilarityMatrix, DoubleMatrix* simMatrix);
|
andrew@5
|
93
|
andrew@9
|
94 void calculatePartJointSimilarityMatrix(DoubleVector* firstEnergyVector, DoubleVector* secondEnergyVector, DoubleMatrix* chromaSimMatrix, DoubleMatrix* simMatrix, int startX, int startY, int endX, int endY);
|
andrew@5
|
95
|
andrew@5
|
96
|
andrew@5
|
97 double getJointChromaAndEnergyDistance(DoubleVector* energyVectorOne, DoubleMatrix* firstChromaMatrix, DoubleVector* energyVectorTwo, DoubleMatrix* secondChromaMatrix, int energyIndexX, int energyIndexY, double energyProportion, double chromaProportion);
|
andrew@5
|
98
|
andrew@5
|
99 DoubleMatrix chromaSimilarityMatrix;
|
andrew@5
|
100 // DoubleMatrix superAlignmentMeasureMatrix; //for the onset + chromagram alignment
|
andrew@5
|
101 // DoubleVector superMinimumAlignmentPath;
|
andrew@4
|
102 //end new additions
|
andrew@4
|
103
|
andrew@4
|
104 int findStartWidthFrame();
|
andrew@4
|
105
|
andrew@4
|
106
|
andrew@4
|
107
|
andrew@5
|
108 int conversionFactor;
|
andrew@4
|
109
|
andrew@4
|
110 void calculateAlignmentMatrix(DoubleMatrix firstMatrix, DoubleMatrix secondMatrix, DoubleMatrix *alignmentMatrix);
|
andrew@4
|
111 double getDistance(int i, int j);
|
andrew@4
|
112
|
andrew@4
|
113
|
andrew@4
|
114 double getMinimum(int i, int j, float newValue);
|
andrew@4
|
115 bool extendAlignmentUp(int endIndexY, DoubleMatrix *alignmentMatrix);
|
andrew@4
|
116 bool extendAlignmentAlong(int endIndexX, DoubleMatrix *alignmentMatrix);
|
andrew@5
|
117 void calculateMinimumAlignmentPath(DoubleMatrix* alignmentMatrix, IntMatrix* backPath, bool pickMinimumFlag);//writes the backwards laignment path to *backPath
|
andrew@5
|
118
|
andrew@4
|
119
|
andrew@5
|
120 bool findPreviousMinimumInBackwardsPath(DoubleMatrix* alignmentMatrix, IntMatrix* backPath);
|
andrew@5
|
121 bool testForNewAlignmentMinimum(double *previousMinimum, int i, int j, DoubleMatrix* alignmentMatrix);
|
andrew@4
|
122
|
andrew@4
|
123 int findMinimumOfVector(DoubleVector *d);
|
andrew@5
|
124
|
andrew@5
|
125 void extendForwardAlignmentPath(int endX, IntMatrix* backPath, int anchorPointX, int anchorPointY);//specify forwards path to extend?
|
andrew@5
|
126 void addNewForwardsPath(int indexX, IntMatrix* backPath, int anchorPointX, int anchorPointY);
|
andrew@5
|
127
|
andrew@5
|
128 int getMinimumIndexOfColumnFromMatrix(int i, DoubleMatrix* matrix);
|
andrew@4
|
129
|
andrew@4
|
130
|
andrew@5
|
131 //PART ALIGNMENT FUNCTIONS
|
andrew@5
|
132 void calculatePartSimilarityMatrix(DoubleMatrix* firstChromaMatrix, DoubleMatrix* secondChromaMatrix, DoubleMatrix* simMatrix, int startX, int startY, int endX);
|
andrew@5
|
133 void calculatePartAlignmentMatrix(int endIndexX, int endIndexY, DoubleMatrix* alignmentMatrix, DoubleMatrix* simMatrix);
|
andrew@4
|
134
|
andrew@4
|
135
|
andrew@5
|
136 double getDistanceFromMatrix(int i, int j, DoubleMatrix* simMatrix);
|
andrew@5
|
137 double getMinimumFromMatrix(int i, int j, float newValue, DoubleMatrix* alignMatrix);
|
andrew@5
|
138
|
andrew@4
|
139 void calculatePartMinimumAlignmentPath(int startX, int startY, int endX, int endY, DoubleMatrix alignmentMatrix);
|
andrew@5
|
140 // bool findPreviousMinimumInPartBackwardsPath(DoubleMatrix* alignmentMatrix);
|
andrew@5
|
141 double getRestrictedMinimum(int i, int j, float newValue, int minX, int minY);
|
andrew@5
|
142 bool extendRestrictedAlignmentUp(int endIndexY, DoubleMatrix *alignmentMatrix, DoubleMatrix* simMatrix);
|
andrew@5
|
143 bool extendRestrictedAlignmentAlong(int endIndexX, DoubleMatrix* alignmentMatrix, DoubleMatrix* simMatrix);
|
andrew@5
|
144
|
andrew@5
|
145
|
andrew@8
|
146 void printBackwardsPath(int startIndex, int endIndex, const IntMatrix* backPath);
|
andrew@5
|
147 void copyForwardsPathToBackwardsPath();
|
andrew@4
|
148
|
andrew@4
|
149 float diagonalPenalty;
|
andrew@15
|
150 bool useDotProduct;
|
andrew@4
|
151 };
|
andrew@4
|
152
|
andrew@4
|
153 #endif
|