andrew@0
|
1 #include "testApp.h"
|
andrew@0
|
2 #include "stdio.h"
|
andrew@0
|
3 #include "aubio.h"
|
andrew@0
|
4 #include <iostream>
|
andrew@0
|
5 #include <cstring>
|
andrew@0
|
6 #include <string>
|
andrew@0
|
7 #include <cstdlib>
|
andrew@0
|
8
|
andrew@2
|
9
|
andrew@2
|
10
|
andrew@0
|
11 //FIX CHORDS IN THE NEW POINTER VERSION OF THE PROCESS AUDIO FN
|
andrew@0
|
12
|
andrew@0
|
13 //BUG IN WHETHER SECOND SONG LOADED OR NOT
|
andrew@0
|
14
|
andrew@0
|
15
|
andrew@0
|
16 //CHECK THAT DTW will not call beyond the limits of the two chroma if different sizes
|
andrew@0
|
17
|
andrew@0
|
18 //CALC DTW on different sizes
|
andrew@0
|
19
|
andrew@0
|
20 //CHECK CORRECT BEST ALIGNMENT METHOD FOR DTW
|
andrew@0
|
21
|
andrew@0
|
22 //RE-DO DRAW SO THAT IT DOES NOT CALCULATE EVERY POINT BUT DOES IN SQUARE CHUNKS
|
andrew@0
|
23
|
andrew@0
|
24 //UPDATE START FRAME SO ALIGNMENT IS ALWAYS ON SCREEN
|
andrew@0
|
25 //--------------------------------------------------------------
|
andrew@4
|
26
|
andrew@4
|
27 /*
|
andrew@4
|
28 Main functions here:
|
andrew@4
|
29
|
andrew@4
|
30 Load file from a dialogue box with LibSndFile
|
andrew@4
|
31 We then iterate through all the samples and call our relevant functions in the timeWarp object - i.e. onset, chroma
|
andrew@4
|
32 and do the calculations for similarity and alignment
|
andrew@4
|
33
|
andrew@4
|
34
|
andrew@4
|
35 TO DO:
|
andrew@4
|
36 Find continual alignment between the playing file and the non-playing file
|
andrew@4
|
37 - show the current location in the energy amd chroma draw fn for the non-playing file
|
andrew@4
|
38
|
andrew@4
|
39 simplify the loading procedure
|
andrew@4
|
40
|
andrew@4
|
41 */
|
andrew@4
|
42
|
andrew@4
|
43
|
andrew@0
|
44 void testApp::setup(){
|
andrew@0
|
45
|
andrew@16
|
46 doCausalAlignment = true;
|
andrew@16
|
47
|
andrew@0
|
48 ofBackground(255,255,255);
|
andrew@0
|
49
|
andrew@0
|
50 // 2 output channels,
|
andrew@0
|
51 // 0 input channels
|
andrew@0
|
52 // 22050 samples per second
|
andrew@0
|
53 // 256 samples per buffer
|
andrew@0
|
54 // 4 num buffers (latency)
|
andrew@0
|
55
|
andrew@0
|
56
|
andrew@0
|
57 // ofSetDataPathRoot("../bin/data/");
|
andrew@0
|
58
|
andrew@0
|
59 //DONT NEED ANY OF THIS
|
andrew@0
|
60 sampleRate = 44100;
|
andrew@0
|
61 phase = 0;
|
andrew@0
|
62 phaseAdder = 0.0f;
|
andrew@0
|
63 phaseAdderTarget = 0.0f;
|
andrew@0
|
64 volume = 0.1f;
|
andrew@0
|
65 bNoise = false;
|
andrew@0
|
66 lAudio = new float[256];
|
andrew@0
|
67 rAudio = new float[256];
|
andrew@0
|
68 ofSoundStreamSetup(2,0,this, sampleRate,256, 4);
|
andrew@0
|
69 //UNTIL HERE
|
andrew@0
|
70
|
andrew@0
|
71
|
andrew@0
|
72 ofSetFrameRate(60);
|
andrew@0
|
73
|
andrew@0
|
74
|
andrew@0
|
75 fvec_t * my_fvec_t;
|
andrew@0
|
76 aubio_onset_t* my_aubio_result;
|
andrew@0
|
77 aubio_onsetdetection_t * my_onset_detection;
|
andrew@0
|
78
|
andrew@5
|
79 scrollWidth = 1600;
|
andrew@5
|
80 conversionFactor = 1.0;//CHROMA_CONVERSION_FACTOR;
|
andrew@5
|
81 chromoLength = (float) scrollWidth / conversionFactor;// CHROMA_CONVERSION_FACTOR;
|
andrew@5
|
82 // chromaConversionRatio = scrollWidth / (float) conversionFactor;
|
andrew@5
|
83 // printf("initial CHROMOLENGTH %f , conv ratio %f\n", chromoLength, chromaConversionRatio);
|
andrew@0
|
84
|
andrew@0
|
85 sfinfo.format = 0;
|
andrew@0
|
86
|
andrew@0
|
87 moveOn = true;
|
andrew@2
|
88
|
andrew@2
|
89
|
andrew@2
|
90 chromaG.initialise(FRAMESIZE, CHROMAGRAM_FRAMESIZE);
|
andrew@2
|
91 onset = new OnsetDetectionFunction(512,1024,6,1);
|
andrew@2
|
92
|
andrew@0
|
93 //loading audio files
|
andrew@6
|
94 //loadSoundFiles();
|
andrew@6
|
95 //this os load soundfiles
|
andrew@0
|
96
|
andrew@6
|
97 string fullFileName = "/Users/andrew/Documents/work/programming/of_preRelease_v0061_osx_FAT/apps/my_openFrameworks/chromaReader13audioTimeWarp3/bin/data/sound/Bach_short1.wav";
|
andrew@11
|
98 secondFileName = "/Users/andrew/Documents/work/programming/of_preRelease_v0061_osx_FAT/apps/my_openFrameworks/chromaReader13audioTimeWarp3/bin/data/sound/Bach_short2.wav";
|
andrew@11
|
99
|
andrew@4
|
100
|
andrew@6
|
101 loadNewAudio(fullFileName);
|
andrew@6
|
102 /*
|
andrew@6
|
103 const char *infile_name = fullFileName.c_str();// "../../../data/sound/Bach_short1.wav"; //
|
andrew@6
|
104
|
andrew@6
|
105 loadLibSndFile(infile_name);
|
andrew@6
|
106
|
andrew@6
|
107 string loadfilename = fullFileName;//"sound/Bach_short1.wav";//
|
andrew@6
|
108 loadedAudio.loadSound(loadfilename);
|
andrew@6
|
109 playingAudio = &loadedAudio;
|
andrew@6
|
110 //end load soninf ifiels
|
andrew@6
|
111
|
andrew@6
|
112 processAudioToDoubleMatrix(&tw.chromaMatrix, &tw.firstEnergyVector);
|
andrew@6
|
113
|
andrew@6
|
114 */
|
andrew@0
|
115
|
andrew@7
|
116 // secondFileName = "../../../data/sound/Bach_short2.wav";
|
andrew@7
|
117
|
andrew@7
|
118
|
andrew@0
|
119
|
andrew@0
|
120 loadSecondAudio(secondFileName);//i.e. load same as first file
|
andrew@0
|
121
|
andrew@0
|
122 backwardsAlignmentIndex = 0;//remember that this goes backwards!
|
andrew@0
|
123
|
andrew@0
|
124 tw.initialiseVariables();
|
andrew@1
|
125
|
andrew@4
|
126 calculateSimilarityAndAlignment();
|
andrew@1
|
127
|
andrew@0
|
128 //set not to play
|
andrew@0
|
129 audioPlaying = false;
|
andrew@0
|
130
|
andrew@0
|
131 drawSecondMatrix = false;
|
andrew@0
|
132 drawSpectralDifferenceFunction = false;
|
andrew@0
|
133 drawSimilarity = true;
|
andrew@0
|
134
|
andrew@0
|
135 screenHeight = ofGetHeight() ;
|
andrew@0
|
136 screenWidth = ofGetWidth();
|
andrew@0
|
137
|
andrew@14
|
138
|
andrew@0
|
139 initialiseVariables();
|
andrew@0
|
140
|
andrew@0
|
141
|
andrew@0
|
142 }
|
andrew@8
|
143
|
andrew@0
|
144
|
andrew@0
|
145
|
andrew@4
|
146 void testApp::calculateSimilarityAndAlignment(){
|
andrew@8
|
147
|
andrew@14
|
148 tw.initialiseVariables();
|
andrew@14
|
149
|
andrew@4
|
150 //here is the main TimeWarp similarity matrix calc, the minimum alignment matrix via dtw and then the backwards path estimate
|
andrew@5
|
151 double timeBefore = ofGetElapsedTimef();
|
andrew@5
|
152 tw.calculateChromaSimilarityMatrix(&tw.chromaMatrix, &tw.secondMatrix, &tw.chromaSimilarityMatrix);
|
andrew@15
|
153
|
andrew@5
|
154 double elapsedTime = ofGetElapsedTimef() - timeBefore;
|
andrew@12
|
155 printf("CHROMA SIMILARITY ONLY TAKES %2.2f seconds\n", elapsedTime);
|
andrew@5
|
156
|
andrew@12
|
157 dontDoJunkAlignment();
|
andrew@13
|
158
|
andrew@16
|
159 if (doCausalAlignment)
|
andrew@16
|
160 calculateCausalAlignment();
|
andrew@16
|
161 else{
|
andrew@16
|
162 //tw.calculateAlignmentMatrix(tw.firstChromaEnergyMatrix, tw.secondChromaEnergyMatrix, &tw.alignmentMeasureMatrix);
|
andrew@16
|
163 tw.calculateAlignmentMatrix(tw.chromaMatrix, tw.secondMatrix, &tw.alignmentMeasureMatrix);
|
andrew@16
|
164 tw.calculateMinimumAlignmentPath(&tw.alignmentMeasureMatrix, &tw.backwardsAlignmentPath, false);
|
andrew@16
|
165 }
|
andrew@15
|
166
|
andrew@13
|
167 backwardsAlignmentIndex = tw.backwardsAlignmentPath[0].size()-1;
|
andrew@15
|
168 printf("index size is %i\n", backwardsAlignmentIndex);
|
andrew@14
|
169
|
andrew@14
|
170
|
andrew@16
|
171
|
andrew@4
|
172
|
andrew@13
|
173 setConversionRatio();
|
andrew@12
|
174
|
andrew@13
|
175 printVariousMatrixInfo();
|
andrew@13
|
176 }
|
andrew@13
|
177
|
andrew@14
|
178 void testApp::doPathBugCheck(){
|
andrew@14
|
179 //bug check
|
andrew@15
|
180 if (tw.forwardsAlignmentPath.size() > 0 && tw.forwardsAlignmentPath[1][0] != 0){
|
andrew@15
|
181 tw.forwardsAlignmentPath[1][0] = 0;//sometimes is large rndm number
|
andrew@14
|
182 printf("BUG IN FORWARDS PATH FIXED!!!\n");
|
andrew@14
|
183 }
|
andrew@14
|
184 }
|
andrew@14
|
185
|
andrew@13
|
186
|
andrew@16
|
187 void testApp::calculateCausalAlignment(){
|
andrew@16
|
188 calculateForwardsAlignment();
|
andrew@16
|
189 doPathBugCheck();
|
andrew@16
|
190 tw.copyForwardsPathToBackwardsPath();
|
andrew@16
|
191 }
|
andrew@16
|
192
|
andrew@13
|
193
|
andrew@13
|
194 void testApp::setConversionRatio(){
|
andrew@5
|
195 conversionFactor = (int) round(tw.firstEnergyVector.size() / tw.chromaMatrix.size());
|
andrew@8
|
196 chromaConversionRatio = (int) round(tw.firstEnergyVector.size() / tw.chromaMatrix.size());
|
andrew@5
|
197 chromoLength = scrollWidth / (float)conversionFactor;// CHROMA_CONVERSION_FACTOR;
|
andrew@5
|
198 printf("scrollwidth %i, conversion factor %i, chromo length %i\n", scrollWidth, (int)conversionFactor, (int)chromoLength);
|
andrew@13
|
199 }
|
andrew@13
|
200
|
andrew@13
|
201 void testApp::printVariousMatrixInfo(){
|
andrew@5
|
202
|
andrew@13
|
203 printf("large SIM SIZE%i, chrom size %ix%i\n", (int)tw.similarityMatrix.size(), (int)tw.chromaMatrix.size(), (int)tw.chromaMatrix[0].size());
|
andrew@12
|
204 if (tw.similarityMatrix.size() > 0 && tw.chromaSimilarityMatrix.size() > 0){
|
andrew@13
|
205 printf("SIM SIZE %i, and %i \n",(int) tw.similarityMatrix.size(), (int) tw.similarityMatrix[0].size());
|
andrew@13
|
206 printf("chomra sim size %i, and %i\n", (int) tw.chromaSimilarityMatrix.size(), (int)tw.chromaSimilarityMatrix[0].size());
|
andrew@12
|
207 }
|
andrew@13
|
208
|
andrew@13
|
209
|
andrew@5
|
210 //tw.printBackwardsPath(0, tw.forwardsAlignmentPath[0].size()-1, &tw.forwardsAlignmentPath);
|
andrew@5
|
211
|
andrew@13
|
212
|
andrew@5
|
213 printf("backwards path size is [0]:%i, [1]%i, \n", (int)tw.backwardsAlignmentPath[0].size(), (int)tw.backwardsAlignmentPath[1].size());
|
andrew@5
|
214
|
andrew@5
|
215 printf("backwards path size is %i, FORWARDS SIZE IS %i\n", (int)tw.backwardsAlignmentPath[0].size(), (int)tw.forwardsAlignmentPath[0].size());
|
andrew@14
|
216 //printf("BACKWARDS PATH::\n");
|
andrew@14
|
217 //tw.printBackwardsPath(0, (int)tw.backwardsAlignmentPath[0].size(), &tw.backwardsAlignmentPath);
|
andrew@4
|
218 }
|
andrew@4
|
219
|
andrew@0
|
220 void testApp::initialiseVariables(){
|
andrew@0
|
221
|
andrew@0
|
222 chromaIndex = 0;
|
andrew@0
|
223 // chromoGramm.initialise(FRAMESIZE,2048);//framesize 512 and hopsize 2048
|
andrew@0
|
224 audioPosition = 0;
|
andrew@5
|
225 if (tw.backwardsAlignmentPath.size() > 0)
|
andrew@5
|
226 backwardsAlignmentIndex = tw.backwardsAlignmentPath[0].size()-1;//go back to beginning for drawing
|
andrew@0
|
227
|
andrew@0
|
228 numberOfScrollWidthsForFirstFile = 0;
|
andrew@0
|
229 numberOfScrollWidthsForSecondFile = 0;
|
andrew@0
|
230
|
andrew@0
|
231 (*playingAudio).setPaused(true);
|
andrew@0
|
232 audioPlaying = false;
|
andrew@0
|
233 audioPaused = true;
|
andrew@0
|
234
|
andrew@14
|
235 // tw.initialiseVariables();
|
andrew@8
|
236
|
andrew@0
|
237 }
|
andrew@0
|
238
|
andrew@0
|
239
|
andrew@13
|
240 void testApp::calculateForwardsAlignment(){
|
andrew@13
|
241
|
andrew@13
|
242 tw.forwardsAlignmentPath.clear();
|
andrew@13
|
243 //causal part
|
andrew@16
|
244 int hopsize = 200;
|
andrew@14
|
245 int frameSize = 800;
|
andrew@13
|
246 int startFrameY = 0;
|
andrew@13
|
247 int startFrameX = 0;
|
andrew@13
|
248 tw.anchorPoints.clear();
|
andrew@13
|
249 for (int startFrameX = 0;startFrameX < tw.firstEnergyVector.size(); startFrameX += hopsize){//tw.firstChromaEnergyMatrix.size()
|
andrew@13
|
250 //replace this with a while startFrame < end of file
|
andrew@13
|
251 tw.addAnchorPoints(startFrameX, startFrameY);
|
andrew@13
|
252
|
andrew@13
|
253 //NEED TO ASSUME WE DON'T HAVE
|
andrew@13
|
254 double timeBefore = ofGetElapsedTimef();
|
andrew@13
|
255 printf("PART SIM: startFrameX %i, startFrameY: %i\n", startFrameX, startFrameY);
|
andrew@15
|
256 //NEW FUNCTION - calls only the energy and uses the stored chromagram
|
andrew@13
|
257
|
andrew@13
|
258 tw.calculatePartJointSimilarityMatrix(&tw.firstEnergyVector, &tw.secondEnergyVector, &tw.chromaSimilarityMatrix, &tw.tmpSimilarityMatrix,
|
andrew@13
|
259 startFrameX, startFrameY, startFrameX+frameSize, startFrameY + 3*frameSize);
|
andrew@13
|
260
|
andrew@13
|
261
|
andrew@13
|
262
|
andrew@13
|
263
|
andrew@14
|
264 // printf("TMP size of tmp sim is %i\n", (int)tw.tmpSimilarityMatrix.size());
|
andrew@13
|
265 double elapsedTime = ofGetElapsedTimef() - timeBefore;
|
andrew@14
|
266 // printf("PART SIM MATRIX CAL TAKES %f\n", elapsedTime);
|
andrew@13
|
267
|
andrew@13
|
268 //change part sim to have a y limit too
|
andrew@13
|
269
|
andrew@13
|
270
|
andrew@13
|
271 //check if we can not calculate alignment matrix for chunks of the sim matrix where it is off diagonal
|
andrew@13
|
272
|
andrew@13
|
273 tw.calculatePartAlignmentMatrix(tw.tmpSimilarityMatrix.size()-1, tw.tmpSimilarityMatrix[0].size()-1, &tw.tmpAlignmentMeasureMatrix, &tw.tmpSimilarityMatrix);
|
andrew@13
|
274
|
andrew@13
|
275 //get alignment measure minimum
|
andrew@13
|
276 //find minimum path between only the section we are interested in
|
andrew@13
|
277 //write new function to find minimum backwards path from the index we choose (not the final corner)
|
andrew@13
|
278 // int myIndex = tw.findMinimumOfMatrixColumn(tw.tmpAlignmentMeasureMatrix, tw.tmpSimilarityMatrix.size()-1);
|
andrew@13
|
279 /* printf("my index is %i\n", myIndex);
|
andrew@13
|
280 for (int i = 0;i< tw.alignmentMeasureMatrix[tw.similarityMatrix.size()-1].size() - 1;i++){
|
andrew@13
|
281 printf("Alignment[%i] : %f\n", i, tw.alignmentMeasureMatrix[tw.similarityMatrix.size()-1][i]);
|
andrew@13
|
282 }
|
andrew@13
|
283 */
|
andrew@13
|
284 printf("\n CALC PART ALIGNMENT MIN PATH\n");
|
andrew@13
|
285 tw.calculateMinimumAlignmentPath(&tw.tmpAlignmentMeasureMatrix, &tw.tmpBackwardsPath, true);//true is for greedy calculation
|
andrew@13
|
286 printf("\n PART ALIGNMENT GENERATES THIS BACKWARDS PATH:: \n");
|
andrew@13
|
287 tw.extendForwardAlignmentPath(hopsize, &tw.tmpBackwardsPath, startFrameX, startFrameY);
|
andrew@13
|
288
|
andrew@13
|
289 startFrameY = tw.forwardsAlignmentPath[1][(tw.forwardsAlignmentPath[0].size()-1)];
|
andrew@13
|
290
|
andrew@13
|
291 }//end for startFrameX
|
andrew@13
|
292
|
andrew@13
|
293 }
|
andrew@13
|
294
|
andrew@0
|
295 //--------------------------------------------------------------
|
andrew@0
|
296 void testApp::update(){
|
andrew@0
|
297 textString = "energy index [";
|
andrew@0
|
298 textString += ofToString(xIndex);
|
andrew@0
|
299 textString += "] = ";
|
andrew@0
|
300 textString += ofToString(energy[xIndex]);
|
andrew@0
|
301
|
andrew@4
|
302 // chordString = "Chord : ";
|
andrew@4
|
303 // chordString += ofToString(rootChord[currentPlayingFrame/conversionFactor]);//CHROMA_CONVERSION_FACTOR]);
|
andrew@0
|
304
|
andrew@8
|
305 audioPosition = (*playingAudio).getPosition();
|
andrew@0
|
306 if (firstAudioFilePlaying){
|
andrew@8
|
307 audioPosition *= tw.firstEnergyVector.size();
|
andrew@0
|
308 updateAlignmentPathIndex(0);
|
andrew@0
|
309 }
|
andrew@0
|
310 else {
|
andrew@8
|
311 audioPosition *= tw.secondEnergyVector.size();
|
andrew@0
|
312 updateAlignmentPathIndex(1);
|
andrew@0
|
313 }
|
andrew@0
|
314
|
andrew@0
|
315 //if(!audioPaused)
|
andrew@0
|
316 //printScoreForRow(audioPosition/CHROMA_CONVERSION_FACTOR, (audioPosition/CHROMA_CONVERSION_FACTOR)+10);
|
andrew@4
|
317
|
andrew@0
|
318
|
andrew@0
|
319 currentPlayingFrame = audioPosition;
|
andrew@0
|
320 audioPosition = (int) audioPosition % scrollWidth ;
|
andrew@0
|
321 audioPosition /= scrollWidth;
|
andrew@0
|
322
|
andrew@0
|
323 ofSoundUpdate();
|
andrew@0
|
324
|
andrew@0
|
325
|
andrew@0
|
326 }
|
andrew@0
|
327
|
andrew@0
|
328 void testApp::updateAlignmentPathIndex(int identifier){
|
andrew@1
|
329
|
andrew@9
|
330
|
andrew@5
|
331 if (tw.backwardsAlignmentPath.size() > 0){
|
andrew@9
|
332
|
andrew@9
|
333 if (backwardsAlignmentIndex >= tw.backwardsAlignmentPath[identifier].size())
|
andrew@9
|
334 backwardsAlignmentIndex = tw.backwardsAlignmentPath[identifier].size()-1;
|
andrew@9
|
335
|
andrew@1
|
336 //this is the alignment where we are currently playing - i.e. switching between files
|
andrew@0
|
337
|
andrew@8
|
338 int chromaPosition = audioPosition;///conversionFactor;//CHROMA_CONVERSION_FACTOR;
|
andrew@0
|
339
|
andrew@9
|
340 while (tw.backwardsAlignmentPath[identifier][backwardsAlignmentIndex] < chromaPosition && backwardsAlignmentIndex > 0)
|
andrew@0
|
341 {
|
andrew@0
|
342 backwardsAlignmentIndex--;
|
andrew@0
|
343 }
|
andrew@5
|
344 }
|
andrew@0
|
345
|
andrew@0
|
346 }
|
andrew@0
|
347
|
andrew@0
|
348 //--------------------------------------------------------------
|
andrew@0
|
349 void testApp::draw(){
|
andrew@0
|
350
|
andrew@5
|
351 if (drawSimilarity){
|
andrew@5
|
352 //drawSimilarityMatrix();
|
andrew@5
|
353 drawChromaSimilarityMatrix();//new fn with alignment causal including energy vector
|
andrew@5
|
354 //but chroma sim used for representation
|
andrew@5
|
355
|
andrew@5
|
356 }
|
andrew@0
|
357 else
|
andrew@5
|
358 drawDoubleMatrix(&tw.tmpSimilarityMatrix);
|
andrew@5
|
359 //drawChromoGram();
|
andrew@0
|
360
|
andrew@0
|
361
|
andrew@0
|
362 }
|
andrew@0
|
363
|
andrew@0
|
364
|
andrew@0
|
365 void testApp::drawEnergyVectorFromPointer(DoubleVector* energyVec){
|
andrew@0
|
366
|
andrew@0
|
367 float screenHeight = ofGetHeight() ;
|
andrew@0
|
368 float screenWidth = ofGetWidth();
|
andrew@2
|
369 float heightFactor = 1;
|
andrew@0
|
370 int i, j, startingFrame;
|
andrew@0
|
371 startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
|
andrew@0
|
372 startingFrame *= scrollWidth;
|
andrew@0
|
373
|
andrew@0
|
374 for (i = 0; i < scrollWidth - 1; i++){
|
andrew@2
|
375 j = min(i + startingFrame, (int)energyVec->size()-1);
|
andrew@0
|
376 ofLine(i*screenWidth/scrollWidth, screenHeight - ((*energyVec)[j]*screenHeight/heightFactor),
|
andrew@0
|
377 screenWidth*(i+1)/scrollWidth, screenHeight - ((*energyVec)[j+1]*screenHeight/heightFactor));
|
andrew@0
|
378
|
andrew@0
|
379 }
|
andrew@0
|
380 }
|
andrew@0
|
381
|
andrew@0
|
382 void testApp::drawSpectralDifference(DoubleMatrix* dMatrix){
|
andrew@0
|
383 if ((*dMatrix).size()>0){
|
andrew@0
|
384
|
andrew@0
|
385 float screenHeight = ofGetHeight() ;
|
andrew@0
|
386 float screenWidth = ofGetWidth();
|
andrew@0
|
387 float heightFactor = 8;
|
andrew@0
|
388 double difference;
|
andrew@0
|
389 int i, j, startingFrame;
|
andrew@0
|
390 startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
|
andrew@0
|
391 startingFrame *= scrollWidth;//starting frame in terms of energy frames
|
andrew@4
|
392 startingFrame /= conversionFactor;// CHROMA_CONVERSION_FACTOR; //in terms of chroma frames
|
andrew@0
|
393
|
andrew@0
|
394
|
andrew@0
|
395 for (i = 1; i < chromoLength; i++){//changed to add 1
|
andrew@2
|
396 j = min(i + startingFrame, (int) dMatrix->size()-1 );//in case out of range
|
andrew@0
|
397 for (int y = 0;y < 12;y++){
|
andrew@0
|
398 difference = (*dMatrix)[j][11-y] - (*dMatrix)[j-1][11-y];
|
andrew@0
|
399 if (difference < 0)
|
andrew@0
|
400 difference = 0;//half wave rectify
|
andrew@0
|
401
|
andrew@0
|
402 ofSetColor(0,0,255 * difference);//, 0;
|
andrew@0
|
403 ofRect(i*screenWidth/chromoLength,y*screenHeight/12,screenWidth/chromoLength,screenHeight/12);
|
andrew@0
|
404 }//end y
|
andrew@0
|
405 }//end i
|
andrew@0
|
406
|
andrew@0
|
407 }///end if matrix has content
|
andrew@0
|
408 else{
|
andrew@0
|
409 printf("Error - please load audio first");
|
andrew@0
|
410 }
|
andrew@0
|
411
|
andrew@0
|
412 }
|
andrew@0
|
413
|
andrew@0
|
414
|
andrew@0
|
415 void testApp::drawChromoGram(){
|
andrew@0
|
416
|
andrew@0
|
417 DoubleMatrix* dptr;
|
andrew@0
|
418 DoubleVector* eptr;
|
andrew@0
|
419 string whichFileString;
|
andrew@0
|
420
|
andrew@0
|
421 if (drawSecondMatrix){
|
andrew@0
|
422
|
andrew@0
|
423 dptr = &tw.secondMatrix;
|
andrew@0
|
424 eptr = &tw.secondEnergyVector;
|
andrew@0
|
425
|
andrew@0
|
426 whichFileString = "second file";
|
andrew@0
|
427
|
andrew@0
|
428 }else {
|
andrew@0
|
429
|
andrew@0
|
430 dptr = &tw.chromaMatrix;
|
andrew@0
|
431 eptr = &tw.firstEnergyVector;
|
andrew@0
|
432 whichFileString = "first file";
|
andrew@0
|
433 }
|
andrew@0
|
434
|
andrew@0
|
435
|
andrew@0
|
436
|
andrew@0
|
437 if (drawSpectralDifferenceFunction)
|
andrew@0
|
438 drawSpectralDifference(dptr);
|
andrew@0
|
439 else
|
andrew@0
|
440 drawDoubleMatrix(dptr);
|
andrew@0
|
441
|
andrew@0
|
442 ofSetColor(0xFF6666);
|
andrew@0
|
443 drawEnergyVectorFromPointer(eptr);
|
andrew@0
|
444
|
andrew@0
|
445 ofDrawBitmapString(textString,80,480);
|
andrew@0
|
446
|
andrew@0
|
447
|
andrew@0
|
448 ofSetColor(0xFFFFFF);
|
andrew@0
|
449 ofLine(audioPosition*width, 0, audioPosition*width, height);
|
andrew@0
|
450
|
andrew@0
|
451
|
andrew@0
|
452 ofDrawBitmapString(chordString,80,580);
|
andrew@0
|
453
|
andrew@0
|
454 ofDrawBitmapString(soundFileName,80,480);
|
andrew@0
|
455
|
andrew@0
|
456 ofDrawBitmapString(whichFileString,80,80);
|
andrew@0
|
457
|
andrew@0
|
458 }
|
andrew@0
|
459
|
andrew@0
|
460 void testApp::drawDoubleMatrix(DoubleMatrix* dMatrix){
|
andrew@5
|
461
|
andrew@5
|
462
|
andrew@0
|
463 if ((*dMatrix).size()>0){
|
andrew@5
|
464 int matrixWidth = (*dMatrix).size();
|
andrew@5
|
465 int matrixHeight = (*dMatrix)[0].size();
|
andrew@5
|
466
|
andrew@0
|
467 float screenHeight = ofGetHeight() ;
|
andrew@0
|
468 float screenWidth = ofGetWidth();
|
andrew@5
|
469 /* float heightFactor = 8;
|
andrew@0
|
470 int i, j, startingFrame;
|
andrew@0
|
471 startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
|
andrew@0
|
472 startingFrame *= scrollWidth;//starting frame in terms of energy frames
|
andrew@4
|
473 startingFrame /= conversionFactor;//CHROMA_CONVERSION_FACTOR; //in terms of chroma frames
|
andrew@0
|
474
|
andrew@5
|
475
|
andrew@5
|
476 float chromoLength = scrollWidth/conversionFactor;// CHROMA_CONVERSION_FACTOR;
|
andrew@5
|
477 for (i = 0; i < chromoLength; i++){
|
andrew@5
|
478 j = min(i + startingFrame, (int) dMatrix->size()-1 ) ;
|
andrew@5
|
479 for (int y = 0;y < 12;y++){
|
andrew@5
|
480 ofSetColor(0,0,255 * (*dMatrix)[j][11-y]);//, 0;
|
andrew@5
|
481 ofRect(i*screenWidth/chromoLength,y*screenHeight/12,screenWidth/chromoLength,screenHeight/12);
|
andrew@5
|
482 }//end y
|
andrew@5
|
483 }//end i
|
andrew@5
|
484
|
andrew@5
|
485 */
|
andrew@5
|
486
|
andrew@5
|
487 float ratio = max(matrixWidth/screenWidth,matrixHeight/screenHeight);
|
andrew@5
|
488 for (int x = 0; x < screenWidth; x+= 5){
|
andrew@5
|
489 //j = min(i + startingFrame, (int) dMatrix->size()-1 ) ;
|
andrew@5
|
490 for (int y = 0;y < screenHeight;y+= 5){
|
andrew@5
|
491 int xIndex = (int)(x*ratio);
|
andrew@5
|
492 int yIndex = (int)(y*ratio);
|
andrew@5
|
493
|
andrew@5
|
494 if (xIndex < matrixWidth && yIndex < matrixHeight)
|
andrew@5
|
495 ofSetColor(0,0,255 * (*dMatrix)[xIndex][yIndex]);//, 0;
|
andrew@5
|
496 else
|
andrew@5
|
497 ofSetColor(0,0,0);
|
andrew@5
|
498
|
andrew@5
|
499 ofRect(x,y,5,5);//screenWidth/matrixWidth,screenHeight/matrixHeight);
|
andrew@0
|
500 }//end y
|
andrew@0
|
501 }//end i
|
andrew@0
|
502
|
andrew@0
|
503 }///end if matrix has content
|
andrew@0
|
504 else{
|
andrew@0
|
505 printf("Error - please load audio first");
|
andrew@0
|
506 }
|
andrew@0
|
507
|
andrew@0
|
508
|
andrew@0
|
509 }
|
andrew@0
|
510
|
andrew@0
|
511
|
andrew@0
|
512 void testApp::drawSimilarityMatrix(){
|
andrew@0
|
513
|
andrew@0
|
514 int simHeight = (tw.similarityMatrix[0]).size();
|
andrew@0
|
515 int simWidth = tw.similarityMatrix.size();
|
andrew@0
|
516
|
andrew@4
|
517 int sizeOfMatrix = (int) tw.similarityMatrix.size();//tw.chromaMatrix.size();
|
andrew@4
|
518 int sizeOfSecondMatrix = (int) tw.similarityMatrix[0].size();
|
andrew@0
|
519
|
andrew@5
|
520 //in chromagram frames
|
andrew@5
|
521 int startingXframe = tw.chromaSimilarityMatrix.size() / (scrollWidth/conversionFactor);
|
andrew@5
|
522 int startingYframe = tw.chromaSimilarityMatrix[0].size() / (scrollWidth/conversionFactor);
|
andrew@5
|
523
|
andrew@8
|
524
|
andrew@5
|
525 if (tw.backwardsAlignmentPath.size() > 0){
|
andrew@5
|
526 startingXframe = tw.backwardsAlignmentPath[0][backwardsAlignmentIndex] / (scrollWidth/conversionFactor);
|
andrew@5
|
527 startingYframe = tw.backwardsAlignmentPath[1][backwardsAlignmentIndex] / (scrollWidth/conversionFactor);
|
andrew@5
|
528 }
|
andrew@8
|
529
|
andrew@4
|
530 startingXframe = startingXframe * scrollWidth/conversionFactor;
|
andrew@4
|
531 startingYframe = startingYframe * scrollWidth/conversionFactor;
|
andrew@8
|
532
|
andrew@8
|
533 // int startingFrame = findStartWidthFrame();
|
andrew@8
|
534 // startingFrame = numberOfScrollWidthsForFirstFile * scrollWidth/conversionFactor;
|
andrew@8
|
535
|
andrew@8
|
536
|
andrew@0
|
537 //need to fix for second file too
|
andrew@0
|
538
|
andrew@0
|
539 int *indexOfAlignmentPathTested;
|
andrew@5
|
540 int lengthOfPath = 0;
|
andrew@5
|
541 if (tw.backwardsAlignmentPath.size() > 0)
|
andrew@5
|
542 lengthOfPath = tw.backwardsAlignmentPath[0].size()-1;
|
andrew@5
|
543
|
andrew@0
|
544 indexOfAlignmentPathTested = &lengthOfPath;
|
andrew@0
|
545
|
andrew@0
|
546 int xcoord;
|
andrew@0
|
547 for (int x = 0;x < screenWidth;x++)
|
andrew@0
|
548 {
|
andrew@0
|
549 for (int y =0;y < screenHeight;y++){
|
andrew@0
|
550
|
andrew@0
|
551 xcoord = (x / screenWidth) * chromoLength;//was simWidth
|
andrew@0
|
552 //xcoord += startingFrame;
|
andrew@0
|
553 xcoord += startingXframe;
|
andrew@0
|
554
|
andrew@0
|
555 int ycoord = y * chromoLength/ screenHeight;
|
andrew@0
|
556 //ycoord += startingFrame;
|
andrew@0
|
557 ycoord += startingYframe;
|
andrew@0
|
558
|
andrew@0
|
559 int colour = 0;
|
andrew@0
|
560 //int ycoord = y * simHeight/ screenHeight;
|
andrew@0
|
561 //y += startingFrame;
|
andrew@0
|
562 if (xcoord < sizeOfMatrix && ycoord < sizeOfSecondMatrix)
|
andrew@0
|
563 colour = tw.similarityMatrix[xcoord][ycoord]*255;
|
andrew@0
|
564
|
andrew@5
|
565
|
andrew@0
|
566
|
andrew@0
|
567 ofSetColor(colour,0,0);
|
andrew@0
|
568
|
andrew@0
|
569 ofRect(x,y,1,1);
|
andrew@0
|
570
|
andrew@0
|
571 }
|
andrew@0
|
572 }
|
andrew@0
|
573
|
andrew@5
|
574
|
andrew@5
|
575
|
andrew@5
|
576 ofSetColor(0,255,255);
|
andrew@5
|
577 // drawAlignmentPath(startingXframe, startingYframe, &tw.tmpBackwardsPath);
|
andrew@4
|
578 drawForwardsAlignmentPath(startingXframe, startingYframe);
|
andrew@0
|
579
|
andrew@5
|
580
|
andrew@5
|
581 // ofSetColor(0,0,255);
|
andrew@5
|
582 // drawAlignmentPath(startingXframe, startingYframe, &tw.backwardsAlignmentPath);
|
andrew@5
|
583
|
andrew@5
|
584
|
andrew@0
|
585 //SET TEXT
|
andrew@5
|
586 ofSetColor(255 ,255,255);
|
andrew@0
|
587 string textString;
|
andrew@0
|
588 textString = "width : ";
|
andrew@0
|
589 textString += ofToString(simWidth);
|
andrew@0
|
590
|
andrew@0
|
591 textString += " height : ";
|
andrew@0
|
592 textString += ofToString(simHeight);
|
andrew@0
|
593
|
andrew@8
|
594 // textString += " startframe : ";
|
andrew@8
|
595 // textString += ofToString(startingFrame);
|
andrew@0
|
596
|
andrew@0
|
597 textString += " Xframe : ";
|
andrew@0
|
598 textString += ofToString(startingXframe);
|
andrew@0
|
599
|
andrew@0
|
600 textString += " Yframe : ";
|
andrew@0
|
601 textString += ofToString(startingYframe);
|
andrew@0
|
602
|
andrew@0
|
603 textString += " currentFrame : ";
|
andrew@0
|
604 textString += ofToString(currentPlayingFrame);
|
andrew@0
|
605
|
andrew@0
|
606 textString += " scrollwidth: ";
|
andrew@0
|
607 textString += ofToString(scrollWidth);
|
andrew@0
|
608
|
andrew@0
|
609 textString += " xcoord: ";
|
andrew@0
|
610 textString += ofToString(xcoord);
|
andrew@0
|
611
|
andrew@0
|
612 textString += " Clength: ";
|
andrew@0
|
613 textString += ofToString(chromoLength);
|
andrew@0
|
614
|
andrew@0
|
615 textString += " no.Scrolls: ";
|
andrew@0
|
616 textString += ofToString(numberOfScrollWidthsForFirstFile);
|
andrew@0
|
617 //END SET TEXT
|
andrew@0
|
618
|
andrew@5
|
619 ofSetColor(0x0000FF);// && tw.backwardsAlignmentPath.size() > 0
|
andrew@5
|
620 if (firstAudioFilePlaying){// && tw.alignmentMeasureMatrix.size() > 0
|
andrew@5
|
621 ofLine(audioPosition*screenWidth, 0, audioPosition*screenWidth, height);
|
andrew@0
|
622 checkIfAudioPositionExceedsWidthForFirstFile();
|
andrew@5
|
623 // drawAlignmentmeasureValues(currentPlayingFrame);
|
andrew@0
|
624 }
|
andrew@0
|
625 else{
|
andrew@0
|
626 ofLine(0, audioPosition*screenHeight, screenWidth, audioPosition*screenHeight);
|
andrew@0
|
627 }
|
andrew@0
|
628
|
andrew@0
|
629 ofDrawBitmapString(textString,80,580);
|
andrew@0
|
630
|
andrew@0
|
631 ofDrawBitmapString(userInfoString,80,80);
|
andrew@0
|
632
|
andrew@0
|
633 }
|
andrew@0
|
634
|
andrew@0
|
635
|
andrew@5
|
636
|
andrew@5
|
637
|
andrew@5
|
638 void testApp::drawChromaSimilarityMatrix(){
|
andrew@5
|
639 //scrollwidth is width in terms of the similarity matrix size (or energy size if we are being accurate)
|
andrew@5
|
640 //need to get rid of dependency on sim matirx and only use chrom sim matrix
|
andrew@5
|
641
|
andrew@5
|
642 // int simHeight = (tw.similarityMatrix[0]).size();
|
andrew@5
|
643 // int simWidth = tw.similarityMatrix.size();
|
andrew@5
|
644
|
andrew@5
|
645 // int sizeOfMatrix = (int) tw.similarityMatrix.size();//tw.chromaMatrix.size();
|
andrew@5
|
646 // int sizeOfSecondMatrix = (int) tw.similarityMatrix[0].size();
|
andrew@5
|
647
|
andrew@5
|
648 float chromogramScrollWidth = (scrollWidth/conversionFactor);
|
andrew@5
|
649 //frames needed in energy still
|
andrew@5
|
650 //in chromagram frames
|
andrew@5
|
651 int startingXframe = (tw.firstEnergyVector.size() / scrollWidth);
|
andrew@8
|
652 int startingYframe = (tw.secondEnergyVector.size() / scrollWidth);//secondMatrix
|
andrew@5
|
653
|
andrew@5
|
654 // printf("DRAW SIM SIZE start frames %i x %i \n", startingXframe, startingYframe);
|
andrew@8
|
655 if (tw.backwardsAlignmentPath.size() > 0 ){
|
andrew@8
|
656 startingXframe = (tw.backwardsAlignmentPath[0][backwardsAlignmentIndex]/ scrollWidth);
|
andrew@9
|
657 startingYframe = max(0 , (int)(tw.backwardsAlignmentPath[1][backwardsAlignmentIndex]/ scrollWidth));//*conversionFactor
|
andrew@5
|
658 //FIX THE 1 - ASDDED AS DEBUG
|
andrew@5
|
659 // printf("alignment index %i, VERSUS DRAW SIM SIZE %i x %i \n", backwardsAlignmentIndex, startingXframe, startingYframe);
|
andrew@5
|
660 }
|
andrew@5
|
661
|
andrew@5
|
662 //PROBLEM IS THAT THE y value startYframe is not correctly incremented
|
andrew@5
|
663
|
andrew@8
|
664 //tmp
|
andrew@8
|
665 // startingXframe = 0;
|
andrew@8
|
666 // startingYframe = 0;
|
andrew@5
|
667
|
andrew@8
|
668 // int startingFrame = findStartWidthFrame();
|
andrew@8
|
669 // startingFrame = numberOfScrollWidthsForFirstFile * scrollWidth/conversionFactor;
|
andrew@5
|
670
|
andrew@5
|
671 startingXframe *= scrollWidth;// /conversionFactor;
|
andrew@5
|
672 startingYframe *= scrollWidth;// /conversionFactor;
|
andrew@5
|
673 //need to fix for second file too
|
andrew@5
|
674
|
andrew@5
|
675 int *indexOfAlignmentPathTested;
|
andrew@5
|
676 int lengthOfPath = 0;
|
andrew@5
|
677 if (tw.backwardsAlignmentPath.size() > 0)
|
andrew@5
|
678 lengthOfPath = tw.backwardsAlignmentPath[0].size()-1;
|
andrew@5
|
679
|
andrew@5
|
680 indexOfAlignmentPathTested = &lengthOfPath;
|
andrew@5
|
681
|
andrew@5
|
682 int xcoord, ycoord;
|
andrew@5
|
683 for (int x = 0;x < screenWidth;x++)
|
andrew@5
|
684 {
|
andrew@5
|
685 for (int y =0;y < screenHeight;y++){
|
andrew@5
|
686
|
andrew@5
|
687 xcoord = (x / screenWidth) * scrollWidth;//i.e. chromoLength * conversionFactor;
|
andrew@5
|
688 xcoord += startingXframe;
|
andrew@5
|
689
|
andrew@5
|
690 int xChromaCoord = xcoord / conversionFactor;
|
andrew@5
|
691
|
andrew@5
|
692 ycoord = y * chromoLength * conversionFactor/ screenHeight;
|
andrew@5
|
693 ycoord += startingYframe;
|
andrew@5
|
694
|
andrew@5
|
695 int yChromaCoord = ycoord / conversionFactor;
|
andrew@5
|
696
|
andrew@5
|
697 int colour = 0;//0x006644;
|
andrew@5
|
698
|
andrew@5
|
699
|
andrew@5
|
700 /* if (xcoord < tw.similarityMatrix.size() && ycoord < tw.similarityMatrix[0].size()){//
|
andrew@5
|
701 //nb not optimised
|
andrew@5
|
702 colour = tw.similarityMatrix[xcoord][ycoord]*255;
|
andrew@5
|
703 }
|
andrew@5
|
704 */
|
andrew@5
|
705 if (xChromaCoord < tw.chromaSimilarityMatrix.size() && yChromaCoord < tw.chromaSimilarityMatrix[0].size()){
|
andrew@5
|
706 colour = tw.chromaSimilarityMatrix[xChromaCoord][yChromaCoord]*255;
|
andrew@5
|
707 }
|
andrew@5
|
708
|
andrew@5
|
709
|
andrew@5
|
710 ofSetColor(colour,0,0);
|
andrew@5
|
711
|
andrew@5
|
712 ofRect(x,y,1,1);
|
andrew@5
|
713
|
andrew@5
|
714 }
|
andrew@5
|
715 }
|
andrew@5
|
716
|
andrew@5
|
717
|
andrew@5
|
718
|
andrew@5
|
719 // ofSetColor(0,0,255);
|
andrew@5
|
720 // drawAlignmentPath(startingXframe, startingYframe, &tw.backwardsAlignmentPath);
|
andrew@5
|
721 //ALIGNMENT PATH doesnt work yet - scae rpobllem
|
andrew@5
|
722
|
andrew@5
|
723
|
andrew@5
|
724 ofSetColor(0,255,255);
|
andrew@5
|
725 // drawAlignmentPath(startingXframe, startingYframe, &tw.tmpBackwardsPath);
|
andrew@8
|
726
|
andrew@5
|
727 drawForwardsAlignmentPathOnChromaSimilarity(startingXframe, startingYframe);
|
andrew@5
|
728
|
andrew@10
|
729 drawAnchorPointsOnChromaSimilarity(startingXframe, startingYframe);
|
andrew@5
|
730
|
andrew@5
|
731
|
andrew@5
|
732 //SET TEXT
|
andrew@5
|
733 ofSetColor(255 ,255,255);
|
andrew@5
|
734 string textString;
|
andrew@5
|
735 /* textString = "width : ";
|
andrew@5
|
736 textString += ofToString(simWidth);
|
andrew@5
|
737
|
andrew@5
|
738 textString += " height : ";
|
andrew@5
|
739 textString += ofToString(simHeight);
|
andrew@5
|
740 */
|
andrew@8
|
741 // textString += " startframe : ";
|
andrew@8
|
742 // textString += ofToString(startingFrame);
|
andrew@5
|
743
|
andrew@5
|
744 textString += " Xframe : ";
|
andrew@5
|
745 textString += ofToString(startingXframe);
|
andrew@5
|
746
|
andrew@5
|
747 textString += " back[0] ";
|
andrew@5
|
748 textString += ofToString(tw.backwardsAlignmentPath[0][backwardsAlignmentIndex]);
|
andrew@5
|
749
|
andrew@5
|
750 textString += " Yframe : ";
|
andrew@5
|
751 textString += ofToString(startingYframe);
|
andrew@5
|
752
|
andrew@5
|
753
|
andrew@5
|
754 textString += " back[1] ";
|
andrew@5
|
755 textString += ofToString(tw.backwardsAlignmentPath[1][backwardsAlignmentIndex]);
|
andrew@5
|
756
|
andrew@5
|
757
|
andrew@5
|
758 textString += " currentFrame : ";
|
andrew@5
|
759 textString += ofToString(currentPlayingFrame);
|
andrew@5
|
760
|
andrew@5
|
761
|
andrew@5
|
762 textString += " backalign index : ";
|
andrew@5
|
763 textString += ofToString(backwardsAlignmentIndex);
|
andrew@5
|
764
|
andrew@5
|
765
|
andrew@5
|
766 textString += " scrollwidth: ";
|
andrew@5
|
767 textString += ofToString(scrollWidth);
|
andrew@5
|
768
|
andrew@5
|
769 textString += " xcoord: ";
|
andrew@5
|
770 textString += ofToString(xcoord);
|
andrew@5
|
771
|
andrew@5
|
772 textString += " Clength: ";
|
andrew@5
|
773 textString += ofToString(chromoLength);
|
andrew@5
|
774
|
andrew@5
|
775 textString += " no.Scrolls: ";
|
andrew@5
|
776 textString += ofToString(numberOfScrollWidthsForFirstFile);
|
andrew@5
|
777 //END SET TEXT
|
andrew@5
|
778
|
andrew@5
|
779 ofSetColor(0x0000FF);// && tw.backwardsAlignmentPath.size() > 0
|
andrew@5
|
780 if (firstAudioFilePlaying){// && tw.alignmentMeasureMatrix.size() > 0
|
andrew@5
|
781 ofLine(audioPosition*screenWidth, 0, audioPosition*screenWidth, height);
|
andrew@5
|
782 checkIfAudioPositionExceedsWidthForFirstFile();
|
andrew@5
|
783 // drawAlignmentmeasureValues(currentPlayingFrame);
|
andrew@5
|
784 }
|
andrew@5
|
785 else{
|
andrew@5
|
786 ofLine(0, audioPosition*screenHeight, screenWidth, audioPosition*screenHeight);
|
andrew@5
|
787 }
|
andrew@5
|
788
|
andrew@5
|
789 ofDrawBitmapString(textString,80,580);
|
andrew@5
|
790
|
andrew@5
|
791 ofDrawBitmapString(userInfoString,80,80);
|
andrew@5
|
792
|
andrew@5
|
793 }
|
andrew@5
|
794
|
andrew@5
|
795
|
andrew@5
|
796
|
andrew@5
|
797
|
andrew@5
|
798
|
andrew@5
|
799
|
andrew@5
|
800
|
andrew@5
|
801
|
andrew@5
|
802
|
andrew@5
|
803 void testApp::drawAlignmentmeasureValues(const int& startingYframe){
|
andrew@5
|
804 //draw values:
|
andrew@5
|
805 /*
|
andrew@5
|
806 int xcoord = currentPlayingFrame / conversionFactor;
|
andrew@5
|
807 ofSetColor(255, 255, 255);
|
andrew@5
|
808 for (int y = 0;y < chromoLength; y+=max(1, (int)(20 * chromoLength / screenHeight))){
|
andrew@5
|
809
|
andrew@5
|
810 float value = tw.alignmentMeasureMatrix[xcoord][y+startingYframe];
|
andrew@5
|
811 int ycoord = y * screenHeight/chromoLength;
|
andrew@5
|
812 ofDrawBitmapString(ofToString(value, 2) , audioPosition*screenWidth , ycoord);
|
andrew@5
|
813 }
|
andrew@5
|
814 */
|
andrew@5
|
815 }
|
andrew@5
|
816
|
andrew@0
|
817 void testApp::checkIfAudioPositionExceedsWidthForFirstFile()
|
andrew@0
|
818 {
|
andrew@0
|
819 if (currentPlayingFrame > scrollWidth*(numberOfScrollWidthsForFirstFile+1))
|
andrew@0
|
820 numberOfScrollWidthsForFirstFile++;
|
andrew@0
|
821 }
|
andrew@0
|
822
|
andrew@0
|
823 int testApp::findStartWidthFrame(){
|
andrew@0
|
824 int startingFrame;
|
andrew@8
|
825 /*
|
andrew@0
|
826 startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
|
andrew@0
|
827 startingFrame *= scrollWidth;//starting frame in terms of energy frames
|
andrew@4
|
828 startingFrame /= conversionFactor;// CHROMA_CONVERSION_FACTOR;
|
andrew@8
|
829 */
|
andrew@0
|
830 return startingFrame;
|
andrew@0
|
831 }
|
andrew@0
|
832
|
andrew@5
|
833 void testApp::drawAlignmentPath(int startingChromaXFrame, int startingChromaYFrame, IntMatrix* backPath){
|
andrew@5
|
834 // if (tw.alignmentMeasureMatrix.size() > 0){
|
andrew@5
|
835 if ((*backPath).size() > 0){
|
andrew@0
|
836 //draw alignment path
|
andrew@0
|
837 int endingChromaXFrame = startingChromaXFrame + chromoLength;
|
andrew@0
|
838 int endingChromaYFrame = startingChromaYFrame + chromoLength;
|
andrew@0
|
839
|
andrew@0
|
840 float chromoWidth = screenWidth / chromoLength;
|
andrew@0
|
841 float chromoHeight = screenHeight / chromoLength;
|
andrew@0
|
842
|
andrew@5
|
843 int index = (*backPath)[0].size()-1;
|
andrew@0
|
844 //OPTIMISE XXX
|
andrew@0
|
845
|
andrew@0
|
846
|
andrew@5
|
847 while ((*backPath)[0][index] < startingChromaXFrame){
|
andrew@0
|
848 index --;
|
andrew@0
|
849 }
|
andrew@0
|
850
|
andrew@0
|
851 int printIndex = index;
|
andrew@5
|
852 int backAlign = (*backPath)[0][index];
|
andrew@0
|
853 int printxcoord;
|
andrew@0
|
854 int xcoord;
|
andrew@0
|
855
|
andrew@5
|
856 while ((*backPath)[0][index] < endingChromaXFrame) {
|
andrew@5
|
857 // xcoord = min((int)(tw.similarityMatrix.size())-1,(*backPath)[0][index]);
|
andrew@5
|
858 xcoord = (*backPath)[0][index];
|
andrew@5
|
859 //int ycoord = min((int)(*backPath)[1][index], (int)(tw.alignmentMeasureMatrix[0].size())-1);
|
andrew@5
|
860 int ycoord = (int)(*backPath)[1][index];
|
andrew@5
|
861 printxcoord = xcoord;
|
andrew@5
|
862 // int colour = tw.similarityMatrix[xcoord][ycoord]*255;
|
andrew@0
|
863
|
andrew@5
|
864 //float value = 0;
|
andrew@5
|
865 //if (xcoord < tw.alignmentMeasureMatrix.size() && ycoord < tw.alignmentMeasureMatrix[xcoord].size())
|
andrew@5
|
866 //float value = tw.alignmentMeasureMatrix[xcoord][ycoord] ;
|
andrew@5
|
867
|
andrew@0
|
868
|
andrew@0
|
869 xcoord -= startingChromaXFrame;
|
andrew@0
|
870 ycoord -= startingChromaYFrame;
|
andrew@5
|
871
|
andrew@0
|
872 ofRect(xcoord*chromoWidth, ycoord*chromoHeight, chromoWidth, chromoHeight);
|
andrew@5
|
873
|
andrew@0
|
874 index--;
|
andrew@0
|
875 }
|
andrew@0
|
876
|
andrew@0
|
877 // drawHoverAlignmentValues();
|
andrew@5
|
878 // printf("ALIGN score :[%i] : %f \n", backwardsAlignmentPath[1][backwardsAlignmentIndex], ureMatrix[ backwardsAlignmentPath[0][backwardsAlignmentIndex] ][ (int) backwardsAlignmentPath[1][backwardsAlignmentIndex] ]);
|
andrew@0
|
879
|
andrew@5
|
880 /*
|
andrew@0
|
881 //SET TEXT
|
andrew@0
|
882 string textString;
|
andrew@0
|
883 textString = "ALIGNMENT PATH ";
|
andrew@0
|
884
|
andrew@0
|
885 textString += "backward A index ";
|
andrew@0
|
886 textString += ofToString(backwardsAlignmentIndex);
|
andrew@0
|
887
|
andrew@0
|
888 textString += " starting X frame ";
|
andrew@0
|
889 textString += ofToString(startingChromaXFrame);
|
andrew@0
|
890
|
andrew@0
|
891 textString += " initial xcoord ";
|
andrew@0
|
892 textString += ofToString(printxcoord);
|
andrew@0
|
893
|
andrew@0
|
894 textString += " first index ";
|
andrew@0
|
895 textString += ofToString(printIndex);
|
andrew@0
|
896
|
andrew@0
|
897 textString += " backalign[index] ";
|
andrew@0
|
898 textString += ofToString(backAlign);
|
andrew@0
|
899
|
andrew@0
|
900 textString += " final xcoord ";
|
andrew@0
|
901 textString += ofToString(xcoord);
|
andrew@0
|
902
|
andrew@5
|
903 */
|
andrew@0
|
904
|
andrew@0
|
905
|
andrew@0
|
906 ofSetColor(255,255,255);
|
andrew@0
|
907 ofDrawBitmapString(textString,80,640);
|
andrew@5
|
908 }//end if alignment path > 0
|
andrew@5
|
909 //else{
|
andrew@5
|
910 // printf("al measure mat not in range \n");
|
andrew@5
|
911 // }
|
andrew@0
|
912 }
|
andrew@0
|
913
|
andrew@0
|
914
|
andrew@0
|
915
|
andrew@0
|
916
|
andrew@0
|
917
|
andrew@0
|
918
|
andrew@4
|
919
|
andrew@4
|
920 void testApp::drawForwardsAlignmentPath(int startingChromaXFrame, int startingChromaYFrame){
|
andrew@5
|
921
|
andrew@5
|
922 //using starting frame in energy vector
|
andrew@5
|
923
|
andrew@4
|
924 if (tw.forwardsAlignmentPath.size() > 0){
|
andrew@4
|
925 int endingChromaXFrame = startingChromaXFrame + chromoLength;
|
andrew@4
|
926 int endingChromaYFrame = startingChromaYFrame + chromoLength;
|
andrew@4
|
927
|
andrew@4
|
928 float chromoWidth = screenWidth / chromoLength;
|
andrew@4
|
929 float chromoHeight = screenHeight / chromoLength;
|
andrew@4
|
930
|
andrew@4
|
931 int index = 0;
|
andrew@4
|
932 //OPTIMISE XXX
|
andrew@4
|
933
|
andrew@4
|
934 while (tw.forwardsAlignmentPath[0][index] < startingChromaXFrame){
|
andrew@4
|
935 //get to NOW
|
andrew@4
|
936 index ++;
|
andrew@4
|
937 }
|
andrew@4
|
938
|
andrew@4
|
939 int xcoord;
|
andrew@12
|
940 //replacing tw.similarityMatrix.size() by first e vec below
|
andrew@4
|
941
|
andrew@4
|
942 while (index < tw.forwardsAlignmentPath[0].size() && tw.forwardsAlignmentPath[0][index] < endingChromaXFrame) {
|
andrew@12
|
943 xcoord = min((int)(tw.firstEnergyVector.size())-1,tw.forwardsAlignmentPath[0][index]);
|
andrew@5
|
944 int ycoord = (int)tw.forwardsAlignmentPath[1][index];
|
andrew@5
|
945
|
andrew@5
|
946 if (tw.alignmentMeasureMatrix.size() > 0)
|
andrew@5
|
947 ycoord = min((int)tw.forwardsAlignmentPath[1][index], (int)(tw.alignmentMeasureMatrix[0].size())-1);
|
andrew@4
|
948
|
andrew@4
|
949 // printxcoord = xcoord;
|
andrew@4
|
950 int colour = 255;//tw.similarityMatrix[xcoord][ycoord]*255;
|
andrew@4
|
951 //float value = tw.alignmentMeasureMatrix[xcoord][ycoord] ;
|
andrew@4
|
952
|
andrew@4
|
953 xcoord -= startingChromaXFrame;
|
andrew@4
|
954 ycoord -= startingChromaYFrame;
|
andrew@4
|
955 ofSetColor(0,colour,0);
|
andrew@4
|
956 ofRect(xcoord*chromoWidth, ycoord*chromoHeight, chromoWidth, chromoHeight);
|
andrew@4
|
957 index++;
|
andrew@4
|
958 }//end while
|
andrew@4
|
959
|
andrew@4
|
960 }//end if forwards path exista
|
andrew@4
|
961
|
andrew@4
|
962 }
|
andrew@4
|
963
|
andrew@4
|
964
|
andrew@4
|
965
|
andrew@4
|
966
|
andrew@4
|
967
|
andrew@5
|
968 void testApp::drawForwardsAlignmentPathOnChromaSimilarity(const int& startingXFrame, const int& startingYFrame){
|
andrew@5
|
969
|
andrew@5
|
970 //using starting frame in energy vector
|
andrew@5
|
971
|
andrew@5
|
972 if (tw.forwardsAlignmentPath.size() > 0){
|
andrew@5
|
973 int endingChromaXFrame = startingXFrame + scrollWidth;
|
andrew@5
|
974 int endingChromaYFrame = startingYFrame + scrollWidth;
|
andrew@5
|
975
|
andrew@5
|
976 float energyVectorWidth = screenWidth / scrollWidth;
|
andrew@5
|
977 float energyVectorHeight = screenHeight / scrollWidth;
|
andrew@5
|
978
|
andrew@10
|
979 int index = max(0, (int)tw.backwardsAlignmentPath[0].size() - backwardsAlignmentIndex);
|
andrew@5
|
980 //OPTIMISE XXX
|
andrew@10
|
981 while (index > 0 && tw.forwardsAlignmentPath[0][index] > startingXFrame){
|
andrew@10
|
982 //get to NOW
|
andrew@10
|
983 index --;
|
andrew@10
|
984 }
|
andrew@5
|
985
|
andrew@5
|
986 while (tw.forwardsAlignmentPath[0][index] < startingXFrame){
|
andrew@5
|
987 //get to NOW
|
andrew@5
|
988 index ++;
|
andrew@5
|
989 }
|
andrew@5
|
990
|
andrew@5
|
991 int xcoord;
|
andrew@12
|
992 //replacing tw.similarityMatrix.size() by fiorst e vec
|
andrew@5
|
993 while (index < tw.forwardsAlignmentPath[0].size() && tw.forwardsAlignmentPath[0][index] < endingChromaXFrame) {
|
andrew@12
|
994 xcoord = min((int)(tw.firstEnergyVector.size())-1,tw.forwardsAlignmentPath[0][index]);
|
andrew@5
|
995 int ycoord = (int)tw.forwardsAlignmentPath[1][index];
|
andrew@5
|
996
|
andrew@5
|
997 if (tw.alignmentMeasureMatrix.size() > 0)
|
andrew@5
|
998 ycoord = min((int)tw.forwardsAlignmentPath[1][index], (int)(tw.alignmentMeasureMatrix[0].size())-1);
|
andrew@5
|
999
|
andrew@5
|
1000 // printxcoord = xcoord;
|
andrew@5
|
1001 int colour = 255;//tw.similarityMatrix[xcoord][ycoord]*255;
|
andrew@5
|
1002 //float value = tw.alignmentMeasureMatrix[xcoord][ycoord] ;
|
andrew@5
|
1003
|
andrew@5
|
1004 xcoord -= startingXFrame;
|
andrew@5
|
1005 ycoord -= startingYFrame;
|
andrew@5
|
1006 ofSetColor(0,colour,0);
|
andrew@5
|
1007 ofRect(xcoord*energyVectorWidth, ycoord*energyVectorHeight, energyVectorWidth, energyVectorHeight);
|
andrew@5
|
1008 index++;
|
andrew@5
|
1009 }//end while
|
andrew@5
|
1010
|
andrew@5
|
1011 }//end if forwards path exista
|
andrew@5
|
1012
|
andrew@5
|
1013 }
|
andrew@5
|
1014
|
andrew@5
|
1015
|
andrew@5
|
1016
|
andrew@10
|
1017 void testApp::drawAnchorPointsOnChromaSimilarity(const int& startingXFrame, const int& startingYFrame){
|
andrew@10
|
1018
|
andrew@10
|
1019 //using starting frame in energy vector
|
andrew@10
|
1020
|
andrew@10
|
1021 if (tw.anchorPoints.size() > 0){
|
andrew@10
|
1022 int endingChromaXFrame = startingXFrame + scrollWidth;
|
andrew@10
|
1023 int endingChromaYFrame = startingYFrame + scrollWidth;
|
andrew@10
|
1024
|
andrew@10
|
1025 float energyVectorWidth = screenWidth / scrollWidth;
|
andrew@10
|
1026 float energyVectorHeight = screenHeight / scrollWidth;
|
andrew@10
|
1027
|
andrew@10
|
1028 int index = 0;
|
andrew@10
|
1029
|
andrew@10
|
1030 while (index < tw.anchorPoints.size() && tw.anchorPoints[index][0] < startingXFrame){
|
andrew@10
|
1031 index ++;
|
andrew@10
|
1032 }
|
andrew@10
|
1033
|
andrew@10
|
1034 int xcoord;
|
andrew@10
|
1035
|
andrew@10
|
1036 while (index < tw.anchorPoints.size() && tw.anchorPoints[index][0] < endingChromaXFrame) {
|
andrew@12
|
1037 xcoord = min((int)(tw.firstEnergyVector.size())-1,tw.anchorPoints[index][0]);
|
andrew@10
|
1038 int ycoord = (int)tw.anchorPoints[index][1];
|
andrew@10
|
1039
|
andrew@10
|
1040 if (tw.alignmentMeasureMatrix.size() > 0)
|
andrew@10
|
1041 ycoord = min((int)tw.anchorPoints[index][1], (int)(tw.alignmentMeasureMatrix[0].size())-1);
|
andrew@10
|
1042
|
andrew@10
|
1043 int colour = 255;//tw.similarityMatrix[xcoord][ycoord]*255;
|
andrew@10
|
1044 //float value = tw.alignmentMeasureMatrix[xcoord][ycoord] ;
|
andrew@10
|
1045
|
andrew@10
|
1046 xcoord -= startingXFrame;
|
andrew@10
|
1047 ycoord -= startingYFrame;
|
andrew@10
|
1048 ofSetColor(colour,colour,colour);
|
andrew@10
|
1049 ofRect((xcoord-1)*energyVectorWidth, (ycoord-1)*energyVectorHeight, 3*energyVectorWidth, 3*energyVectorHeight);
|
andrew@10
|
1050 index++;
|
andrew@10
|
1051 }//end while
|
andrew@10
|
1052
|
andrew@10
|
1053 }//end if
|
andrew@10
|
1054
|
andrew@10
|
1055 }
|
andrew@10
|
1056
|
andrew@10
|
1057
|
andrew@10
|
1058
|
andrew@5
|
1059
|
andrew@5
|
1060
|
andrew@4
|
1061
|
andrew@0
|
1062 void testApp::loadSoundFiles(){
|
andrew@0
|
1063
|
andrew@0
|
1064 //assume libsndfile looks in the folder where the app is run
|
andrew@0
|
1065 //therefore ../../../ gets to the bin folder
|
andrew@0
|
1066 //we then need data/sounds/to get to the sound folder
|
andrew@0
|
1067 //this is different to the usual OF default folder
|
andrew@0
|
1068 //was const char
|
andrew@4
|
1069 const char *infilename = "../../../data/sound/Bach_short1.wav";
|
andrew@0
|
1070 loadLibSndFile(infilename);
|
andrew@0
|
1071
|
andrew@4
|
1072 string loadfilename = "sound/Bach_short1.wav";//PicturesMixer6.aif";
|
andrew@0
|
1073 loadedAudio.loadSound(loadfilename);
|
andrew@0
|
1074 playingAudio = &loadedAudio;
|
andrew@0
|
1075
|
andrew@0
|
1076 }
|
andrew@0
|
1077
|
andrew@0
|
1078 void testApp::loadLibSndFile(const char *infilename){
|
andrew@0
|
1079
|
andrew@0
|
1080 if (!sf_close(infile)){
|
andrew@0
|
1081 printf("closed sndfile okay \n");
|
andrew@0
|
1082 }
|
andrew@0
|
1083
|
andrew@0
|
1084 // Open Input File with lib snd file
|
andrew@0
|
1085 if (! (infile = sf_open (infilename, SFM_READ, &sfinfo)))
|
andrew@0
|
1086 { // Open failed
|
andrew@0
|
1087 printf ("SF OPEN routine Not able to open input file %s.\n", infilename) ;
|
andrew@0
|
1088 // Print the error message from libsndfile.
|
andrew@0
|
1089 puts (sf_strerror (NULL)) ;
|
andrew@0
|
1090
|
andrew@0
|
1091 } else{
|
andrew@0
|
1092 printf("SF OPEN opened file %s okay.\n", infilename);
|
andrew@0
|
1093 sndfileInfoString = "Opened okay ";
|
andrew@0
|
1094
|
andrew@0
|
1095 };
|
andrew@0
|
1096
|
andrew@0
|
1097 }
|
andrew@0
|
1098
|
andrew@1
|
1099 void testApp::processAudioToDoubleMatrix(DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector){
|
andrew@0
|
1100 //wendy
|
andrew@0
|
1101 myDoubleMatrix->clear();
|
andrew@0
|
1102 energyVector->clear();
|
andrew@1
|
1103
|
andrew@0
|
1104
|
andrew@1
|
1105
|
andrew@1
|
1106 chromaG.initialise(FRAMESIZE, CHROMAGRAM_FRAMESIZE);//framesize 512 and hopsize 2048 - already done
|
andrew@1
|
1107 chromaG.maximumChromaValue = 1;
|
andrew@2
|
1108 double maximumEnergyValue = 1;
|
andrew@0
|
1109
|
andrew@0
|
1110 int readcount = 1; // counts number of samples read from sound file
|
andrew@0
|
1111 printf("processing audio from doublematrix \n");
|
andrew@0
|
1112 printf("readcount %i", readcount);
|
andrew@14
|
1113 while(readcount != 0 && moveOn == true && energyVector->size() < FILE_LIMIT)
|
andrew@0
|
1114 {
|
andrew@0
|
1115
|
andrew@0
|
1116 // read FRAMESIZE samples from 'infile' and save in 'data'
|
andrew@0
|
1117 readcount = sf_read_float(infile, frame, FRAMESIZE);
|
andrew@0
|
1118
|
andrew@2
|
1119 double doubleFrame[FRAMESIZE];
|
andrew@2
|
1120 for (int k = 0;k< FRAMESIZE;k++){
|
andrew@2
|
1121 doubleFrame[k] = frame[k];
|
andrew@2
|
1122 }
|
andrew@2
|
1123
|
andrew@2
|
1124
|
andrew@2
|
1125
|
andrew@1
|
1126 //8192 samples per chroma frame //processing frame - downsampled to 11025Hz
|
andrew@1
|
1127 chromaG.processframe(frame);
|
andrew@0
|
1128
|
andrew@1
|
1129 if (chromaG.chromaready)
|
andrew@0
|
1130 {
|
andrew@0
|
1131 DoubleVector d;
|
andrew@0
|
1132
|
andrew@0
|
1133 for (int i = 0;i<12;i++){
|
andrew@1
|
1134 d.push_back(chromaG.rawChroma[i]);// / chromaG->maximumChromaValue);
|
andrew@0
|
1135
|
andrew@0
|
1136 }
|
andrew@0
|
1137 //this would do chord detection
|
andrew@0
|
1138
|
andrew@0
|
1139 myDoubleMatrix->push_back(d);
|
andrew@1
|
1140 //so now is storing at d[i][current_index]
|
andrew@0
|
1141
|
andrew@0
|
1142 }//end if chromagRamm ready
|
andrew@0
|
1143
|
andrew@0
|
1144
|
andrew@2
|
1145 // double energyValue = getEnergyOfFrame();
|
andrew@2
|
1146 double energyValue = onset->getDFsample(doubleFrame);
|
andrew@0
|
1147 energyVector->push_back(energyValue);
|
andrew@2
|
1148 if (energyValue > maximumEnergyValue)
|
andrew@2
|
1149 maximumEnergyValue = energyValue;
|
andrew@4
|
1150
|
andrew@0
|
1151
|
andrew@0
|
1152 }//end while readcount
|
andrew@0
|
1153
|
andrew@1
|
1154 printf("Max chroma value is %f \n", chromaG.maximumChromaValue);
|
andrew@2
|
1155 printf("length of chromagram is %d frames\n", (int)myDoubleMatrix->size());
|
andrew@4
|
1156 printf("height of dmatrix is %d\n", (int)(*myDoubleMatrix)[0].size());
|
andrew@4
|
1157 //normalise chroma matrix
|
andrew@0
|
1158 for (int i = 0; i < myDoubleMatrix->size();i++){
|
andrew@0
|
1159 for (int j = 0; j < ((*myDoubleMatrix)[0]).size();j++){
|
andrew@1
|
1160 //non-causal normalisation
|
andrew@1
|
1161 (*myDoubleMatrix)[i][j] /= chromaG.maximumChromaValue;
|
andrew@0
|
1162 }
|
andrew@0
|
1163 }
|
andrew@0
|
1164
|
andrew@4
|
1165
|
andrew@4
|
1166 printf("size of energy vector is %d \n", (int)energyVector->size());
|
andrew@4
|
1167 //non causal normalisation
|
andrew@2
|
1168 for (int i = 0; i < energyVector->size();i++){
|
andrew@2
|
1169 (*energyVector)[i] /= maximumEnergyValue;
|
andrew@2
|
1170 }
|
andrew@2
|
1171
|
andrew@4
|
1172 // totalNumberOfFrames = (int)energyVector->size();
|
andrew@4
|
1173 chromaConversionRatio = myDoubleMatrix->size() / (int)energyVector->size();
|
andrew@0
|
1174
|
andrew@0
|
1175 // int size = myDoubleMatrix->size() * CHROMA_CONVERSION_FACTOR;
|
andrew@0
|
1176
|
andrew@0
|
1177 }
|
andrew@0
|
1178
|
andrew@0
|
1179
|
andrew@0
|
1180 //--------------------------------------------------------------
|
andrew@0
|
1181 void testApp::keyPressed (int key){
|
andrew@0
|
1182 if (key == '-'){
|
andrew@0
|
1183 volume -= 0.05;
|
andrew@0
|
1184 volume = MAX(volume, 0);
|
andrew@0
|
1185 } else if (key == '+'){
|
andrew@0
|
1186 volume += 0.05;
|
andrew@0
|
1187 volume = MIN(volume, 1);
|
andrew@0
|
1188 }
|
andrew@0
|
1189
|
andrew@0
|
1190 if (key == OF_KEY_DOWN){
|
andrew@0
|
1191 if (scrollWidth > 600)
|
andrew@0
|
1192 scrollWidth += 400;
|
andrew@0
|
1193 else
|
andrew@0
|
1194 scrollWidth *= 2;
|
andrew@0
|
1195
|
andrew@4
|
1196 chromoLength = scrollWidth/conversionFactor;// CHROMA_CONVERSION_FACTOR;
|
andrew@0
|
1197 }
|
andrew@0
|
1198
|
andrew@0
|
1199 if (key == OF_KEY_UP){
|
andrew@0
|
1200 if (scrollWidth > 600)
|
andrew@0
|
1201 scrollWidth -= 400;
|
andrew@0
|
1202 else
|
andrew@0
|
1203 scrollWidth /= 2;
|
andrew@0
|
1204
|
andrew@4
|
1205 chromoLength = scrollWidth/conversionFactor;// CHROMA_CONVERSION_FACTOR;
|
andrew@0
|
1206 }
|
andrew@0
|
1207
|
andrew@0
|
1208 if (key == OF_KEY_LEFT){
|
andrew@0
|
1209
|
andrew@2
|
1210 (*playingAudio).setSpeed(-4);
|
andrew@0
|
1211 backwardsAlignmentIndex = tw.backwardsAlignmentPath[0].size()-1;
|
andrew@0
|
1212 }
|
andrew@0
|
1213
|
andrew@0
|
1214 if (key == OF_KEY_RIGHT){
|
andrew@0
|
1215
|
andrew@2
|
1216 (*playingAudio).setSpeed(4);
|
andrew@0
|
1217 }
|
andrew@0
|
1218
|
andrew@0
|
1219 if (key == OF_KEY_RETURN){
|
andrew@0
|
1220 loadedAudio.stop();
|
andrew@0
|
1221 audioPlaying = false;
|
andrew@0
|
1222 audioPaused = true;
|
andrew@0
|
1223 initialiseVariables();
|
andrew@0
|
1224 }
|
andrew@0
|
1225
|
andrew@0
|
1226 if (key == ' '){
|
andrew@0
|
1227 if (!audioPlaying) {
|
andrew@0
|
1228 (*playingAudio).play();
|
andrew@0
|
1229 (*playingAudio).setPaused(false);
|
andrew@0
|
1230 secondAudio.play();
|
andrew@0
|
1231 secondAudio.setPaused(true);
|
andrew@0
|
1232
|
andrew@0
|
1233 firstAudioFilePlaying = true;
|
andrew@0
|
1234
|
andrew@0
|
1235 audioPlaying = true;
|
andrew@0
|
1236 audioPaused = false;
|
andrew@0
|
1237 }
|
andrew@0
|
1238 else{
|
andrew@0
|
1239 audioPaused = !audioPaused;
|
andrew@0
|
1240 (*playingAudio).setPaused(audioPaused);
|
andrew@0
|
1241 }
|
andrew@0
|
1242
|
andrew@0
|
1243 }
|
andrew@0
|
1244
|
andrew@0
|
1245 if (key == 'p'){
|
andrew@0
|
1246 swapBetweenPlayingFilesUsingAlignmentMatch();
|
andrew@0
|
1247
|
andrew@0
|
1248 }
|
andrew@0
|
1249
|
andrew@0
|
1250 if (key == 'o'){
|
andrew@8
|
1251 tw.clearVectors();
|
andrew@8
|
1252
|
andrew@0
|
1253 openNewAudioFileWithdialogBox();
|
andrew@0
|
1254 }
|
andrew@0
|
1255
|
andrew@0
|
1256 if (key == 'l'){
|
andrew@0
|
1257 //open audio file
|
andrew@0
|
1258 string *filePtr, secondFileName;
|
andrew@0
|
1259 filePtr = &secondFileName;
|
andrew@0
|
1260 //so filePtr points to secondFileName
|
andrew@0
|
1261
|
andrew@0
|
1262 if (getFilenameFromDialogBox(filePtr)){
|
andrew@0
|
1263 printf("Loaded name okay :\n'%s' \n", secondFileName.c_str());
|
andrew@0
|
1264 }
|
andrew@0
|
1265
|
andrew@0
|
1266 loadSecondAudio(secondFileName);
|
andrew@0
|
1267
|
andrew@8
|
1268 initialiseVariables();
|
andrew@8
|
1269 backwardsAlignmentIndex = 0;
|
andrew@8
|
1270
|
andrew@4
|
1271 calculateSimilarityAndAlignment();
|
andrew@4
|
1272
|
andrew@8
|
1273
|
andrew@8
|
1274
|
andrew@0
|
1275 }
|
andrew@0
|
1276
|
andrew@14
|
1277 if (key == 'f'){
|
andrew@8
|
1278 tw.printBackwardsPath(0, (int) tw.forwardsAlignmentPath[0].size(), &tw.forwardsAlignmentPath);
|
andrew@8
|
1279 }
|
andrew@8
|
1280
|
andrew@14
|
1281 if (key == 'b'){
|
andrew@14
|
1282 tw.printBackwardsPath(0, (int) tw.backwardsAlignmentPath[0].size(), &tw.backwardsAlignmentPath);
|
andrew@14
|
1283 }
|
andrew@14
|
1284
|
andrew@8
|
1285
|
andrew@0
|
1286 if (key == 's'){
|
andrew@0
|
1287 drawSimilarity = !drawSimilarity;
|
andrew@0
|
1288 }
|
andrew@0
|
1289
|
andrew@0
|
1290
|
andrew@0
|
1291 if (key == 'm'){
|
andrew@0
|
1292 drawSecondMatrix = !drawSecondMatrix;
|
andrew@0
|
1293 }
|
andrew@0
|
1294
|
andrew@0
|
1295 if (key == 'd'){
|
andrew@0
|
1296 drawSpectralDifferenceFunction = !drawSpectralDifferenceFunction;
|
andrew@0
|
1297 }
|
andrew@0
|
1298
|
andrew@0
|
1299 }
|
andrew@0
|
1300
|
andrew@0
|
1301 //--------------------------------------------------------------
|
andrew@0
|
1302 void testApp::keyReleased (int key){
|
andrew@0
|
1303 if (key == OF_KEY_LEFT || OF_KEY_RIGHT){
|
andrew@0
|
1304 (*playingAudio).setSpeed(1);
|
andrew@5
|
1305 if (tw.backwardsAlignmentPath.size() > 0)
|
andrew@0
|
1306 backwardsAlignmentIndex = tw.backwardsAlignmentPath[0].size()-1;
|
andrew@0
|
1307 }
|
andrew@0
|
1308
|
andrew@0
|
1309 }
|
andrew@0
|
1310
|
andrew@0
|
1311 void testApp::openNewAudioFileWithdialogBox(){
|
andrew@0
|
1312
|
andrew@0
|
1313 //open audio file
|
andrew@0
|
1314 string *filePtr;
|
andrew@0
|
1315 filePtr = &soundFileName;
|
andrew@0
|
1316
|
andrew@0
|
1317 if (getFilenameFromDialogBox(filePtr)){
|
andrew@0
|
1318 printf("Mainfile: Loaded name okay :\n'%s' \n", soundFileName.c_str());
|
andrew@0
|
1319 }
|
andrew@0
|
1320
|
andrew@0
|
1321 //openFileDialogBox(); - replaced this lone by call to openFile Dialoguebox
|
andrew@0
|
1322 loadNewAudio(soundFileName);
|
andrew@0
|
1323
|
andrew@0
|
1324 }
|
andrew@0
|
1325
|
andrew@0
|
1326 //--------------------------------------------------------------
|
andrew@0
|
1327 void testApp::mouseMoved(int x, int y ){
|
andrew@0
|
1328 width = ofGetWidth();
|
andrew@0
|
1329 pan = (float)x / (float)width;
|
andrew@0
|
1330 float height = (float)ofGetHeight();
|
andrew@0
|
1331 float heightPct = ((height-y) / height);
|
andrew@0
|
1332 targetFrequency = 2000.0f * heightPct;
|
andrew@0
|
1333 phaseAdderTarget = (targetFrequency / (float) sampleRate) * TWO_PI;
|
andrew@0
|
1334 xIndex = (int)(pan*ENERGY_LENGTH);
|
andrew@0
|
1335 }
|
andrew@0
|
1336
|
andrew@0
|
1337 //--------------------------------------------------------------
|
andrew@0
|
1338 void testApp::mouseDragged(int x, int y, int button){
|
andrew@0
|
1339 width = ofGetWidth();
|
andrew@0
|
1340 pan = (float)x / (float)width;
|
andrew@0
|
1341 }
|
andrew@0
|
1342
|
andrew@0
|
1343 //--------------------------------------------------------------
|
andrew@0
|
1344 void testApp::mousePressed(int x, int y, int button){
|
andrew@0
|
1345 bNoise = true;
|
andrew@4
|
1346 //moveOn = true;
|
andrew@0
|
1347 }
|
andrew@0
|
1348
|
andrew@0
|
1349
|
andrew@0
|
1350 //--------------------------------------------------------------
|
andrew@0
|
1351 void testApp::mouseReleased(int x, int y, int button){
|
andrew@0
|
1352 bNoise = false;
|
andrew@0
|
1353 }
|
andrew@0
|
1354
|
andrew@0
|
1355 //--------------------------------------------------------------
|
andrew@0
|
1356 void testApp::windowResized(int w, int h){
|
andrew@0
|
1357 width = w;
|
andrew@0
|
1358 height = h;
|
andrew@0
|
1359 screenHeight = ofGetHeight() ;
|
andrew@0
|
1360 screenWidth = ofGetWidth();
|
andrew@0
|
1361
|
andrew@0
|
1362 }
|
andrew@0
|
1363 //--------------------------------------------------------------
|
andrew@0
|
1364 void testApp::audioRequested (float * output, int bufferSize, int nChannels){
|
andrew@0
|
1365 //pan = 0.5f;
|
andrew@0
|
1366 float leftScale = 1 - pan;
|
andrew@0
|
1367 float rightScale = pan;
|
andrew@0
|
1368
|
andrew@0
|
1369 // sin (n) seems to have trouble when n is very large, so we
|
andrew@0
|
1370 // keep phase in the range of 0-TWO_PI like this:
|
andrew@0
|
1371 while (phase > TWO_PI){
|
andrew@0
|
1372 phase -= TWO_PI;
|
andrew@0
|
1373 }
|
andrew@0
|
1374
|
andrew@0
|
1375
|
andrew@0
|
1376 }
|
andrew@0
|
1377
|
andrew@0
|
1378
|
andrew@0
|
1379 //--------------------------------------------------------------
|
andrew@0
|
1380
|
andrew@0
|
1381
|
andrew@0
|
1382 bool testApp::getFilenameFromDialogBox(string* fileNameToSave){
|
andrew@0
|
1383 //this uses a pointer structure within the loader and returns true if the dialogue box was used successfully
|
andrew@0
|
1384 // first, create a string that will hold the URL
|
andrew@0
|
1385 string URL;
|
andrew@0
|
1386
|
andrew@0
|
1387 // openFile(string& URL) returns 1 if a file was picked
|
andrew@0
|
1388 // returns 0 when something went wrong or the user pressed 'cancel'
|
andrew@0
|
1389 int response = ofxFileDialogOSX::openFile(URL);
|
andrew@0
|
1390 if(response){
|
andrew@0
|
1391 // now you can use the URL
|
andrew@0
|
1392 *fileNameToSave = URL;
|
andrew@0
|
1393 //printf("\n filename is %s \n", soundFileName.c_str());
|
andrew@0
|
1394 return true;
|
andrew@0
|
1395 }
|
andrew@0
|
1396 else {
|
andrew@0
|
1397 // soundFileName = "OPEN canceled. ";
|
andrew@0
|
1398 printf("\n open file cancelled \n");
|
andrew@0
|
1399 return false;
|
andrew@0
|
1400 }
|
andrew@0
|
1401
|
andrew@0
|
1402 }
|
andrew@0
|
1403
|
andrew@0
|
1404 void testApp::openFileDialogBox(){
|
andrew@0
|
1405
|
andrew@0
|
1406 // first, create a string that will hold the URL
|
andrew@0
|
1407 string URL;
|
andrew@0
|
1408
|
andrew@0
|
1409 // openFile(string& URL) returns 1 if a file was picked
|
andrew@0
|
1410 // returns 0 when something went wrong or the user pressed 'cancel'
|
andrew@0
|
1411 int response = ofxFileDialogOSX::openFile(URL);
|
andrew@0
|
1412 if(response){
|
andrew@0
|
1413 // now you can use the URL
|
andrew@0
|
1414 soundFileName = URL;//"URL to open: \n "+URL;
|
andrew@0
|
1415 }else {
|
andrew@0
|
1416 soundFileName = "OPEN cancelled. ";
|
andrew@0
|
1417 }
|
andrew@0
|
1418
|
andrew@0
|
1419
|
andrew@0
|
1420
|
andrew@0
|
1421 }
|
andrew@0
|
1422
|
andrew@0
|
1423
|
andrew@0
|
1424 void testApp::loadNewAudio(string soundFileName){
|
andrew@7
|
1425 //need to add in clear fns
|
andrew@7
|
1426 // tw.chromaMatrix.clear();
|
andrew@7
|
1427 // tw.firstEnergyVector.clear();
|
andrew@6
|
1428
|
andrew@0
|
1429 loadedAudio.loadSound(soundFileName);
|
andrew@6
|
1430 playingAudio = &loadedAudio;
|
andrew@0
|
1431 //snd file method
|
andrew@0
|
1432 const char *infilename = soundFileName.c_str() ;
|
andrew@0
|
1433 loadLibSndFile(infilename);
|
andrew@0
|
1434
|
andrew@7
|
1435 // loadFirstAudioFile();
|
andrew@7
|
1436 processAudioToDoubleMatrix(&tw.chromaMatrix, &tw.firstEnergyVector);
|
andrew@0
|
1437 audioPlaying = false;
|
andrew@0
|
1438 }
|
andrew@0
|
1439
|
andrew@0
|
1440
|
andrew@0
|
1441
|
andrew@0
|
1442 void testApp::loadFirstAudioFile(){
|
andrew@14
|
1443
|
andrew@1
|
1444 processAudioToDoubleMatrix(&tw.chromaMatrix, &tw.firstEnergyVector);
|
andrew@14
|
1445
|
andrew@0
|
1446
|
andrew@0
|
1447 }
|
andrew@0
|
1448
|
andrew@6
|
1449 void testApp::loadSecondAudio(string sndFileName){
|
andrew@0
|
1450
|
andrew@6
|
1451 secondAudio.loadSound(sndFileName);
|
andrew@0
|
1452
|
andrew@6
|
1453 const char *infilenme = sndFileName.c_str() ;
|
andrew@6
|
1454 loadLibSndFile(infilenme);
|
andrew@0
|
1455
|
andrew@14
|
1456
|
andrew@14
|
1457 processAudioToDoubleMatrix(&tw.secondMatrix, &tw.secondEnergyVector);
|
andrew@0
|
1458
|
andrew@0
|
1459 }
|
andrew@0
|
1460
|
andrew@0
|
1461
|
andrew@0
|
1462 void testApp::swapBetweenPlayingFilesUsingAlignmentMatch(){
|
andrew@8
|
1463 float tmpConvFac = conversionFactor;
|
andrew@8
|
1464 conversionFactor = 1.0;
|
andrew@0
|
1465 ofSoundUpdate();
|
andrew@0
|
1466 //swapping between files
|
andrew@8
|
1467 //printf("current playing (energy scale) frame was %i \n", currentPlayingFrame);
|
andrew@0
|
1468 float oldPosition = (*playingAudio).getPosition();
|
andrew@11
|
1469 printf("\n playing position is %f \n", oldPosition);//and conv factor %f \n", (*playingAudio).getPosition(), conversionFactor);
|
andrew@11
|
1470 float currentPlayingFileLength;
|
andrew@11
|
1471 float newFileLength;
|
andrew@0
|
1472 //(*playingAudio).stop();
|
andrew@0
|
1473 (*playingAudio).setPaused(true);
|
andrew@0
|
1474 int newIndicator;
|
andrew@0
|
1475 if (firstAudioFilePlaying){
|
andrew@0
|
1476 playingAudio = &secondAudio;
|
andrew@0
|
1477 newIndicator = 1;
|
andrew@11
|
1478 currentPlayingFileLength = tw.firstEnergyVector.size();
|
andrew@11
|
1479 newFileLength = tw.secondEnergyVector.size();
|
andrew@0
|
1480 }
|
andrew@0
|
1481 else{
|
andrew@0
|
1482 playingAudio = &loadedAudio;
|
andrew@0
|
1483 newIndicator = 0;
|
andrew@11
|
1484 currentPlayingFileLength = tw.secondEnergyVector.size();
|
andrew@11
|
1485 newFileLength = tw.firstEnergyVector.size();
|
andrew@0
|
1486 }
|
andrew@4
|
1487
|
andrew@8
|
1488 //printf("new indicator %i \n", newIndicator);
|
andrew@11
|
1489 printf("playing pos according to energy frames is %f; ",
|
andrew@8
|
1490 (currentPlayingFrame/((float)tw.backwardsAlignmentPath[1-newIndicator][0])) );//* conversionFactor)) );//CHROMA_CONVERSION_FACTOR
|
andrew@11
|
1491 printf("Current frame %f, predicts new frame to be roughly %f \n",
|
andrew@11
|
1492 (oldPosition*tw.backwardsAlignmentPath[newIndicator][0]), (oldPosition*tw.backwardsAlignmentPath[1-newIndicator][0]));
|
andrew@11
|
1493 printf("file lenbgths are now %i and other %i\n", tw.backwardsAlignmentPath[newIndicator][0], tw.backwardsAlignmentPath[1-newIndicator][0]);
|
andrew@11
|
1494 printf("compared to energy vec lengths %i and %i\n", tw.firstEnergyVector.size(), tw.secondEnergyVector.size());
|
andrew@0
|
1495
|
andrew@11
|
1496 currentChromaFrame = round(oldPosition * currentPlayingFileLength);
|
andrew@11
|
1497 // currentChromaFrame = currentPlayingFrame;// / conversionFactor;
|
andrew@9
|
1498 printf("current chroma frame %i \n", currentChromaFrame);//and using energy frames would have been %i \n", currentChromaFrame, currentPlayingFrame / conversionFactor);//CHROMA_CONVERSION_FACTOR);
|
andrew@4
|
1499
|
andrew@4
|
1500 int matchingFrame = findMatchFromAlignment(firstAudioFilePlaying);
|
andrew@11
|
1501 float relativePosition = matchingFrame / newFileLength;// tw.backwardsAlignmentPath[newIndicator][0];
|
andrew@0
|
1502 //i.e. the position as float [0,1] 0:beginning, 1 is end
|
andrew@0
|
1503
|
andrew@0
|
1504 (*playingAudio).setPaused(false);
|
andrew@0
|
1505 (*playingAudio).setPosition(relativePosition);
|
andrew@0
|
1506
|
andrew@11
|
1507 printf("matching frame is %i \n", matchingFrame, tw.backwardsAlignmentPath[newIndicator][0]);
|
andrew@9
|
1508 printf("new playing position is %f and back align index %i \n", (*playingAudio).getPosition(), backwardsAlignmentIndex);
|
andrew@0
|
1509
|
andrew@0
|
1510 firstAudioFilePlaying = !firstAudioFilePlaying;
|
andrew@0
|
1511
|
andrew@8
|
1512 conversionFactor = tmpConvFac;
|
andrew@0
|
1513 }
|
andrew@0
|
1514
|
andrew@0
|
1515 int testApp::findMatchFromAlignment(bool whichFileToTest){
|
andrew@0
|
1516 //could use technique from middle of file and go either way to reduce latency for long search?
|
andrew@0
|
1517 //- (not that this is a problem yet)
|
andrew@0
|
1518 int indicator;
|
andrew@0
|
1519 if (whichFileToTest)
|
andrew@0
|
1520 indicator = 0;
|
andrew@0
|
1521 else
|
andrew@0
|
1522 indicator = 1;
|
andrew@0
|
1523
|
andrew@0
|
1524 int oppositeIndicator = 1 - indicator;
|
andrew@0
|
1525
|
andrew@9
|
1526 int frame = backwardsAlignmentIndex;// tw.backwardsAlignmentPath[indicator].size()-1;
|
andrew@0
|
1527
|
andrew@9
|
1528 while (tw.backwardsAlignmentPath[indicator][frame] > currentChromaFrame && backwardsAlignmentIndex < tw.backwardsAlignmentPath[indicator].size()-1){
|
andrew@9
|
1529 frame++;
|
andrew@9
|
1530 }
|
andrew@0
|
1531
|
andrew@9
|
1532 while (tw.backwardsAlignmentPath[indicator][frame] < currentChromaFrame && frame > 0){
|
andrew@0
|
1533 frame--;
|
andrew@0
|
1534 }
|
andrew@0
|
1535 //printf("frame found is %i \n", frame);
|
andrew@0
|
1536 int frameToSwitchTo = tw.backwardsAlignmentPath[oppositeIndicator][frame];
|
andrew@0
|
1537
|
andrew@0
|
1538 float calculatedPosition = (currentChromaFrame / (float) tw.backwardsAlignmentPath[indicator][0]);
|
andrew@0
|
1539
|
andrew@0
|
1540 printf("(length was %i)\n", tw.backwardsAlignmentPath[indicator][0]);
|
andrew@0
|
1541
|
andrew@0
|
1542 printf("compares to position calculated from chroma length %f \n", calculatedPosition);
|
andrew@0
|
1543 printf("current frame %i maps to new frame %i \n", currentChromaFrame, frameToSwitchTo);
|
andrew@0
|
1544 printf("relative position of new frame is %f \n", (frameToSwitchTo / (float) tw.backwardsAlignmentPath[oppositeIndicator][0]) );
|
andrew@0
|
1545 return frameToSwitchTo;
|
andrew@0
|
1546
|
andrew@0
|
1547 }
|
andrew@0
|
1548
|
andrew@0
|
1549 void testApp::printSimilarityMatrix(int sizeToPrint){
|
andrew@0
|
1550
|
andrew@0
|
1551 printf("\n _ _ _ _\n");
|
andrew@0
|
1552 printf("Similarity Matrix \n");
|
andrew@0
|
1553 int i,j;
|
andrew@0
|
1554 DoubleVector d;
|
andrew@0
|
1555 int rowSize = sizeToPrint;
|
andrew@0
|
1556
|
andrew@0
|
1557 for (int j = 0;j < rowSize;j++){
|
andrew@0
|
1558 printf("row %i : ", j);
|
andrew@0
|
1559
|
andrew@0
|
1560 for (i = 0;i < rowSize;i++){
|
andrew@0
|
1561 printf("%f , ", tw.similarityMatrix[i][j] );
|
andrew@0
|
1562 }
|
andrew@0
|
1563 printf("\n");
|
andrew@0
|
1564 }
|
andrew@0
|
1565 printf("...............\n");
|
andrew@0
|
1566
|
andrew@0
|
1567 }
|
andrew@0
|
1568
|
andrew@0
|
1569
|
andrew@8
|
1570
|
andrew@8
|
1571 void testApp::printAlignmentMatrix(const DoubleMatrix& alignmentMatrix){
|
andrew@0
|
1572
|
andrew@8
|
1573 int size = alignmentMatrix.size();
|
andrew@0
|
1574 printf("\n _ _ _ _\n");
|
andrew@0
|
1575 printf("align size is %i \n", size);
|
andrew@0
|
1576
|
andrew@0
|
1577 int i,j;
|
andrew@0
|
1578 DoubleVector d;
|
andrew@8
|
1579 int rowSize = alignmentMatrix.size();
|
andrew@8
|
1580 d = alignmentMatrix[0];//choose initial size
|
andrew@0
|
1581
|
andrew@0
|
1582 for (int j = 0;j < d.size();j++){
|
andrew@0
|
1583 printf("row %i : ", j);
|
andrew@0
|
1584
|
andrew@0
|
1585 for (i = 0;i < rowSize;i++){
|
andrew@8
|
1586 d = alignmentMatrix[i];
|
andrew@0
|
1587
|
andrew@0
|
1588 // printf("row %i , col %i, val : %f \n", i, j, alignmentMeasureMatrix[i][j] );
|
andrew@8
|
1589 printf("%f , ", alignmentMatrix[i][j] );
|
andrew@0
|
1590 }
|
andrew@0
|
1591 printf("\n");
|
andrew@0
|
1592 }
|
andrew@0
|
1593 printf("...............\n");
|
andrew@0
|
1594
|
andrew@0
|
1595 }
|
andrew@0
|
1596
|
andrew@0
|
1597
|
andrew@0
|
1598 void testApp::printScoreForRow(int row, int max){
|
andrew@0
|
1599 printf("alignment scores row %i \n", row);
|
andrew@0
|
1600 float minimum = tw.alignmentMeasureMatrix[row][0];
|
andrew@0
|
1601 int minimumIndex = 0;
|
andrew@0
|
1602 for (int i =0;i < max;i++){
|
andrew@0
|
1603 printf("[%i] %f ", i, tw.alignmentMeasureMatrix[row][i]);
|
andrew@0
|
1604 if (tw.alignmentMeasureMatrix[row][i] < minimum)
|
andrew@0
|
1605 {
|
andrew@0
|
1606 minimum = tw.alignmentMeasureMatrix[row][i] ;
|
andrew@0
|
1607 minimumIndex = i;
|
andrew@0
|
1608 }
|
andrew@0
|
1609 printf(" \n");
|
andrew@0
|
1610 }
|
andrew@0
|
1611 printf("Minimum [%i] : %f \n", minimumIndex, minimum);
|
andrew@0
|
1612 printf("ALIGN score :[%i] : %f \n", tw.backwardsAlignmentPath[1][backwardsAlignmentIndex], tw.alignmentMeasureMatrix[tw.backwardsAlignmentPath[0][backwardsAlignmentIndex] ][ (int) tw.backwardsAlignmentPath[1][backwardsAlignmentIndex] ]);
|
andrew@0
|
1613
|
andrew@0
|
1614 }
|
andrew@0
|
1615
|
andrew@0
|
1616
|
andrew@0
|
1617
|
andrew@0
|
1618
|
andrew@0
|
1619
|
andrew@0
|
1620
|
andrew@12
|
1621 void testApp::dontDoJunkAlignment(){
|
andrew@12
|
1622
|
andrew@12
|
1623 if (1 == 2){
|
andrew@12
|
1624 //dont do joint as matrix is too large - energyvec x energyvec
|
andrew@12
|
1625 //needs doing in parts
|
andrew@12
|
1626 double timeBefore = ofGetElapsedTimef();
|
andrew@12
|
1627 tw.calculateJointSimilarityMatrix(&tw.firstEnergyVector, &tw.secondEnergyVector, &tw.chromaSimilarityMatrix, &tw.similarityMatrix);
|
andrew@12
|
1628 double elapsedTime = ofGetElapsedTimef() - timeBefore;
|
andrew@12
|
1629 printf("JOINT SIMILARITY TAKES %6.2f seconds\n", elapsedTime);
|
andrew@12
|
1630 //this has been replaced by the joint function
|
andrew@12
|
1631 }
|
andrew@12
|
1632
|
andrew@12
|
1633
|
andrew@12
|
1634
|
andrew@12
|
1635 // the big similarity measure
|
andrew@12
|
1636 //timeBefore = ofGetElapsedTimef();
|
andrew@12
|
1637 //tw.calculateSimilarityMatrixWithPointers(&tw.firstChromaEnergyMatrix, &tw.secondChromaEnergyMatrix, &tw.similarityMatrix);
|
andrew@12
|
1638 //elapsedTime = ofGetElapsedTimef() - timeBefore;
|
andrew@12
|
1639 //printf("CREATING BIG SIMILARITY MATRIX TAKES %f\n", elapsedTime);
|
andrew@12
|
1640 //bug is here above - needed to make sim matrix visible
|
andrew@12
|
1641
|
andrew@12
|
1642 //new fn
|
andrew@12
|
1643 // tw.calculateSimilarityMatrixFromChromagramAndEnergy(&tw.firstEnergyVector, &tw.chromaMatrix, &tw.secondEnergyVector, tw.secondMatrix, &tw.similarityMatrix);
|
andrew@12
|
1644 // tw.calculateAlignmentMatrix(tw.firstChromaEnergyMatrix, tw.secondChromaEnergyMatrix, &tw.alignmentMeasureMatrix);
|
andrew@12
|
1645 // tw.calculateMinimumAlignmentPath(&tw.alignmentMeasureMatrix, &tw.backwardsAlignmentPath, false);
|
andrew@12
|
1646
|
andrew@12
|
1647 }
|
andrew@0
|
1648
|
andrew@0
|
1649
|
andrew@0
|
1650
|
andrew@0
|
1651
|
andrew@0
|
1652
|
andrew@0
|
1653
|
andrew@0
|
1654 /*
|
andrew@5
|
1655 void testApp::pushSimCoxde(){
|
andrew@5
|
1656 /* for (int i = 0;i < tw.tmpSimilarityMatrix.size();i++){
|
andrew@5
|
1657 DoubleVector v;
|
andrew@5
|
1658 v = tw.tmpSimilarityMatrix[i];
|
andrew@5
|
1659 tw.similarityMatrix.push_back(v);
|
andrew@5
|
1660 }
|
andrew@5
|
1661 */
|
andrew@5
|
1662
|
andrew@5
|
1663 /*
|
andrew@0
|
1664 void testApp::calculateSimilarityMatrix(){
|
andrew@0
|
1665 similarityMatrix.clear();
|
andrew@0
|
1666 printf("calculating similarity matrix...");
|
andrew@0
|
1667 userInfoString = "calculating similarity matrix...";
|
andrew@0
|
1668
|
andrew@0
|
1669 double distance, firstSum, secondSum;
|
andrew@0
|
1670
|
andrew@0
|
1671 for (int x = 0;x < tw.chromaMatrix.size();x++){
|
andrew@0
|
1672 DoubleVector d;
|
andrew@0
|
1673 for (int y = 0;y < tw.secondMatrix.size();y++){
|
andrew@0
|
1674
|
andrew@0
|
1675 //d.push_back( drand48() );
|
andrew@0
|
1676
|
andrew@0
|
1677 distance = 0;
|
andrew@0
|
1678 firstSum = 0;
|
andrew@0
|
1679 secondSum = 0;
|
andrew@0
|
1680 for (int z = 0;z < chromaMatrix[x].size();z++){//z is the twelve chromagram values
|
andrew@0
|
1681
|
andrew@0
|
1682 distance += chromaMatrix[x][z] * secondMatrix[y][z];
|
andrew@0
|
1683
|
andrew@0
|
1684 firstSum += chromaMatrix[x][z] * chromaMatrix[x][z];
|
andrew@0
|
1685 secondSum += secondMatrix[y][z] * secondMatrix[y][z];
|
andrew@0
|
1686 }
|
andrew@0
|
1687
|
andrew@0
|
1688 if (firstSum > 0 && secondSum > 0)
|
andrew@0
|
1689 distance /= sqrt(firstSum * secondSum);
|
andrew@0
|
1690
|
andrew@0
|
1691
|
andrew@0
|
1692 d.push_back( distance);
|
andrew@0
|
1693
|
andrew@0
|
1694 } //end for y
|
andrew@0
|
1695
|
andrew@0
|
1696 similarityMatrix.push_back(d);
|
andrew@0
|
1697
|
andrew@0
|
1698 }//end for x
|
andrew@0
|
1699 userInfoString += "; size =";
|
andrew@0
|
1700 userInfoString += ofToString(similarityMatrix.size() , 0);
|
andrew@0
|
1701 printf("..sim size: %i, height: %i \n", similarityMatrix.size(), (chromaMatrix[0]).size());
|
andrew@0
|
1702
|
andrew@0
|
1703 }//end self sim
|
andrew@0
|
1704
|
andrew@0
|
1705 */
|
andrew@0
|
1706 /*
|
andrew@0
|
1707 void testApp::calculateAlignmentMatrix(){
|
andrew@0
|
1708
|
andrew@0
|
1709 //initialise alignment
|
andrew@0
|
1710 alignmentMeasureMatrix.clear();
|
andrew@0
|
1711 DoubleVector d;
|
andrew@0
|
1712 d.push_back(getDistance(0,0));
|
andrew@0
|
1713 alignmentMeasureMatrix.push_back(d);
|
andrew@0
|
1714
|
andrew@0
|
1715 bool chromaCalculated = false;
|
andrew@0
|
1716 bool secondCalculated = false;
|
andrew@0
|
1717
|
andrew@0
|
1718 while (!chromaCalculated || !secondCalculated) {
|
andrew@0
|
1719
|
andrew@0
|
1720 if (!chromaCalculated)
|
andrew@0
|
1721 chromaCalculated = extendAlignmentAlong();
|
andrew@0
|
1722
|
andrew@0
|
1723 if (!secondCalculated)
|
andrew@0
|
1724 secondCalculated = extendAlignmentUp();
|
andrew@0
|
1725
|
andrew@0
|
1726 }
|
andrew@0
|
1727
|
andrew@0
|
1728 }
|
andrew@0
|
1729
|
andrew@0
|
1730 bool testApp::extendAlignmentUp(){
|
andrew@0
|
1731 DoubleVector d;
|
andrew@0
|
1732 d = alignmentMeasureMatrix[0];
|
andrew@0
|
1733 int heightSize = d.size();
|
andrew@0
|
1734 if (heightSize < secondMatrix.size()){
|
andrew@0
|
1735 //then we haven't finished yet
|
andrew@0
|
1736 for (int i = 0;i < alignmentMeasureMatrix.size();i++){
|
andrew@0
|
1737 double value = getDistance(i, heightSize);
|
andrew@0
|
1738 value += getMinimum(i, heightSize, value);
|
andrew@0
|
1739 alignmentMeasureMatrix[i].push_back(value);
|
andrew@0
|
1740 }
|
andrew@0
|
1741 }
|
andrew@0
|
1742 if (alignmentMeasureMatrix[0].size() == secondMatrix.size())
|
andrew@0
|
1743 return true;
|
andrew@0
|
1744 else
|
andrew@0
|
1745 return false;
|
andrew@0
|
1746
|
andrew@0
|
1747 }
|
andrew@0
|
1748
|
andrew@0
|
1749
|
andrew@0
|
1750 bool testApp::extendAlignmentAlong(){
|
andrew@0
|
1751 DoubleVector d;
|
andrew@0
|
1752 int widthSize = alignmentMeasureMatrix.size();
|
andrew@0
|
1753 if (widthSize < chromaMatrix.size()){
|
andrew@0
|
1754 //then we can extend along
|
andrew@0
|
1755 double value = getDistance(widthSize, 0);
|
andrew@0
|
1756 value += getMinimum(widthSize, 0, value);
|
andrew@0
|
1757
|
andrew@0
|
1758 d.push_back(value);
|
andrew@0
|
1759 alignmentMeasureMatrix.push_back(d);
|
andrew@0
|
1760
|
andrew@0
|
1761 for (int j = 1;j < alignmentMeasureMatrix[widthSize - 1].size();j++){
|
andrew@0
|
1762 value = getDistance(widthSize, j);
|
andrew@0
|
1763 value += getMinimum(widthSize, j, value);
|
andrew@0
|
1764 alignmentMeasureMatrix[widthSize].push_back(value);
|
andrew@0
|
1765 }
|
andrew@0
|
1766
|
andrew@0
|
1767 //alignmentMeasureMatrix.push_back(d);
|
andrew@0
|
1768 }
|
andrew@0
|
1769
|
andrew@0
|
1770 if (alignmentMeasureMatrix.size() == chromaMatrix.size())
|
andrew@0
|
1771 return true;
|
andrew@0
|
1772 else
|
andrew@0
|
1773 return false;
|
andrew@0
|
1774
|
andrew@0
|
1775 }
|
andrew@0
|
1776
|
andrew@0
|
1777
|
andrew@0
|
1778 void testApp::calculateMinimumAlignmentPath(){
|
andrew@0
|
1779 //this requires one pass of the DTW algorithm and then works backwards from (N,M)
|
andrew@0
|
1780 //to find the optimal path to (0,0), where N and M are the lengths of the two chromoVectors respectively
|
andrew@0
|
1781 //minimumAlignmentPath.clear();
|
andrew@0
|
1782 backwardsAlignmentPath.clear();
|
andrew@0
|
1783
|
andrew@0
|
1784 printf("Finding minimum Path \n");
|
andrew@0
|
1785 IntVector v;
|
andrew@0
|
1786 v.push_back(chromaMatrix.size()-1);
|
andrew@0
|
1787 backwardsAlignmentPath.push_back(v);
|
andrew@0
|
1788 v.clear();
|
andrew@0
|
1789 v.push_back(secondMatrix.size()-1);
|
andrew@0
|
1790 backwardsAlignmentPath.push_back(v);
|
andrew@0
|
1791 //so now backwards path[0][0] = size(chroma) and path[1][0] = size(secondMatrix)
|
andrew@0
|
1792 printf("backwards path %i : %i \n", backwardsAlignmentPath[0][0], backwardsAlignmentPath[1][0]);
|
andrew@0
|
1793
|
andrew@0
|
1794
|
andrew@0
|
1795 int indexOfBackwardsPath = 0;
|
andrew@0
|
1796 while (!findPreviousMinimumInBackwardsPath()) {
|
andrew@0
|
1797 indexOfBackwardsPath++;
|
andrew@0
|
1798 printf("backwards path %i : %i \n", backwardsAlignmentPath[0][indexOfBackwardsPath], backwardsAlignmentPath[1][indexOfBackwardsPath]);
|
andrew@0
|
1799
|
andrew@0
|
1800 }
|
andrew@0
|
1801 //printf("final index of backwards path is %i and i is %i \n", backwardsAlignmentPath[0].size()-1, indexOfBackwardsPath);
|
andrew@0
|
1802
|
andrew@0
|
1803 backwardsAlignmentIndex = backwardsAlignmentPath[0].size()-1;//remember that this goes backwards!
|
andrew@0
|
1804
|
andrew@0
|
1805 }
|
andrew@0
|
1806
|
andrew@0
|
1807
|
andrew@0
|
1808 bool testApp::findPreviousMinimumInBackwardsPath(){
|
andrew@0
|
1809 int chromaPosition, secondPosition;
|
andrew@0
|
1810 int i,j;
|
andrew@0
|
1811 i = backwardsAlignmentPath[0][backwardsAlignmentPath[0].size()-1];
|
andrew@0
|
1812 j = backwardsAlignmentPath[1][backwardsAlignmentPath[1].size()-1];
|
andrew@0
|
1813
|
andrew@0
|
1814 double newMinimum;
|
andrew@0
|
1815 double *ptr;
|
andrew@0
|
1816 ptr = &newMinimum;
|
andrew@0
|
1817 newMinimum = alignmentMeasureMatrix[i][j];
|
andrew@0
|
1818 DoubleVector d;
|
andrew@0
|
1819
|
andrew@0
|
1820
|
andrew@0
|
1821 bool finishedAligning = true;
|
andrew@0
|
1822
|
andrew@0
|
1823 if (i > 0){
|
andrew@0
|
1824 if (testForNewAlignmentMinimum(ptr, i-1, j)){
|
andrew@0
|
1825 chromaPosition = i-1;
|
andrew@0
|
1826 secondPosition = j;
|
andrew@0
|
1827 finishedAligning = false;
|
andrew@0
|
1828 }
|
andrew@0
|
1829
|
andrew@0
|
1830 if (j>0 && testForNewAlignmentMinimum(ptr, i-1, j-1)){
|
andrew@0
|
1831 chromaPosition = i-1;
|
andrew@0
|
1832 secondPosition = j-1;
|
andrew@0
|
1833 finishedAligning = false;
|
andrew@0
|
1834 }
|
andrew@0
|
1835 }
|
andrew@0
|
1836
|
andrew@0
|
1837 if (j > 0 && testForNewAlignmentMinimum(ptr, i, j-1)){
|
andrew@0
|
1838 chromaPosition = i;
|
andrew@0
|
1839 secondPosition = j-1;
|
andrew@0
|
1840 //newMinimum = alignmentMeasureMatrix[chromaPosition][secondPosition];
|
andrew@0
|
1841 finishedAligning = false;
|
andrew@0
|
1842 }
|
andrew@0
|
1843
|
andrew@0
|
1844 if (!finishedAligning){
|
andrew@0
|
1845 backwardsAlignmentPath[0].push_back(chromaPosition);
|
andrew@0
|
1846 backwardsAlignmentPath[1].push_back(secondPosition);
|
andrew@0
|
1847 }
|
andrew@0
|
1848
|
andrew@0
|
1849 return finishedAligning;
|
andrew@0
|
1850
|
andrew@0
|
1851 }
|
andrew@0
|
1852
|
andrew@0
|
1853
|
andrew@0
|
1854
|
andrew@0
|
1855 bool testApp::testForNewAlignmentMinimum(double *previousMinimum, int i, int j){
|
andrew@0
|
1856 bool newMinimumFound = false;
|
andrew@0
|
1857 if (alignmentMeasureMatrix[i][j] < *previousMinimum){
|
andrew@0
|
1858 *previousMinimum = alignmentMeasureMatrix[i][j];
|
andrew@0
|
1859 newMinimumFound = true;
|
andrew@0
|
1860 }
|
andrew@0
|
1861
|
andrew@0
|
1862 return newMinimumFound;
|
andrew@0
|
1863 }
|
andrew@0
|
1864 */
|
andrew@4
|
1865
|
andrew@4
|
1866
|
andrew@4
|
1867 /*
|
andrew@4
|
1868 int testApp::findMinimumOfVector(DoubleVector *d){
|
andrew@4
|
1869 int minimumIndex = 0;
|
andrew@4
|
1870 double minimumValue = (*d)[0];
|
andrew@4
|
1871 for (int i = 0;i < d->size();i++){
|
andrew@4
|
1872 if ((*d)[i] < minimumValue){
|
andrew@4
|
1873 minimumIndex = i;
|
andrew@4
|
1874 minimumValue = (*d)[i];
|
andrew@4
|
1875 }
|
andrew@4
|
1876 }
|
andrew@4
|
1877
|
andrew@4
|
1878 return minimumIndex;
|
andrew@4
|
1879 }
|
andrew@4
|
1880 */
|
andrew@4
|
1881 /*
|
andrew@4
|
1882 double testApp::getDistance(int i, int j){
|
andrew@4
|
1883 return (1 - similarityMatrix[i][j]);
|
andrew@4
|
1884 }
|
andrew@4
|
1885
|
andrew@4
|
1886 double testApp::getMinimum(int i, int j, float newValue){
|
andrew@4
|
1887 double minimumValue = 0;
|
andrew@4
|
1888
|
andrew@4
|
1889 if (i > 0){
|
andrew@4
|
1890 minimumValue = tw.alignmentMeasureMatrix[i-1][j];
|
andrew@4
|
1891 if (j > 0){
|
andrew@4
|
1892 minimumValue = min(minimumValue, alignmentMeasureMatrix[i-1][j-1] + newValue ) ;//penalises diagonal by 2
|
andrew@4
|
1893 minimumValue = min(minimumValue, alignmentMeasureMatrix[i][j-1]);
|
andrew@4
|
1894 }
|
andrew@4
|
1895 }
|
andrew@4
|
1896 else{//i.e. i == 0
|
andrew@4
|
1897 if (j > 0)
|
andrew@4
|
1898 minimumValue = tw.alignmentMeasureMatrix[i][j-1];
|
andrew@4
|
1899 }
|
andrew@4
|
1900
|
andrew@4
|
1901 return minimumValue;
|
andrew@4
|
1902 }
|
andrew@4
|
1903
|
andrew@4
|
1904 */
|
andrew@4
|
1905
|