annotate AutocorrelationProcessor.cpp @ 36:4010960c659e
* Merge with Chris' changes
author |
Carl Bussey <c.bussey@se10.qmul.ac.uk> |
date |
Thu, 04 Sep 2014 14:33:36 +0100 |
parents |
1ad47a9afc2e |
children |
4cf2d163127b |
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@28
|
11 #include <iostream>
|
c@25
|
12
|
c@26
|
13 AutocorrelationProcessor::AutocorrelationProcessor(const size_t &windowLength, const unsigned int &hopSize) :
|
c@25
|
14 m_windowLength(windowLength),
|
c@28
|
15 m_hopSize(hopSize)
|
c@25
|
16 {
|
c@28
|
17
|
c@26
|
18 }
|
c@26
|
19
|
c@29
|
20 AutocorrelationProcessor::~AutocorrelationProcessor()
|
c@29
|
21 {
|
c@28
|
22
|
c@25
|
23 }
|
c@25
|
24
|
c@25
|
25 AutoCorrelation AutocorrelationProcessor::process(float * input, const size_t &inputLength) const
|
c@25
|
26 {
|
c@25
|
27 int readBlockPointerIndex = 0;
|
c@25
|
28 AutoCorrelation autocorrelation;
|
c@25
|
29
|
c@25
|
30 while(readBlockPointerIndex <= (int)inputLength) {
|
c@25
|
31
|
c@28
|
32 vector<float> autocorrelationBlock;
|
c@28
|
33
|
c@28
|
34 for (int lag = 0; lag < (int)m_windowLength; lag++){
|
c@28
|
35 float sum = 0;
|
c@28
|
36 int readPointer = readBlockPointerIndex - m_windowLength/2;
|
c@26
|
37
|
c@28
|
38 for (int n = 0; n < (int)m_windowLength; n++){
|
c@28
|
39 if (readPointer+lag >= (int)inputLength) break;
|
c@28
|
40 else if (readPointer >= 0) sum += input[readPointer]*input[readPointer+lag];
|
c@28
|
41 //else cout << readPointer << " : "<< lag << "/" << m_windowLength << endl;
|
c@28
|
42
|
c@28
|
43 readPointer++;
|
c@28
|
44 }
|
c@28
|
45 autocorrelationBlock.push_back(sum/(2*m_windowLength + 1 - lag));
|
c@26
|
46 }
|
c@26
|
47
|
c@28
|
48 //autocorrelation.push_back(processBlock());
|
c@28
|
49 autocorrelation.push_back(autocorrelationBlock);
|
c@25
|
50 readBlockPointerIndex += m_hopSize;
|
c@25
|
51 }
|
c@25
|
52
|
c@25
|
53 return autocorrelation;
|
c@25
|
54 }
|