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