comparison AutocorrelationProcessor.cpp @ 44:a908a5a56267

Some unsigned -> int (while bug hunting)
author Chris Cannam
date Thu, 25 Sep 2014 15:42:15 +0100
parents 4cf2d163127b
children
comparison
equal deleted inserted replaced
43:4cf2d163127b 44:a908a5a56267
14 14
15 #include "AutocorrelationProcessor.h" 15 #include "AutocorrelationProcessor.h"
16 using namespace std; 16 using namespace std;
17 #include <iostream> 17 #include <iostream>
18 18
19 AutocorrelationProcessor::AutocorrelationProcessor(const size_t &windowLength, const unsigned int &hopSize) : 19 AutocorrelationProcessor::AutocorrelationProcessor(int windowLength, int hopSize) :
20 m_windowLength(windowLength), 20 m_windowLength(windowLength),
21 m_hopSize(hopSize) 21 m_hopSize(hopSize)
22 { 22 {
23 23
24 } 24 }
26 AutocorrelationProcessor::~AutocorrelationProcessor() 26 AutocorrelationProcessor::~AutocorrelationProcessor()
27 { 27 {
28 28
29 } 29 }
30 30
31 AutoCorrelation AutocorrelationProcessor::process(float * input, const size_t &inputLength) const 31 AutoCorrelation AutocorrelationProcessor::process(float * input, int inputLength) const
32 { 32 {
33 int readBlockPointerIndex = 0; 33 int readBlockPointerIndex = 0;
34 AutoCorrelation autocorrelation; 34 AutoCorrelation autocorrelation;
35 35
36 while(readBlockPointerIndex <= (int)inputLength) { 36 while(readBlockPointerIndex <= inputLength) {
37 37
38 vector<float> autocorrelationBlock; 38 vector<float> autocorrelationBlock;
39 39
40 for (int lag = 0; lag < (int)m_windowLength; lag++){ 40 for (int lag = 0; lag < m_windowLength; lag++){
41 float sum = 0; 41 float sum = 0;
42 int readPointer = readBlockPointerIndex - m_windowLength/2; 42 int readPointer = readBlockPointerIndex - m_windowLength/2;
43 43
44 for (int n = 0; n < (int)m_windowLength; n++){ 44 for (int n = 0; n < (int)m_windowLength; n++){
45 if (readPointer+lag >= (int)inputLength) break; 45 if (readPointer+lag >= inputLength) break;
46 else if (readPointer >= 0) sum += input[readPointer]*input[readPointer+lag]; 46 else if (readPointer >= 0) {
47 //else cout << readPointer << " : "<< lag << "/" << m_windowLength << endl; 47 sum += input[readPointer]*input[readPointer+lag];
48 48 }
49 readPointer++; 49 readPointer++;
50 } 50 }
51 autocorrelationBlock.push_back(sum/(2*m_windowLength + 1 - lag)); 51 autocorrelationBlock.push_back(sum/(2*m_windowLength + 1 - lag));
52 } 52 }
53 53
54 //autocorrelation.push_back(processBlock());
55 autocorrelation.push_back(autocorrelationBlock); 54 autocorrelation.push_back(autocorrelationBlock);
56 readBlockPointerIndex += m_hopSize; 55 readBlockPointerIndex += m_hopSize;
57 } 56 }
58 57
59 return autocorrelation; 58 return autocorrelation;