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