andrew@0
|
1 #ifndef _TEST_APP
|
andrew@0
|
2 #define _TEST_APP
|
andrew@0
|
3
|
andrew@0
|
4
|
andrew@0
|
5 #include "ofMain.h"
|
andrew@0
|
6 #include "chromaGram.h"
|
andrew@0
|
7 #include "ChordDetect.h"
|
andrew@0
|
8 #include "sndfile.h"
|
andrew@0
|
9 #include "ofxFileDialogOSX.h"
|
andrew@0
|
10 #include "timeWarp.h"
|
andrew@0
|
11
|
andrew@0
|
12 //#include <vector>
|
andrew@0
|
13 //#include <cstdlib>
|
andrew@0
|
14
|
andrew@0
|
15
|
andrew@0
|
16 #define FRAMESIZE 512
|
andrew@0
|
17 #define ENERGY_LENGTH 80000
|
andrew@0
|
18 #define CHROMA_LENGTH 12000
|
andrew@0
|
19 #define CHROMA_CONVERSION_FACTOR 16 //16 times as many frames in energy as in chroma
|
andrew@0
|
20 //length in terms of frames (at 512 samples per frame - there are 90 per second) => 900: 10 seconds
|
andrew@0
|
21
|
andrew@0
|
22 class testApp : public ofBaseApp{
|
andrew@0
|
23
|
andrew@0
|
24 public:
|
andrew@0
|
25
|
andrew@0
|
26
|
andrew@0
|
27 void setup();
|
andrew@0
|
28 void update();
|
andrew@0
|
29 void draw();
|
andrew@0
|
30
|
andrew@0
|
31 void keyPressed (int key);
|
andrew@0
|
32 void keyReleased(int key);
|
andrew@0
|
33 void mouseMoved(int x, int y );
|
andrew@0
|
34 void mouseDragged(int x, int y, int button);
|
andrew@0
|
35 void mousePressed(int x, int y, int button);
|
andrew@0
|
36 void mouseReleased(int x, int y, int button);
|
andrew@0
|
37 void windowResized(int w, int h);
|
andrew@0
|
38
|
andrew@0
|
39 void audioRequested (float * input, int bufferSize, int nChannels);
|
andrew@0
|
40 void loadSndfile();
|
andrew@0
|
41 double getEnergyOfFrame();
|
andrew@0
|
42
|
andrew@0
|
43
|
andrew@0
|
44 void drawChromoGram();
|
andrew@0
|
45
|
andrew@0
|
46 void loadFirstAudioFile();
|
andrew@0
|
47 void initialiseVariables();
|
andrew@0
|
48
|
andrew@0
|
49
|
andrew@0
|
50 typedef std::vector<double> DoubleVector;
|
andrew@0
|
51 typedef std::vector<DoubleVector> DoubleMatrix;
|
andrew@0
|
52
|
andrew@0
|
53 // DoubleMatrix chromaMatrix;
|
andrew@0
|
54 // DoubleMatrix secondMatrix;
|
andrew@0
|
55 DoubleMatrix* matrixPtr;
|
andrew@0
|
56
|
andrew@0
|
57 void drawDoubleMatrix(DoubleMatrix* dMatrix);//DoubleMatrix* dMatrix); WOULD BE NICE TO USE POINTER BUT NOT WORKING YET
|
andrew@0
|
58 void drawSpectralDifference(DoubleMatrix* dMatrix);
|
andrew@0
|
59
|
andrew@0
|
60 // DoubleVector firstEnergyVector;
|
andrew@0
|
61 // DoubleVector secondEnergyVector;
|
andrew@0
|
62
|
andrew@0
|
63
|
andrew@0
|
64 // DoubleMatrix similarityMatrix;
|
andrew@0
|
65 void calculateSimilarityMatrix();
|
andrew@0
|
66
|
andrew@0
|
67 bool drawSimilarity;
|
andrew@0
|
68 void drawSimilarityMatrix();
|
andrew@0
|
69 void printSimilarityMatrix(int sizeToPrint);
|
andrew@0
|
70
|
andrew@0
|
71 // DoubleMatrix alignmentMeasureMatrix;
|
andrew@0
|
72
|
andrew@0
|
73 // DoubleVector minimumAlignmentPath;
|
andrew@0
|
74
|
andrew@0
|
75 void drawAlignmentPath(int startingChromaXFrame, int startingChromaYFrame);
|
andrew@0
|
76 int findStartWidthFrame();
|
andrew@0
|
77
|
andrew@0
|
78 void printScoreForRow(int row, int max);
|
andrew@0
|
79
|
andrew@0
|
80 int numberOfScrollWidthsForFirstFile;
|
andrew@0
|
81 int numberOfScrollWidthsForSecondFile;
|
andrew@0
|
82
|
andrew@0
|
83 void checkIfAudioPositionExceedsWidthForFirstFile();
|
andrew@0
|
84
|
andrew@0
|
85 typedef std::vector<int> IntVector;
|
andrew@0
|
86 typedef std::vector<IntVector> IntMatrix;
|
andrew@0
|
87
|
andrew@0
|
88 // IntMatrix backwardsAlignmentPath;
|
andrew@0
|
89 int backwardsAlignmentIndex;//used for drawing the path
|
andrew@0
|
90
|
andrew@0
|
91 void updateAlignmentPathIndex(int idenifier);
|
andrew@0
|
92
|
andrew@0
|
93 // bool checkWhetherOnAlignmentPath(int xcoord, int ycoord, int *indexOfAlignmentPathTested);
|
andrew@0
|
94
|
andrew@0
|
95 bool findPreviousMinimumInBackwardsPath();
|
andrew@0
|
96 bool testForNewAlignmentMinimum(double *previousMinimum, int i, int j);
|
andrew@0
|
97
|
andrew@0
|
98 void calculateAlignmentMatrix();
|
andrew@0
|
99 // void performNextAlignment();
|
andrew@0
|
100 double getDistance(int i, int j);
|
andrew@0
|
101 void printAlignmentMatrix();
|
andrew@0
|
102 double getMinimum(int i, int j, float newValue);
|
andrew@0
|
103 bool extendAlignmentUp();
|
andrew@0
|
104 bool extendAlignmentAlong();
|
andrew@0
|
105 void calculateMinimumAlignmentPath();
|
andrew@0
|
106 int findMinimumOfVector(DoubleVector *d);
|
andrew@0
|
107 void swapBetweenPlayingFilesUsingAlignmentMatch();
|
andrew@0
|
108 int findMatchFromAlignment(bool whichFileToTest);
|
andrew@0
|
109
|
andrew@0
|
110 void drawEnergyVectorFromPointer(DoubleVector* energyVec);
|
andrew@0
|
111
|
andrew@0
|
112 void processAudioToDoubleMatrix(Chromagram* chromaG, DoubleMatrix* myDoubleMatrix, DoubleVector* energyVector);
|
andrew@0
|
113
|
andrew@0
|
114 void loadNewAudio(string soundFileName);
|
andrew@0
|
115 void loadSecondAudio(string soundFileName);
|
andrew@0
|
116
|
andrew@0
|
117 void loadSoundFiles();
|
andrew@0
|
118 void openFileDialogBox();
|
andrew@0
|
119 void loadLibSndFile(const char * filename);
|
andrew@0
|
120 bool getFilenameFromDialogBox(string* fileNameToSave);
|
andrew@0
|
121 void openNewAudioFileWithdialogBox();
|
andrew@0
|
122
|
andrew@0
|
123 //int* firstAudioLength, secondAudioLength;
|
andrew@0
|
124
|
andrew@0
|
125 string soundFileName, secondFileName;
|
andrew@0
|
126
|
andrew@0
|
127 float screenHeight, screenWidth;
|
andrew@0
|
128
|
andrew@0
|
129 float pan;
|
andrew@0
|
130 int sampleRate;
|
andrew@0
|
131 bool bNoise;
|
andrew@0
|
132 float volume;
|
andrew@0
|
133
|
andrew@0
|
134 float * lAudio;
|
andrew@0
|
135 float * rAudio;
|
andrew@0
|
136
|
andrew@0
|
137 bool moveOn;
|
andrew@0
|
138 bool drawSpectralDifferenceFunction;
|
andrew@0
|
139 float frame[FRAMESIZE];
|
andrew@0
|
140 int frameIndex;
|
andrew@0
|
141 float energy[ENERGY_LENGTH];
|
andrew@0
|
142 float secondEnergy[ENERGY_LENGTH];
|
andrew@0
|
143
|
andrew@0
|
144 float chromoGramVector[CHROMA_LENGTH][12];
|
andrew@0
|
145 int rootChord[CHROMA_LENGTH];
|
andrew@0
|
146
|
andrew@0
|
147 // int energyIndex;
|
andrew@0
|
148 // int totalFrames;
|
andrew@0
|
149
|
andrew@0
|
150 int scrollWidth;// 1600
|
andrew@0
|
151 float chromoLength;
|
andrew@0
|
152
|
andrew@0
|
153 bool audioPlaying, audioPaused;
|
andrew@0
|
154 bool drawSecondMatrix;
|
andrew@0
|
155
|
andrew@0
|
156 float diagonalPenalty;
|
andrew@0
|
157
|
andrew@0
|
158 //------------------- for the simple sine wave synthesis
|
andrew@0
|
159 float targetFrequency;
|
andrew@0
|
160 float phase;
|
andrew@0
|
161 float phaseAdder;
|
andrew@0
|
162 float phaseAdderTarget;
|
andrew@0
|
163
|
andrew@0
|
164 string sndfileInfoString, textString;
|
andrew@0
|
165 int xIndex;
|
andrew@0
|
166
|
andrew@0
|
167 bool firstAudioFilePlaying;
|
andrew@0
|
168 ofSoundPlayer loadedAudio;
|
andrew@0
|
169 ofSoundPlayer secondAudio;
|
andrew@0
|
170 ofSoundPlayer *playingAudio;
|
andrew@0
|
171
|
andrew@0
|
172 float audioPosition;
|
andrew@0
|
173 float width, height;
|
andrew@0
|
174 int chromaIndex;
|
andrew@0
|
175 int totalNumberOfFrames;
|
andrew@0
|
176 int currentPlayingFrame;
|
andrew@0
|
177 int currentChromaFrame ;
|
andrew@0
|
178 string chordString;
|
andrew@0
|
179
|
andrew@0
|
180 //Chromagram* chromoGrammPtr;
|
andrew@0
|
181 Chromagram chromoGramm;
|
andrew@0
|
182 Chromagram secondChromoGramm;
|
andrew@0
|
183 string userInfoString;
|
andrew@0
|
184 ChordDetect chord;
|
andrew@0
|
185 //sndfile part
|
andrew@0
|
186 SNDFILE *infile; // define input and output sound files
|
andrew@0
|
187 SF_INFO sfinfo ; // struct to hold info about sound file
|
andrew@0
|
188
|
andrew@0
|
189
|
andrew@0
|
190 timeWarp tw;
|
andrew@0
|
191
|
andrew@0
|
192
|
andrew@0
|
193 };
|
andrew@0
|
194
|
andrew@0
|
195 #endif
|