Mercurial > hg > audio-time-warp
comparison src/timeWarp.h @ 4:f40577e6b30d
revised this to work with onset and chroma and looking now to do sequential DTW
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Wed, 08 Jun 2011 17:35:56 +0100 |
parents | 6842ff391568 |
children | 0d51e93bfe74 |
comparison
equal
deleted
inserted
replaced
3:d0242d0a48e8 | 4:f40577e6b30d |
---|---|
1 /* | 1 /* |
2 * timeWarp.h | 2 * TimeWarp.h |
3 * chromaReader13 | 3 * chromaReader13 |
4 * | 4 * |
5 * Created by Andrew on 16/05/2011. | 5 * Created by Andrew on 16/05/2011. |
6 * Copyright 2011 QMUL. All rights reserved. | 6 * Copyright 2011 QMUL. All rights reserved. |
7 * | 7 * |
21 #define FRAMESIZE 512 | 21 #define FRAMESIZE 512 |
22 #define ENERGY_LENGTH 80000 | 22 #define ENERGY_LENGTH 80000 |
23 #define CHROMA_LENGTH 12000 | 23 #define CHROMA_LENGTH 12000 |
24 #define CHROMA_CONVERSION_FACTOR 16 //16 times as many frames in energy as in chroma | 24 #define CHROMA_CONVERSION_FACTOR 16 //16 times as many frames in energy as in chroma |
25 //length in terms of frames (at 512 samples per frame - there are 90 per second) => 900: 10 seconds | 25 //length in terms of frames (at 512 samples per frame - there are 90 per second) => 900: 10 seconds |
26 #define ALIGNMENT_FRAMESIZE 128 | |
26 | 27 |
27 class timeWarp : public ofBaseApp{ | 28 class TimeWarp : public ofBaseApp{ |
28 | 29 |
29 public: | 30 public: |
30 | 31 TimeWarp(); // constructor |
31 /* | 32 ~TimeWarp(); |
32 void setup(); | |
33 void update(); | |
34 void draw(); | |
35 | |
36 void keyPressed (int key); | |
37 void keyReleased(int key); | |
38 void mouseMoved(int x, int y ); | |
39 void mouseDragged(int x, int y, int button); | |
40 void mousePressed(int x, int y, int button); | |
41 void mouseReleased(int x, int y, int button); | |
42 void windowResized(int w, int h); | |
43 | |
44 void audioRequested (float * input, int bufferSize, int nChannels); | |
45 void loadSndfile(); | |
46 */ | |
47 | |
48 double getEnergyOfFrame(); | |
49 void putEnergyInFrame(); | |
50 | 33 |
51 // void drawChromoGram(); | |
52 // void loadFirstAudioFile(); | |
53 void initialiseVariables(); | 34 void initialiseVariables(); |
54 | 35 |
55 //variables | 36 //variables |
56 typedef std::vector<double> DoubleVector; | 37 typedef std::vector<double> DoubleVector; |
57 typedef std::vector<DoubleVector> DoubleMatrix; | 38 typedef std::vector<DoubleVector> DoubleMatrix; |
58 | 39 |
59 DoubleMatrix chromaMatrix; | 40 DoubleMatrix chromaMatrix; |
60 DoubleMatrix secondMatrix; | 41 DoubleMatrix secondMatrix; |
61 DoubleMatrix* matrixPtr; | 42 DoubleMatrix* matrixPtr; |
62 | 43 |
63 // void drawDoubleMatrix(DoubleMatrix* dMatrix);//DoubleMatrix* dMatrix); WOULD BE NICE TO USE POINTER BUT NOT WORKING YET | |
64 // void drawSpectralDifference(DoubleMatrix* dMatrix); | |
65 | |
66 DoubleVector firstEnergyVector; | 44 DoubleVector firstEnergyVector; |
67 DoubleVector secondEnergyVector; | 45 DoubleVector secondEnergyVector; |
68 | |
69 DoubleMatrix similarityMatrix; | |
70 | |
71 void calculateSimilarityMatrix(); | |
72 | 46 |
73 // bool drawSimilarity; | 47 DoubleMatrix firstChromaEnergyMatrix; |
74 // void drawSimilarityMatrix(); | 48 DoubleMatrix secondChromaEnergyMatrix; |
75 // void printSimilarityMatrix(int sizeToPrint); | |
76 | 49 |
77 Chromagram chromoGramm; | 50 Chromagram chromoGramm; |
78 Chromagram secondChromoGramm; | 51 Chromagram secondChromoGramm; |
79 | 52 |
80 | 53 DoubleMatrix similarityMatrix; |
81 DoubleMatrix alignmentMeasureMatrix;//just the choma alignment | 54 DoubleMatrix tmpSimilarityMatrix; |
55 DoubleMatrix alignmentMeasureMatrix; | |
56 DoubleMatrix tmpAlignmentMeasureMatrix; | |
82 DoubleVector minimumAlignmentPath; | 57 DoubleVector minimumAlignmentPath; |
83 | 58 |
84 //new addition | 59 double partAlignmentMeasureMatrix[ALIGNMENT_FRAMESIZE][ALIGNMENT_FRAMESIZE]; |
85 DoubleMatrix superAlignmentMeasureMatrix; //for the onset + chromagram alignment | |
86 DoubleVector superMinimumAlignmentPath; | |
87 | |
88 // void drawAlignmentPath(int startingChromaXFrame, int startingChromaYFrame); | |
89 int findStartWidthFrame(); | |
90 | |
91 // void printScoreForRow(int row, int max); | |
92 | |
93 // int numberOfScrollWidthsForFirstFile; | |
94 // int numberOfScrollWidthsForSecondFile; | |
95 // void checkIfAudioPositionExceedsWidthForFirstFile(); | |
96 | 60 |
97 typedef std::vector<int> IntVector; | 61 typedef std::vector<int> IntVector; |
98 typedef std::vector<IntVector> IntMatrix; | 62 typedef std::vector<IntVector> IntMatrix; |
63 IntMatrix backwardsAlignmentPath; | |
64 IntMatrix tmpBackwardsPath; | |
99 | 65 |
100 // void updateAlignmentPathIndex(int idenifier); | 66 int backwardsAlignmentIndex; |
101 | 67 |
102 IntMatrix backwardsAlignmentPath; | 68 IntMatrix partBackwardsAlignmentPath; |
103 int backwardsAlignmentIndex; | 69 IntMatrix forwardsAlignmentPath; |
70 | |
71 int partBackwardsAlignmentIndex; | |
72 | |
73 | |
74 void createCombinedMatrix(DoubleMatrix myChromaMatrix, DoubleVector energyVector, DoubleMatrix* chromaEnergyMatrix); | |
75 | |
76 void calculateSimilarityMatrix(); | |
77 | |
78 | |
79 | |
80 | |
81 //new addition | |
82 void calculateSimilarityMatrixWithPointers(DoubleMatrix firstChromaMatrix, DoubleMatrix secondChromaMatrix, DoubleMatrix* simMatrix); | |
83 DoubleMatrix superAlignmentMeasureMatrix; //for the onset + chromagram alignment | |
84 DoubleVector superMinimumAlignmentPath; | |
85 //end new additions | |
86 | |
87 int findStartWidthFrame(); | |
88 | |
89 | |
90 | |
91 | |
92 | |
93 void calculateAlignmentMatrix(DoubleMatrix firstMatrix, DoubleMatrix secondMatrix, DoubleMatrix *alignmentMatrix); | |
94 double getDistance(int i, int j); | |
95 | |
96 double getRestrictedMinimum(int i, int j, float newValue, int minX, int minY); | |
97 bool extendRestrictedAlignmentUp(int startX, int startY, int endIndexY, DoubleMatrix *alignmentMatrix); | |
98 bool extendRestrictedAlignmentAlong(int startX, int startY, int endIndexX, DoubleMatrix* alignmentMatrix); | |
99 | |
100 double getMinimum(int i, int j, float newValue); | |
101 bool extendAlignmentUp(int endIndexY, DoubleMatrix *alignmentMatrix); | |
102 bool extendAlignmentAlong(int endIndexX, DoubleMatrix *alignmentMatrix); | |
103 void calculateMinimumAlignmentPath(DoubleMatrix alignmentMatrix); | |
104 void extendForwardAlignmentPath(int endX); | |
105 | |
104 | 106 |
105 bool findPreviousMinimumInBackwardsPath(); | 107 bool findPreviousMinimumInBackwardsPath(); |
106 bool testForNewAlignmentMinimum(double *previousMinimum, int i, int j); | 108 bool testForNewAlignmentMinimum(double *previousMinimum, int i, int j); |
107 | 109 |
108 void calculateAlignmentMatrix(); | |
109 double getDistance(int i, int j); | |
110 // void printAlignmentMatrix(); | |
111 double getMinimum(int i, int j, float newValue); | |
112 bool extendAlignmentUp(); | |
113 bool extendAlignmentAlong(); | |
114 void calculateMinimumAlignmentPath(); | |
115 int findMinimumOfVector(DoubleVector *d); | 110 int findMinimumOfVector(DoubleVector *d); |
116 // void swapBetweenPlayingFilesUsingAlignmentMatch(); | |
117 // int findMatchFromAlignment(bool whichFileToTest); | |
118 | |
119 // void drawEnergyVectorFromPointer(DoubleVector* energyVec); | |
120 | |
121 // void processAudioToDoubleMatrix(Chromagram* chromaG, DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector); | |
122 | 111 |
123 | 112 |
113 void addNewForwardsPath(int indexX); | |
114 | |
115 void calculatePartSimilarityMatrix(DoubleMatrix firstChromaMatrix, DoubleMatrix secondChromaMatrix, DoubleMatrix* simMatrix, int startX, int startY, int endX); | |
124 | 116 |
125 | 117 // void calculatePartAlignmentMatrix(int startIndexX, int startIndexY, int endIndexX, int endIndexY, DoubleMatrix* alignmentMatrix); |
126 | 118 void calculatePartMinimumAlignmentPath(int startX, int startY, int endX, int endY, DoubleMatrix alignmentMatrix); |
127 | 119 bool findPreviousMinimumInPartBackwardsPath(); |
128 | |
129 // void loadNewAudio(string soundFileName); | |
130 // void loadSecondAudio(string soundFileName); | |
131 | |
132 // void loadSoundFiles(); | |
133 // void openFileDialogBox(); | |
134 // void loadLibSndFile(const char * filename); | |
135 // bool getFilenameFromDialogBox(string* fileNameToSave); | |
136 // void openNewAudioFileWithdialogBox(); | |
137 | |
138 //int* firstAudioLength, secondAudioLength; | |
139 | |
140 // string soundFileName, secondFileName; | |
141 | |
142 // float screenHeight, screenWidth; | |
143 | |
144 | |
145 // bool moveOn; | |
146 // bool drawSpectralDifferenceFunction; | |
147 | |
148 float frame[FRAMESIZE]; | |
149 | 120 |
150 float diagonalPenalty; | 121 float diagonalPenalty; |
151 | |
152 // int frameIndex; | |
153 | |
154 // float chromoGramVector[CHROMA_LENGTH][12]; | |
155 // int rootChord[CHROMA_LENGTH]; | |
156 | |
157 // int energyIndex; | |
158 // int totalFrames; | |
159 | |
160 // int scrollWidth;// 1600 | |
161 // float chromoLength; | |
162 | |
163 // bool audioPlaying, audioPaused; | |
164 // bool drawSecondMatrix; | |
165 | |
166 /* | |
167 | |
168 | |
169 //------------------- for the simple sine wave synthesis | |
170 float targetFrequency; | |
171 float phase; | |
172 float phaseAdder; | |
173 float phaseAdderTarget; | |
174 | |
175 string sndfileInfoString, textString; | |
176 int xIndex; | |
177 | |
178 bool firstAudioFilePlaying; | |
179 ofSoundPlayer loadedAudio; | |
180 ofSoundPlayer secondAudio; | |
181 ofSoundPlayer *playingAudio; | |
182 | |
183 */ | |
184 // float audioPosition; | |
185 // float width, height; | |
186 // int chromaIndex; | |
187 // int totalNumberOfFrames; | |
188 // int currentPlayingFrame; | |
189 // int currentChromaFrame ; | |
190 | |
191 // string chordString; | |
192 | |
193 //Chromagram* chromoGrammPtr; | |
194 | |
195 | |
196 | |
197 | |
198 // string userInfoString; | |
199 // ChordDetect chord; | |
200 //sndfile part | |
201 // SNDFILE *infile; // define input and output sound files | |
202 // SF_INFO sfinfo ; // struct to hold info about sound file | |
203 | |
204 | 122 |
205 }; | 123 }; |
206 | 124 |
207 #endif | 125 #endif |