comparison 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
comparison
equal deleted inserted replaced
24:957b83524c06 25:fe23998968b4
1 //
2 // AutocorrelationProcessor.cpp
3 // Tempogram
4 //
5 // Created by Carl Bussey on 20/08/2014.
6 // Copyright (c) 2014 Carl Bussey. All rights reserved.
7 //
8
9 #include "AutocorrelationProcessor.h"
10 using namespace std;
11
12 AutocorrelationProcessor::AutocorrelationProcessor(const size_t &windowLength, const unsigned int &hopSize, const unsigned int &lagIncrement) :
13 m_windowLength(windowLength),
14 m_hopSize(hopSize),
15 m_lagIncrement(lagIncrement)
16 {
17 //Nothing to do here
18 }
19
20 AutoCorrelation AutocorrelationProcessor::process(float * input, const size_t &inputLength) const
21 {
22 int readBlockPointerIndex = 0;
23 AutoCorrelation autocorrelation;
24
25 while(readBlockPointerIndex <= (int)inputLength) {
26 int readPointer = readBlockPointerIndex - m_windowLength/2;
27
28 autocorrelation.push_back(processBlock(&input[readPointer], min(inputLength-readPointer, m_windowLength)));
29 readBlockPointerIndex += m_hopSize;
30 }
31
32 return autocorrelation;
33 }
34
35 vector<float> AutocorrelationProcessor::processBlock(float * blockInput, const size_t &blockLength) const
36 {
37 vector<float> autocorrelation;
38
39 int N = m_windowLength/m_lagIncrement;
40
41 for (int lag = 0; lag < N; lag++){
42 float sum = 0;
43 int sampleLag = m_lagIncrement*lag;
44
45 for (int n = sampleLag; n < (int)blockLength; n++){
46 sum += blockInput[n-sampleLag]*blockInput[n];
47 }
48 autocorrelation.push_back(sum/(2*N + 1 - lag));
49 }
50
51 return autocorrelation;
52 }