andrew@0
|
1 /*
|
andrew@0
|
2 * AudioAnalysis.cpp
|
andrew@0
|
3 * audioFileLoader4
|
andrew@0
|
4 *
|
andrew@0
|
5 * Created by Andrew on 14/08/2011.
|
andrew@0
|
6 * Copyright 2011 QMUL. All rights reserved.
|
andrew@0
|
7 *
|
andrew@0
|
8 */
|
andrew@0
|
9
|
andrew@0
|
10 #include "AudioAnalysis.h"
|
andrew@0
|
11
|
andrew@0
|
12
|
andrew@1
|
13 AudioAnalysis::AudioAnalysis(){
|
andrew@1
|
14 chromoGramm.initialise(FRAMESIZE,2048);
|
andrew@1
|
15
|
andrew@1
|
16 scrollWidth = 1600;
|
andrew@1
|
17
|
andrew@1
|
18 }
|
andrew@1
|
19
|
andrew@1
|
20
|
andrew@1
|
21
|
andrew@1
|
22 void AudioAnalysis::drawEnergyVectorFromPointer(){
|
andrew@1
|
23 DoubleVector* energyVec;
|
andrew@1
|
24 energyVec = &energyVector;
|
andrew@1
|
25 //xxx above
|
andrew@1
|
26
|
andrew@1
|
27 ofSetColor(0xFF0066);
|
andrew@1
|
28 float screenHeight = ofGetHeight() ;
|
andrew@1
|
29 float screenWidth = ofGetWidth();
|
andrew@1
|
30 float heightFactor = 8;
|
andrew@1
|
31 int i, j, startingFrame;
|
andrew@1
|
32 startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
|
andrew@1
|
33 startingFrame *= scrollWidth;
|
andrew@1
|
34
|
andrew@1
|
35 for (i = 0; i < scrollWidth - 1; i++){
|
andrew@1
|
36 j = i + startingFrame;
|
andrew@1
|
37 if (j < (*energyVec).size())
|
andrew@1
|
38 ofLine(i*screenWidth/scrollWidth, screenHeight - ((*energyVec)[j]*screenHeight/heightFactor),
|
andrew@1
|
39 screenWidth*(i+1)/scrollWidth, screenHeight - ((*energyVec)[j+1]*screenHeight/heightFactor));
|
andrew@1
|
40
|
andrew@1
|
41 }
|
andrew@1
|
42 }
|
andrew@1
|
43
|
andrew@1
|
44 void AudioAnalysis::drawSpectralDifference(){
|
andrew@1
|
45 DoubleMatrix* dMatrix;
|
andrew@1
|
46 dMatrix = &chromaMatrix;
|
andrew@1
|
47 //get rid of these!
|
andrew@1
|
48
|
andrew@1
|
49 int matrixSize = (*dMatrix).size();
|
andrew@1
|
50 if (matrixSize > 0){
|
andrew@1
|
51
|
andrew@1
|
52 float screenHeight = ofGetHeight() ;
|
andrew@1
|
53 float screenWidth = ofGetWidth();
|
andrew@1
|
54 float heightFactor = 8;
|
andrew@1
|
55 double difference;
|
andrew@1
|
56 int i, j, startingFrame;
|
andrew@1
|
57 startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
|
andrew@1
|
58 startingFrame *= scrollWidth;//starting frame in terms of energy frames
|
andrew@1
|
59 startingFrame /= CHROMA_CONVERSION_FACTOR; //in terms of chroma frames
|
andrew@1
|
60
|
andrew@1
|
61 float chromoLength = scrollWidth/CHROMA_CONVERSION_FACTOR;
|
andrew@1
|
62 for (i = 1; i < chromoLength; i++){//changed to add 1
|
andrew@1
|
63 j = i + startingFrame;
|
andrew@1
|
64 for (int y = 0;y < 12;y++){
|
andrew@1
|
65
|
andrew@1
|
66 if (j < matrixSize)
|
andrew@1
|
67 difference = (*dMatrix)[j][11-y] - (*dMatrix)[j-1][11-y];
|
andrew@1
|
68 else
|
andrew@1
|
69 difference = 0;
|
andrew@1
|
70
|
andrew@1
|
71 if (difference < 0)
|
andrew@1
|
72 difference = 0;//half wave rectify
|
andrew@1
|
73
|
andrew@1
|
74 ofSetColor(0,0,255 * difference);//, 0;
|
andrew@1
|
75 ofRect(i*screenWidth/chromoLength,y*screenHeight/12,screenWidth/chromoLength,screenHeight/12);
|
andrew@1
|
76 }//end y
|
andrew@1
|
77 }//end i
|
andrew@1
|
78
|
andrew@1
|
79 }///end if matrix has content
|
andrew@1
|
80 else{
|
andrew@1
|
81 printf("Error - please load audio first");
|
andrew@1
|
82 }
|
andrew@1
|
83
|
andrew@1
|
84 }
|
andrew@1
|
85
|
andrew@1
|
86
|
andrew@0
|
87 /*
|
andrew@0
|
88 void testApp::initialiseVariables(){
|
andrew@0
|
89
|
andrew@0
|
90 energyIndex = 0;
|
andrew@0
|
91 // frameIndex = 0;
|
andrew@0
|
92 chromaIndex = 0;
|
andrew@0
|
93 chromoGramm.initialise(FRAMESIZE,2048);//framesize 512 and hopsize 2048
|
andrew@0
|
94 }
|
andrew@0
|
95
|
andrew@0
|
96
|
andrew@0
|
97 //--------------------------------------------------------------
|
andrew@0
|
98 void testApp::draw(){
|
andrew@0
|
99 switch (screenToDraw){
|
andrew@0
|
100 case 0:
|
andrew@0
|
101 if (drawSpectralDifferenceFunction)
|
andrew@0
|
102 drawSpectralDifference(&chromaMatrix);
|
andrew@0
|
103 else
|
andrew@0
|
104 drawDoubleMatrix(&chromaMatrix);
|
andrew@0
|
105
|
andrew@0
|
106 drawEnergyVectorFromPointer(&firstEnergyVector);
|
andrew@0
|
107 break;
|
andrew@0
|
108 case 1:
|
andrew@0
|
109 // audioHolder.drawAudioVectorMillis(1000, 1000+audioScale);
|
andrew@0
|
110 audioHolder.drawAudioVectorSamples(audioHolder.playPosition, audioHolder.playPosition+audioHolder.audioScaleSamples);
|
andrew@0
|
111 break;
|
andrew@0
|
112 }
|
andrew@0
|
113
|
andrew@0
|
114
|
andrew@0
|
115
|
andrew@0
|
116 //ofSetColor(255,0,0);
|
andrew@0
|
117 //drawEnergyVectorFromPointer(&audioVector);
|
andrew@0
|
118
|
andrew@0
|
119 ofSetColor(0xFFFFFF);
|
andrew@0
|
120 ofLine(audioPosition*width, 0, audioPosition*width, height);
|
andrew@0
|
121
|
andrew@0
|
122 ofDrawBitmapString(soundFileName,80,480);
|
andrew@0
|
123
|
andrew@0
|
124 }
|
andrew@0
|
125
|
andrew@0
|
126
|
andrew@0
|
127 void testApp::drawEnergyVectorFromPointer(DoubleVector* energyVec){
|
andrew@0
|
128
|
andrew@0
|
129 ofSetColor(0xFF0066);
|
andrew@0
|
130 float screenHeight = ofGetHeight() ;
|
andrew@0
|
131 float screenWidth = ofGetWidth();
|
andrew@0
|
132 float heightFactor = 8;
|
andrew@0
|
133 int i, j, startingFrame;
|
andrew@0
|
134 startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
|
andrew@0
|
135 startingFrame *= scrollWidth;
|
andrew@0
|
136
|
andrew@0
|
137 for (i = 0; i < scrollWidth - 1; i++){
|
andrew@0
|
138 j = i + startingFrame;
|
andrew@0
|
139 if (j < (*energyVec).size())
|
andrew@0
|
140 ofLine(i*screenWidth/scrollWidth, screenHeight - ((*energyVec)[j]*screenHeight/heightFactor),
|
andrew@0
|
141 screenWidth*(i+1)/scrollWidth, screenHeight - ((*energyVec)[j+1]*screenHeight/heightFactor));
|
andrew@0
|
142
|
andrew@0
|
143 }
|
andrew@0
|
144 }
|
andrew@0
|
145
|
andrew@0
|
146 void testApp::drawSpectralDifference(DoubleMatrix* dMatrix){
|
andrew@0
|
147 int matrixSize = (*dMatrix).size();
|
andrew@0
|
148 if (matrixSize > 0){
|
andrew@0
|
149
|
andrew@0
|
150 float screenHeight = ofGetHeight() ;
|
andrew@0
|
151 float screenWidth = ofGetWidth();
|
andrew@0
|
152 float heightFactor = 8;
|
andrew@0
|
153 double difference;
|
andrew@0
|
154 int i, j, startingFrame;
|
andrew@0
|
155 startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
|
andrew@0
|
156 startingFrame *= scrollWidth;//starting frame in terms of energy frames
|
andrew@0
|
157 startingFrame /= CHROMA_CONVERSION_FACTOR; //in terms of chroma frames
|
andrew@0
|
158
|
andrew@0
|
159 float chromoLength = scrollWidth/CHROMA_CONVERSION_FACTOR;
|
andrew@0
|
160 for (i = 1; i < chromoLength; i++){//changed to add 1
|
andrew@0
|
161 j = i + startingFrame;
|
andrew@0
|
162 for (int y = 0;y < 12;y++){
|
andrew@0
|
163
|
andrew@0
|
164 if (j < matrixSize)
|
andrew@0
|
165 difference = (*dMatrix)[j][11-y] - (*dMatrix)[j-1][11-y];
|
andrew@0
|
166 else
|
andrew@0
|
167 difference = 0;
|
andrew@0
|
168
|
andrew@0
|
169 if (difference < 0)
|
andrew@0
|
170 difference = 0;//half wave rectify
|
andrew@0
|
171
|
andrew@0
|
172 ofSetColor(0,0,255 * difference);//, 0;
|
andrew@0
|
173 ofRect(i*screenWidth/chromoLength,y*screenHeight/12,screenWidth/chromoLength,screenHeight/12);
|
andrew@0
|
174 }//end y
|
andrew@0
|
175 }//end i
|
andrew@0
|
176
|
andrew@0
|
177 }///end if matrix has content
|
andrew@0
|
178 else{
|
andrew@0
|
179 printf("Error - please load audio first");
|
andrew@0
|
180 }
|
andrew@0
|
181
|
andrew@0
|
182 }
|
andrew@0
|
183
|
andrew@0
|
184
|
andrew@0
|
185 void testApp::drawDoubleMatrix(DoubleMatrix* dMatrix){
|
andrew@0
|
186 //used to draw the chromagram matrix
|
andrew@0
|
187 int matrixSize = (*dMatrix).size();
|
andrew@0
|
188 if (matrixSize > 0){
|
andrew@0
|
189
|
andrew@0
|
190 float screenHeight = ofGetHeight() ;
|
andrew@0
|
191 float screenWidth = ofGetWidth();
|
andrew@0
|
192 float heightFactor = 8;
|
andrew@0
|
193 int i, j, startingFrame;
|
andrew@0
|
194 startingFrame = currentPlayingFrame / scrollWidth;//i.e. number of scroll widths in
|
andrew@0
|
195 startingFrame *= scrollWidth;//starting frame in terms of energy frames
|
andrew@0
|
196 startingFrame /= CHROMA_CONVERSION_FACTOR; //in terms of chroma frames
|
andrew@0
|
197
|
andrew@0
|
198 float chromoLength = scrollWidth/CHROMA_CONVERSION_FACTOR;
|
andrew@0
|
199 for (i = 0; i < chromoLength; i++){
|
andrew@0
|
200 j = i + startingFrame;
|
andrew@0
|
201 for (int y = 0;y < 12;y++){
|
andrew@0
|
202
|
andrew@0
|
203 if (j < matrixSize)
|
andrew@0
|
204 ofSetColor(0,0,255 * (*dMatrix)[j][11-y]);
|
andrew@0
|
205 else
|
andrew@0
|
206 ofSetColor(0,0,0);
|
andrew@0
|
207
|
andrew@0
|
208 ofRect(i*screenWidth/chromoLength,y*screenHeight/12,screenWidth/chromoLength,screenHeight/12);
|
andrew@0
|
209 }//end y
|
andrew@0
|
210 }//end i
|
andrew@0
|
211
|
andrew@0
|
212 }///end if matrix has content
|
andrew@0
|
213 else{
|
andrew@0
|
214 printf("Error - please load audio first");
|
andrew@0
|
215 }
|
andrew@0
|
216
|
andrew@0
|
217
|
andrew@0
|
218 }
|
andrew@0
|
219
|
andrew@0
|
220
|
andrew@0
|
221
|
andrew@0
|
222
|
andrew@0
|
223
|
andrew@0
|
224 */
|
andrew@0
|
225
|
andrew@0
|
226
|