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@4
|
76 void calculateSimilarityMatrix();
|
andrew@4
|
77
|
andrew@4
|
78
|
andrew@4
|
79
|
andrew@4
|
80
|
andrew@4
|
81 //new addition
|
andrew@4
|
82 void calculateSimilarityMatrixWithPointers(DoubleMatrix firstChromaMatrix, DoubleMatrix secondChromaMatrix, DoubleMatrix* simMatrix);
|
andrew@4
|
83 DoubleMatrix superAlignmentMeasureMatrix; //for the onset + chromagram alignment
|
andrew@4
|
84 DoubleVector superMinimumAlignmentPath;
|
andrew@4
|
85 //end new additions
|
andrew@4
|
86
|
andrew@4
|
87 int findStartWidthFrame();
|
andrew@4
|
88
|
andrew@4
|
89
|
andrew@4
|
90
|
andrew@4
|
91
|
andrew@4
|
92
|
andrew@4
|
93 void calculateAlignmentMatrix(DoubleMatrix firstMatrix, DoubleMatrix secondMatrix, DoubleMatrix *alignmentMatrix);
|
andrew@4
|
94 double getDistance(int i, int j);
|
andrew@4
|
95
|
andrew@4
|
96 double getRestrictedMinimum(int i, int j, float newValue, int minX, int minY);
|
andrew@4
|
97 bool extendRestrictedAlignmentUp(int startX, int startY, int endIndexY, DoubleMatrix *alignmentMatrix);
|
andrew@4
|
98 bool extendRestrictedAlignmentAlong(int startX, int startY, int endIndexX, DoubleMatrix* alignmentMatrix);
|
andrew@4
|
99
|
andrew@4
|
100 double getMinimum(int i, int j, float newValue);
|
andrew@4
|
101 bool extendAlignmentUp(int endIndexY, DoubleMatrix *alignmentMatrix);
|
andrew@4
|
102 bool extendAlignmentAlong(int endIndexX, DoubleMatrix *alignmentMatrix);
|
andrew@4
|
103 void calculateMinimumAlignmentPath(DoubleMatrix alignmentMatrix);
|
andrew@4
|
104 void extendForwardAlignmentPath(int endX);
|
andrew@4
|
105
|
andrew@0
|
106
|
andrew@0
|
107 bool findPreviousMinimumInBackwardsPath();
|
andrew@0
|
108 bool testForNewAlignmentMinimum(double *previousMinimum, int i, int j);
|
andrew@0
|
109
|
andrew@0
|
110 int findMinimumOfVector(DoubleVector *d);
|
andrew@0
|
111
|
andrew@0
|
112
|
andrew@4
|
113 void addNewForwardsPath(int indexX);
|
andrew@4
|
114
|
andrew@4
|
115 void calculatePartSimilarityMatrix(DoubleMatrix firstChromaMatrix, DoubleMatrix secondChromaMatrix, DoubleMatrix* simMatrix, int startX, int startY, int endX);
|
andrew@0
|
116
|
andrew@4
|
117 // void calculatePartAlignmentMatrix(int startIndexX, int startIndexY, int endIndexX, int endIndexY, DoubleMatrix* alignmentMatrix);
|
andrew@4
|
118 void calculatePartMinimumAlignmentPath(int startX, int startY, int endX, int endY, DoubleMatrix alignmentMatrix);
|
andrew@4
|
119 bool findPreviousMinimumInPartBackwardsPath();
|
andrew@0
|
120
|
andrew@0
|
121 float diagonalPenalty;
|
andrew@0
|
122
|
andrew@0
|
123 };
|
andrew@0
|
124
|
andrew@0
|
125 #endif
|