annotate AutocorrelationProcessor.cpp @ 25:fe23998968b4

* Added tempogram via autocorrelation feature, using AutocorrelationProcessor * Moved calculateMax() from NoveltyCurveProcessor to SpectrogramProcessor
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Wed, 20 Aug 2014 16:00:37 +0100
parents
children ff6110f1144b
rev   line source
c@25 1 //
c@25 2 // AutocorrelationProcessor.cpp
c@25 3 // Tempogram
c@25 4 //
c@25 5 // Created by Carl Bussey on 20/08/2014.
c@25 6 // Copyright (c) 2014 Carl Bussey. All rights reserved.
c@25 7 //
c@25 8
c@25 9 #include "AutocorrelationProcessor.h"
c@25 10 using namespace std;
c@25 11
c@25 12 AutocorrelationProcessor::AutocorrelationProcessor(const size_t &windowLength, const unsigned int &hopSize, const unsigned int &lagIncrement) :
c@25 13 m_windowLength(windowLength),
c@25 14 m_hopSize(hopSize),
c@25 15 m_lagIncrement(lagIncrement)
c@25 16 {
c@25 17 //Nothing to do here
c@25 18 }
c@25 19
c@25 20 AutoCorrelation AutocorrelationProcessor::process(float * input, const size_t &inputLength) const
c@25 21 {
c@25 22 int readBlockPointerIndex = 0;
c@25 23 AutoCorrelation autocorrelation;
c@25 24
c@25 25 while(readBlockPointerIndex <= (int)inputLength) {
c@25 26 int readPointer = readBlockPointerIndex - m_windowLength/2;
c@25 27
c@25 28 autocorrelation.push_back(processBlock(&input[readPointer], min(inputLength-readPointer, m_windowLength)));
c@25 29 readBlockPointerIndex += m_hopSize;
c@25 30 }
c@25 31
c@25 32 return autocorrelation;
c@25 33 }
c@25 34
c@25 35 vector<float> AutocorrelationProcessor::processBlock(float * blockInput, const size_t &blockLength) const
c@25 36 {
c@25 37 vector<float> autocorrelation;
c@25 38
c@25 39 int N = m_windowLength/m_lagIncrement;
c@25 40
c@25 41 for (int lag = 0; lag < N; lag++){
c@25 42 float sum = 0;
c@25 43 int sampleLag = m_lagIncrement*lag;
c@25 44
c@25 45 for (int n = sampleLag; n < (int)blockLength; n++){
c@25 46 sum += blockInput[n-sampleLag]*blockInput[n];
c@25 47 }
c@25 48 autocorrelation.push_back(sum/(2*N + 1 - lag));
c@25 49 }
c@25 50
c@25 51 return autocorrelation;
c@25 52 }