comparison DrumTimingLoader_OF/ofxAudioFileLoader/AudioAnalysis.cpp @ 0:82352cfc0b23

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