comparison AutocorrelationProcessor.cpp @ 28:723af5b3303a

* Fixed tempogram via ACT bin names etc
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Thu, 21 Aug 2014 11:07:20 +0100
parents a3a37c8dcee7
children 1ad47a9afc2e
comparison
equal deleted inserted replaced
27:a3a37c8dcee7 28:723af5b3303a
6 // Copyright (c) 2014 Carl Bussey. All rights reserved. 6 // Copyright (c) 2014 Carl Bussey. All rights reserved.
7 // 7 //
8 8
9 #include "AutocorrelationProcessor.h" 9 #include "AutocorrelationProcessor.h"
10 using namespace std; 10 using namespace std;
11 #include <iostream>
11 12
12 AutocorrelationProcessor::AutocorrelationProcessor(const size_t &windowLength, const unsigned int &hopSize) : 13 AutocorrelationProcessor::AutocorrelationProcessor(const size_t &windowLength, const unsigned int &hopSize) :
13 m_windowLength(windowLength), 14 m_windowLength(windowLength),
14 m_hopSize(hopSize), 15 m_hopSize(hopSize)
15 m_blockInput(0)
16 { 16 {
17 m_blockInput = new float [m_windowLength]; 17
18 } 18 }
19 19
20 AutocorrelationProcessor::~AutocorrelationProcessor(){ 20 AutocorrelationProcessor::~AutocorrelationProcessor(){
21 delete []m_blockInput; 21
22 m_blockInput = 0;
23 } 22 }
24 23
25 AutoCorrelation AutocorrelationProcessor::process(float * input, const size_t &inputLength) const 24 AutoCorrelation AutocorrelationProcessor::process(float * input, const size_t &inputLength) const
26 { 25 {
27 int readBlockPointerIndex = 0; 26 int readBlockPointerIndex = 0;
28 AutoCorrelation autocorrelation; 27 AutoCorrelation autocorrelation;
29 28
30 while(readBlockPointerIndex <= (int)inputLength) { 29 while(readBlockPointerIndex <= (int)inputLength) {
31 int readPointer = readBlockPointerIndex - m_windowLength/2; //read window centered at readBlockPointerIndex
32 30
33 for (int n = 0; n < (int)m_windowLength; n++){ 31 vector<float> autocorrelationBlock;
34 if (readPointer < 0 || readPointer >= (int)inputLength) m_blockInput[n] = 0.0f; 32
35 else m_blockInput[n] = input[readPointer]; 33 for (int lag = 0; lag < (int)m_windowLength; lag++){
34 float sum = 0;
35 int readPointer = readBlockPointerIndex - m_windowLength/2;
36 36
37 readPointer++; 37 for (int n = 0; n < (int)m_windowLength; n++){
38 if (readPointer+lag >= (int)inputLength) break;
39 else if (readPointer >= 0) sum += input[readPointer]*input[readPointer+lag];
40 //else cout << readPointer << " : "<< lag << "/" << m_windowLength << endl;
41
42 readPointer++;
43 }
44 autocorrelationBlock.push_back(sum/(2*m_windowLength + 1 - lag));
38 } 45 }
39 46
40 autocorrelation.push_back(processBlock()); 47 //autocorrelation.push_back(processBlock());
48 autocorrelation.push_back(autocorrelationBlock);
41 readBlockPointerIndex += m_hopSize; 49 readBlockPointerIndex += m_hopSize;
42 } 50 }
43 51
44 return autocorrelation; 52 return autocorrelation;
45 } 53 }
46
47 vector<float> AutocorrelationProcessor::processBlock() const
48 {
49 vector<float> autocorrelation;
50
51 int N = m_windowLength;
52
53 for (int lag = 0; lag < N; lag++){
54 float sum = 0;
55
56 for (int n = 0; n < N-lag; n++){
57 sum += m_blockInput[n]*m_blockInput[n+lag];
58 }
59 autocorrelation.push_back(sum/(2*N + 1 - lag));
60 }
61
62 return autocorrelation;
63 }