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@4
|
72
|
andrew@4
|
73 int partBackwardsAlignmentIndex;
|
andrew@4
|
74
|
andrew@4
|
75
|
andrew@4
|
76 void createCombinedMatrix(DoubleMatrix myChromaMatrix, DoubleVector energyVector, DoubleMatrix* chromaEnergyMatrix);
|
andrew@4
|
77
|
andrew@5
|
78 double getChromaSimilarity(int x, int y, DoubleMatrix* firstChromaMatrix, DoubleMatrix* secondChromaMatrix);
|
andrew@5
|
79
|
andrew@5
|
80 void calculateChromaSimilarityMatrix(DoubleMatrix* firstChromaMatrix, DoubleMatrix* secondChromaMatrix, DoubleMatrix* simMatrix);
|
andrew@5
|
81
|
andrew@4
|
82 void calculateSimilarityMatrix();
|
andrew@4
|
83
|
andrew@5
|
84 int findMinimumOfMatrixColumn(DoubleMatrix d, int column);
|
andrew@4
|
85
|
andrew@4
|
86
|
andrew@4
|
87 //new addition
|
andrew@5
|
88 void calculateSimilarityMatrixWithPointers(DoubleMatrix* firstChromaMatrix, DoubleMatrix* secondChromaMatrix, DoubleMatrix* simMatrix);
|
andrew@5
|
89
|
andrew@5
|
90 void calculateJointSimilarityMatrix(DoubleVector* energyVectorOne, DoubleVector* energyVectorTwo, DoubleMatrix* chromaSimilarityMatrix, DoubleMatrix* simMatrix);
|
andrew@5
|
91
|
andrew@9
|
92 void calculatePartJointSimilarityMatrix(DoubleVector* firstEnergyVector, DoubleVector* secondEnergyVector, DoubleMatrix* chromaSimMatrix, DoubleMatrix* simMatrix, int startX, int startY, int endX, int endY);
|
andrew@5
|
93
|
andrew@5
|
94
|
andrew@5
|
95 double getJointChromaAndEnergyDistance(DoubleVector* energyVectorOne, DoubleMatrix* firstChromaMatrix, DoubleVector* energyVectorTwo, DoubleMatrix* secondChromaMatrix, int energyIndexX, int energyIndexY, double energyProportion, double chromaProportion);
|
andrew@5
|
96
|
andrew@5
|
97 DoubleMatrix chromaSimilarityMatrix;
|
andrew@5
|
98 // DoubleMatrix superAlignmentMeasureMatrix; //for the onset + chromagram alignment
|
andrew@5
|
99 // DoubleVector superMinimumAlignmentPath;
|
andrew@4
|
100 //end new additions
|
andrew@4
|
101
|
andrew@4
|
102 int findStartWidthFrame();
|
andrew@4
|
103
|
andrew@4
|
104
|
andrew@4
|
105
|
andrew@5
|
106 int conversionFactor;
|
andrew@4
|
107
|
andrew@4
|
108 void calculateAlignmentMatrix(DoubleMatrix firstMatrix, DoubleMatrix secondMatrix, DoubleMatrix *alignmentMatrix);
|
andrew@4
|
109 double getDistance(int i, int j);
|
andrew@4
|
110
|
andrew@4
|
111
|
andrew@4
|
112 double getMinimum(int i, int j, float newValue);
|
andrew@4
|
113 bool extendAlignmentUp(int endIndexY, DoubleMatrix *alignmentMatrix);
|
andrew@4
|
114 bool extendAlignmentAlong(int endIndexX, DoubleMatrix *alignmentMatrix);
|
andrew@5
|
115 void calculateMinimumAlignmentPath(DoubleMatrix* alignmentMatrix, IntMatrix* backPath, bool pickMinimumFlag);//writes the backwards laignment path to *backPath
|
andrew@5
|
116
|
andrew@4
|
117
|
andrew@5
|
118 bool findPreviousMinimumInBackwardsPath(DoubleMatrix* alignmentMatrix, IntMatrix* backPath);
|
andrew@5
|
119 bool testForNewAlignmentMinimum(double *previousMinimum, int i, int j, DoubleMatrix* alignmentMatrix);
|
andrew@4
|
120
|
andrew@4
|
121 int findMinimumOfVector(DoubleVector *d);
|
andrew@5
|
122
|
andrew@5
|
123 void extendForwardAlignmentPath(int endX, IntMatrix* backPath, int anchorPointX, int anchorPointY);//specify forwards path to extend?
|
andrew@5
|
124 void addNewForwardsPath(int indexX, IntMatrix* backPath, int anchorPointX, int anchorPointY);
|
andrew@5
|
125
|
andrew@5
|
126 int getMinimumIndexOfColumnFromMatrix(int i, DoubleMatrix* matrix);
|
andrew@4
|
127
|
andrew@4
|
128
|
andrew@5
|
129 //PART ALIGNMENT FUNCTIONS
|
andrew@5
|
130 void calculatePartSimilarityMatrix(DoubleMatrix* firstChromaMatrix, DoubleMatrix* secondChromaMatrix, DoubleMatrix* simMatrix, int startX, int startY, int endX);
|
andrew@5
|
131 void calculatePartAlignmentMatrix(int endIndexX, int endIndexY, DoubleMatrix* alignmentMatrix, DoubleMatrix* simMatrix);
|
andrew@4
|
132
|
andrew@4
|
133
|
andrew@5
|
134 double getDistanceFromMatrix(int i, int j, DoubleMatrix* simMatrix);
|
andrew@5
|
135 double getMinimumFromMatrix(int i, int j, float newValue, DoubleMatrix* alignMatrix);
|
andrew@5
|
136
|
andrew@4
|
137 void calculatePartMinimumAlignmentPath(int startX, int startY, int endX, int endY, DoubleMatrix alignmentMatrix);
|
andrew@5
|
138 // bool findPreviousMinimumInPartBackwardsPath(DoubleMatrix* alignmentMatrix);
|
andrew@5
|
139 double getRestrictedMinimum(int i, int j, float newValue, int minX, int minY);
|
andrew@5
|
140 bool extendRestrictedAlignmentUp(int endIndexY, DoubleMatrix *alignmentMatrix, DoubleMatrix* simMatrix);
|
andrew@5
|
141 bool extendRestrictedAlignmentAlong(int endIndexX, DoubleMatrix* alignmentMatrix, DoubleMatrix* simMatrix);
|
andrew@5
|
142
|
andrew@5
|
143
|
andrew@8
|
144 void printBackwardsPath(int startIndex, int endIndex, const IntMatrix* backPath);
|
andrew@5
|
145 void copyForwardsPathToBackwardsPath();
|
andrew@4
|
146
|
andrew@4
|
147 float diagonalPenalty;
|
andrew@4
|
148
|
andrew@4
|
149 };
|
andrew@4
|
150
|
andrew@4
|
151 #endif
|