comparison Tempogram.cpp @ 11:09fb76606b2b

* Removed many unnecessary heap allocations with objects
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Wed, 13 Aug 2014 10:45:46 +0100
parents be59b4a73f49
children 7680cc4c0073
comparison
equal deleted inserted replaced
9:be59b4a73f49 11:09fb76606b2b
327 327
328 void 328 void
329 Tempogram::reset() 329 Tempogram::reset()
330 { 330 {
331 // Clear buffers, reset stored values, etc 331 // Clear buffers, reset stored values, etc
332 cleanupForGRF();
333 ncTimestamps.clear(); 332 ncTimestamps.clear();
334 specData.clear(); 333 specData.clear();
335 specData = vector< vector<float> >(m_blockSize/2 + 1); 334 specData = vector< vector<float> >(m_blockSize/2 + 1);
336 } 335 }
337 336
356 ncTimestamps.push_back(timestamp); //save timestamp 355 ncTimestamps.push_back(timestamp); //save timestamp
357 356
358 return featureSet; 357 return featureSet;
359 } 358 }
360 359
361 void 360 Tempogram::FeatureSet
362 Tempogram::initialiseForGRF(){ 361 Tempogram::getRemainingFeatures()
363 hannWindowtN = new float[windowLength]; 362 {
364 363
364 float * hannWindowtN = new float[windowLength];
365 for (int i = 0; i < windowLength; i++){ 365 for (int i = 0; i < windowLength; i++){
366 hannWindowtN[i] = 0.0; 366 hannWindowtN[i] = 0.0;
367 } 367 }
368 } 368
369
370 void
371 Tempogram::cleanupForGRF(){
372 delete []hannWindowtN;
373 hannWindowtN = NULL;
374 }
375
376
377
378 Tempogram::FeatureSet
379 Tempogram::getRemainingFeatures()
380 {
381 //Make sure this is called at the beginning of the function
382 initialiseForGRF();
383 FeatureSet featureSet; 369 FeatureSet featureSet;
384 370
385 //initialise noveltycurve processor 371 //initialise noveltycurve processor
386 NoveltyCurve nc(m_inputSampleRate, m_blockSize, numberOfBlocks, compressionConstant); 372 NoveltyCurve nc(m_inputSampleRate, m_blockSize, numberOfBlocks, compressionConstant);
387 noveltyCurve = nc.spectrogramToNoveltyCurve(specData); //calculate novelty curve from magnitude data 373 noveltyCurve = nc.spectrogramToNoveltyCurve(specData); //calculate novelty curve from magnitude data
397 383
398 //window function for spectrogram 384 //window function for spectrogram
399 WindowFunction::hanning(hannWindowtN,windowLength); 385 WindowFunction::hanning(hannWindowtN,windowLength);
400 386
401 //initialise spectrogram processor 387 //initialise spectrogram processor
402 Spectrogram * spectrogramProcessor = new Spectrogram(numberOfBlocks, windowLength, fftLength, thopSize); 388 SpectrogramProcessor spectrogramProcessor(numberOfBlocks, windowLength, fftLength, thopSize);
403 //compute spectrogram from novelty curve data (i.e., tempogram) 389 //compute spectrogram from novelty curve data (i.e., tempogram)
404 vector< vector<float> > tempogram = spectrogramProcessor->audioToMagnitudeSpectrogram(&noveltyCurve[0], hannWindowtN); 390 vector< vector<float> > tempogram = spectrogramProcessor.process(&noveltyCurve[0], hannWindowtN);
405 delete spectrogramProcessor;
406 spectrogramProcessor = NULL;
407 391
408 int timePointer = thopSize-windowLength/2; 392 int timePointer = thopSize-windowLength/2;
409 int tempogramLength = tempogram[0].size(); 393 int tempogramLength = tempogram[0].size();
410 394
411 //push tempogram data to featureset 0 and set timestamps. 395 //push tempogram data to featureset 0 and set timestamps.
423 featureSet[0].push_back(feature); 407 featureSet[0].push_back(feature);
424 408
425 timePointer += thopSize; 409 timePointer += thopSize;
426 } 410 }
427 411
428 //Make sure this is called at the end of the function 412 //float func = [](){ cout << "Hello"; };
429 cleanupForGRF(); 413
414 delete []hannWindowtN;
415 hannWindowtN = NULL;
430 416
431 return featureSet; 417 return featureSet;
432 } 418 }