comparison TempogramPlugin.cpp @ 29:1ad47a9afc2e

* Changed variable names * Took calculations out of setParameter() function and placed into initialise()
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Tue, 02 Sep 2014 11:40:48 +0100
parents 723af5b3303a
children 36cffe6493e4
comparison
equal deleted inserted replaced
28:723af5b3303a 29:1ad47a9afc2e
13 13
14 TempogramPlugin::TempogramPlugin(float inputSampleRate) : 14 TempogramPlugin::TempogramPlugin(float inputSampleRate) :
15 Plugin(inputSampleRate), 15 Plugin(inputSampleRate),
16 m_inputBlockSize(0), //host parameter 16 m_inputBlockSize(0), //host parameter
17 m_inputStepSize(0), //host parameter 17 m_inputStepSize(0), //host parameter
18 m_noveltyCurveMinDB(pow(10,(float)-74/20)), //set in initialise() 18 m_noveltyCurveMinDB(-74), //parameter
19 m_noveltyCurveMinV(0), //set in initialise()
19 m_noveltyCurveCompressionConstant(1000), //parameter 20 m_noveltyCurveCompressionConstant(1000), //parameter
20 m_tempogramLog2WindowLength(10), //parameter 21 m_tempogramLog2WindowLength(10), //parameter
21 m_tempogramWindowLength(pow((float)2,m_tempogramLog2WindowLength)), 22 m_tempogramWindowLength(0), //set in initialise()
22 m_tempogramLog2FftLength(m_tempogramLog2WindowLength), //parameter 23 m_tempogramLog2FftLength(m_tempogramLog2WindowLength), //parameter
23 m_tempogramFftLength(m_tempogramWindowLength), 24 m_tempogramFftLength(0), //set in initialise()
24 m_tempogramLog2HopSize(6), //parameter 25 m_tempogramLog2HopSize(6), //parameter
25 m_tempogramHopSize(pow((float)2,m_tempogramLog2HopSize)), 26 m_tempogramHopSize(0), //set in initialise()
26 m_tempogramMinBPM(30), //parameter 27 m_tempogramMinBPM(30), //parameter
27 m_tempogramMaxBPM(480), //parameter 28 m_tempogramMaxBPM(480), //parameter
28 m_tempogramMinBin(0), //set in initialise() 29 m_tempogramMinBin(0), //set in initialise()
29 m_tempogramMaxBin(0), //set in initialise() 30 m_tempogramMaxBin(0), //set in initialise()
30 m_tempogramMinLag(0), 31 m_tempogramMinLag(0), //set in initialise()
31 m_tempogramMaxLag(0), 32 m_tempogramMaxLag(0), //set in initialise()
32 m_cyclicTempogramMinBPM(30), //reset in initialise() 33 m_cyclicTempogramMinBPM(30), //reset in initialise()
33 m_cyclicTempogramNumberOfOctaves(0), //set in initialise() 34 m_cyclicTempogramNumberOfOctaves(0), //set in initialise()
34 m_cyclicTempogramOctaveDivider(30) //parameter 35 m_cyclicTempogramOctaveDivider(30) //parameter
35 36
36 // Also be sure to set your plugin parameters (presumably stored 37 // Also be sure to set your plugin parameters (presumably stored
40 } 41 }
41 42
42 TempogramPlugin::~TempogramPlugin() 43 TempogramPlugin::~TempogramPlugin()
43 { 44 {
44 //delete stuff 45 //delete stuff
45
46 } 46 }
47 47
48 string 48 string
49 TempogramPlugin::getIdentifier() const 49 TempogramPlugin::getIdentifier() const
50 { 50 {
145 d1.minValue = 2; 145 d1.minValue = 2;
146 d1.maxValue = 10000; 146 d1.maxValue = 10000;
147 d1.defaultValue = 1000; 147 d1.defaultValue = 1000;
148 d1.isQuantized = false; 148 d1.isQuantized = false;
149 list.push_back(d1); 149 list.push_back(d1);
150 150
151 ParameterDescriptor d2; 151 ParameterDescriptor d2;
152 d2.identifier = "log2TN"; 152 d2.identifier = "minDB";
153 d2.name = "Tempogram Window Length"; 153 d2.name = "Novelty Curve Minimum DB";
154 d2.description = "FFT window length when analysing the novelty curve and extracting the tempogram time-frequency function."; 154 d2.description = "Spectrogram minimum DB used when removing unwanted peaks in the Spectrogram when retrieving the novelty curve from the audio.";
155 d2.unit = ""; 155 d2.unit = "";
156 d2.minValue = 7; 156 d2.minValue = -100;
157 d2.maxValue = 12; 157 d2.maxValue = -50;
158 d2.defaultValue = 10; 158 d2.defaultValue = -74;
159 d2.isQuantized = true; 159 d2.isQuantized = false;
160 d2.quantizeStep = 1;
161 for (int i = d2.minValue; i <= d2.maxValue; i++){
162 d2.valueNames.push_back(floatToString(pow((float)2,(float)i)));
163 }
164 list.push_back(d2); 160 list.push_back(d2);
165 161
166 ParameterDescriptor d3; 162 ParameterDescriptor d3;
167 d3.identifier = "log2HopSize"; 163 d3.identifier = "log2TN";
168 d3.name = "Tempogram Hopsize"; 164 d3.name = "Tempogram Window Length";
169 d3.description = "FFT hopsize when analysing the novelty curve and extracting the tempogram time-frequency function."; 165 d3.description = "FFT window length when analysing the novelty curve and extracting the tempogram time-frequency function.";
170 d3.unit = ""; 166 d3.unit = "";
171 d3.minValue = 6; 167 d3.minValue = 7;
172 d3.maxValue = 12; 168 d3.maxValue = 12;
173 d3.defaultValue = 6; 169 d3.defaultValue = 10;
174 d3.isQuantized = true; 170 d3.isQuantized = true;
175 d3.quantizeStep = 1; 171 d3.quantizeStep = 1;
176 for (int i = d3.minValue; i <= d3.maxValue; i++){ 172 for (int i = d3.minValue; i <= d3.maxValue; i++){
177 d3.valueNames.push_back(floatToString(pow((float)2,(float)i))); 173 d3.valueNames.push_back(floatToString(pow((float)2,(float)i)));
178 } 174 }
179 list.push_back(d3); 175 list.push_back(d3);
180 176
181 ParameterDescriptor d4; 177 ParameterDescriptor d4;
182 d4.identifier = "log2FftLength"; 178 d4.identifier = "log2HopSize";
183 d4.name = "Tempogram FFT Length"; 179 d4.name = "Tempogram Hopsize";
184 d4.description = "FFT length when analysing the novelty curve and extracting the tempogram time-frequency function. This parameter determines the amount of zero padding."; 180 d4.description = "FFT hopsize when analysing the novelty curve and extracting the tempogram time-frequency function.";
185 d4.unit = ""; 181 d4.unit = "";
186 d4.minValue = 6; 182 d4.minValue = 6;
187 d4.maxValue = 12; 183 d4.maxValue = 12;
188 d4.defaultValue = d2.defaultValue; 184 d4.defaultValue = 6;
189 d4.isQuantized = true; 185 d4.isQuantized = true;
190 d4.quantizeStep = 1; 186 d4.quantizeStep = 1;
191 for (int i = d4.minValue; i <= d4.maxValue; i++){ 187 for (int i = d4.minValue; i <= d4.maxValue; i++){
192 d4.valueNames.push_back(floatToString(pow((float)2,(float)i))); 188 d4.valueNames.push_back(floatToString(pow((float)2,(float)i)));
193 } 189 }
194 list.push_back(d4); 190 list.push_back(d4);
195 191
196 ParameterDescriptor d5; 192 ParameterDescriptor d5;
197 d5.identifier = "minBPM"; 193 d5.identifier = "log2FftLength";
198 d5.name = "(Cyclic) Tempogram Minimum BPM"; 194 d5.name = "Tempogram FFT Length";
199 d5.description = "The minimum BPM of the tempogram output bins."; 195 d5.description = "FFT length when analysing the novelty curve and extracting the tempogram time-frequency function. This parameter determines the amount of zero padding.";
200 d5.unit = ""; 196 d5.unit = "";
201 d5.minValue = 0; 197 d5.minValue = 6;
202 d5.maxValue = 2000; 198 d5.maxValue = 12;
203 d5.defaultValue = 30; 199 d5.defaultValue = d2.defaultValue;
204 d5.isQuantized = true; 200 d5.isQuantized = true;
205 d5.quantizeStep = 5; 201 d5.quantizeStep = 1;
202 for (int i = d5.minValue; i <= d5.maxValue; i++){
203 d4.valueNames.push_back(floatToString(pow((float)2,(float)i)));
204 }
206 list.push_back(d5); 205 list.push_back(d5);
207 206
208 ParameterDescriptor d6; 207 ParameterDescriptor d6;
209 d6.identifier = "maxBPM"; 208 d6.identifier = "minBPM";
210 d6.name = "(Cyclic) Tempogram Maximum BPM"; 209 d6.name = "(Cyclic) Tempogram Minimum BPM";
211 d6.description = "The maximum BPM of the tempogram output bins."; 210 d6.description = "The minimum BPM of the tempogram output bins.";
212 d6.unit = ""; 211 d6.unit = "";
213 d6.minValue = 30; 212 d6.minValue = 0;
214 d6.maxValue = 2000; 213 d6.maxValue = 2000;
215 d6.defaultValue = 480; 214 d6.defaultValue = 30;
216 d6.isQuantized = true; 215 d6.isQuantized = true;
217 d6.quantizeStep = 5; 216 d6.quantizeStep = 5;
218 list.push_back(d6); 217 list.push_back(d6);
219 218
220 ParameterDescriptor d7; 219 ParameterDescriptor d7;
221 d7.identifier = "octDiv"; 220 d7.identifier = "maxBPM";
222 d7.name = "Cyclic Tempogram Octave Divider"; 221 d7.name = "(Cyclic) Tempogram Maximum BPM";
223 d7.description = "The number bins within each octave."; 222 d7.description = "The maximum BPM of the tempogram output bins.";
224 d7.unit = ""; 223 d7.unit = "";
225 d7.minValue = 5; 224 d7.minValue = 30;
226 d7.maxValue = 60; 225 d7.maxValue = 2000;
227 d7.defaultValue = 30; 226 d7.defaultValue = 480;
228 d7.isQuantized = true; 227 d7.isQuantized = true;
229 d7.quantizeStep = 1; 228 d7.quantizeStep = 5;
230 list.push_back(d7); 229 list.push_back(d7);
230
231 ParameterDescriptor d8;
232 d8.identifier = "octDiv";
233 d8.name = "Cyclic Tempogram Octave Divider";
234 d8.description = "The number bins within each octave.";
235 d8.unit = "";
236 d8.minValue = 5;
237 d8.maxValue = 60;
238 d8.defaultValue = 30;
239 d8.isQuantized = true;
240 d8.quantizeStep = 1;
241 list.push_back(d8);
231 242
232 return list; 243 return list;
233 } 244 }
234 245
235 float 246 float
236 TempogramPlugin::getParameter(string identifier) const 247 TempogramPlugin::getParameter(string identifier) const
237 { 248 {
238 if (identifier == "C") { 249 if (identifier == "C") {
239 return m_noveltyCurveCompressionConstant; // return the ACTUAL current value of your parameter here! 250 return m_noveltyCurveCompressionConstant; // return the ACTUAL current value of your parameter here!
240 } 251 }
252 else if (identifier == "minDB"){
253 return m_noveltyCurveMinDB;
254 }
241 else if (identifier == "log2TN"){ 255 else if (identifier == "log2TN"){
242 return m_tempogramLog2WindowLength; 256 return m_tempogramLog2WindowLength;
243 } 257 }
244 else if (identifier == "log2HopSize"){ 258 else if (identifier == "log2HopSize"){
245 return m_tempogramLog2HopSize; 259 return m_tempogramLog2HopSize;
265 { 279 {
266 280
267 if (identifier == "C") { 281 if (identifier == "C") {
268 m_noveltyCurveCompressionConstant = value; // set the actual value of your parameter 282 m_noveltyCurveCompressionConstant = value; // set the actual value of your parameter
269 } 283 }
284 else if (identifier == "minDB"){
285 m_noveltyCurveMinDB = value;
286 }
270 else if (identifier == "log2TN") { 287 else if (identifier == "log2TN") {
271 m_tempogramWindowLength = pow(2,value);
272 m_tempogramLog2WindowLength = value; 288 m_tempogramLog2WindowLength = value;
273 } 289 }
274 else if (identifier == "log2HopSize"){ 290 else if (identifier == "log2HopSize"){
275 m_tempogramHopSize = pow(2,value); 291 m_tempogramHopSize = pow(2,value);
276 m_tempogramLog2HopSize = value;
277 } 292 }
278 else if (identifier == "log2FftLength"){ 293 else if (identifier == "log2FftLength"){
279 m_tempogramFftLength = pow(2,value); 294 m_tempogramFftLength = pow(2,value);
280 m_tempogramLog2FftLength = value;
281 } 295 }
282 else if (identifier == "minBPM") { 296 else if (identifier == "minBPM") {
283 m_tempogramMinBPM = value; 297 m_tempogramMinBPM = value;
284 } 298 }
285 else if (identifier == "maxBPM"){ 299 else if (identifier == "maxBPM"){
420 } 434 }
421 435
422 TempogramPlugin::FeatureSet 436 TempogramPlugin::FeatureSet
423 TempogramPlugin::process(const float *const *inputBuffers, Vamp::RealTime timestamp) 437 TempogramPlugin::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
424 { 438 {
425
426 int n = m_inputBlockSize/2 + 1; 439 int n = m_inputBlockSize/2 + 1;
427 const float *in = inputBuffers[0]; 440 const float *in = inputBuffers[0];
428 441
429 //calculate magnitude of FrequencyDomain input 442 //calculate magnitude of FrequencyDomain input
430 vector<float> fftCoefficients; 443 vector<float> fftCoefficients;
431 for (int i = 0; i < n; i++){ 444 for (int i = 0; i < n; i++){
432 float magnitude = sqrt(in[2*i] * in[2*i] + in[2*i + 1] * in[2*i + 1]); 445 float magnitude = sqrt(in[2*i] * in[2*i] + in[2*i + 1] * in[2*i + 1]);
433 magnitude = magnitude > m_noveltyCurveMinDB ? magnitude : m_noveltyCurveMinDB; 446 magnitude = magnitude > m_noveltyCurveMinV ? magnitude : m_noveltyCurveMinV;
434 fftCoefficients.push_back(magnitude); 447 fftCoefficients.push_back(magnitude);
435 } 448 }
436 m_spectrogram.push_back(fftCoefficients); 449 m_spectrogram.push_back(fftCoefficients);
437 //m_spectrogram.push_back(fftCoefficients); 450 //m_spectrogram.push_back(fftCoefficients);
438 451
576 if (m_tempogramMinBPM >= m_tempogramMaxBPM){ 589 if (m_tempogramMinBPM >= m_tempogramMaxBPM){
577 m_tempogramMinBPM = 30; 590 m_tempogramMinBPM = 30;
578 m_tempogramMaxBPM = 480; 591 m_tempogramMaxBPM = 480;
579 } 592 }
580 593
594 m_noveltyCurveMinV = pow(10,(float)m_noveltyCurveMinDB/20);
595
596 m_tempogramWindowLength = pow(2,m_tempogramLog2WindowLength);
597 m_tempogramHopSize = pow(2,m_tempogramLog2HopSize);
598 m_tempogramFftLength = pow(2,m_tempogramLog2FftLength);
599
581 float tempogramInputSampleRate = (float)m_inputSampleRate/m_inputStepSize; 600 float tempogramInputSampleRate = (float)m_inputSampleRate/m_inputStepSize;
582 m_tempogramMinBin = (max((int)floor(((m_tempogramMinBPM/60)/tempogramInputSampleRate)*m_tempogramFftLength), 0)); 601 m_tempogramMinBin = (max((int)floor(((m_tempogramMinBPM/60)/tempogramInputSampleRate)*m_tempogramFftLength), 0));
583 m_tempogramMaxBin = (min((int)ceil(((m_tempogramMaxBPM/60)/tempogramInputSampleRate)*m_tempogramFftLength), (int)(m_tempogramFftLength/2))); 602 m_tempogramMaxBin = (min((int)ceil(((m_tempogramMaxBPM/60)/tempogramInputSampleRate)*m_tempogramFftLength), (int)(m_tempogramFftLength/2)));
584 603
585 m_tempogramMinLag = max((int)ceil((60/(m_inputStepSize * m_tempogramMaxBPM))*m_inputSampleRate), 0); 604 m_tempogramMinLag = max((int)ceil((60/(m_inputStepSize * m_tempogramMaxBPM))*m_inputSampleRate), 0);