c@25: // c@25: // AutocorrelationProcessor.cpp c@25: // Tempogram c@25: // c@25: // Created by Carl Bussey on 20/08/2014. c@25: // Copyright (c) 2014 Carl Bussey. All rights reserved. c@25: // c@25: c@25: #include "AutocorrelationProcessor.h" c@25: using namespace std; c@28: #include c@25: c@26: AutocorrelationProcessor::AutocorrelationProcessor(const size_t &windowLength, const unsigned int &hopSize) : c@25: m_windowLength(windowLength), c@28: m_hopSize(hopSize) c@25: { c@28: c@26: } c@26: c@29: AutocorrelationProcessor::~AutocorrelationProcessor() c@29: { c@28: c@25: } c@25: c@25: AutoCorrelation AutocorrelationProcessor::process(float * input, const size_t &inputLength) const c@25: { c@25: int readBlockPointerIndex = 0; c@25: AutoCorrelation autocorrelation; c@25: c@25: while(readBlockPointerIndex <= (int)inputLength) { c@25: c@28: vector autocorrelationBlock; c@28: c@28: for (int lag = 0; lag < (int)m_windowLength; lag++){ c@28: float sum = 0; c@28: int readPointer = readBlockPointerIndex - m_windowLength/2; c@26: c@28: for (int n = 0; n < (int)m_windowLength; n++){ c@28: if (readPointer+lag >= (int)inputLength) break; c@28: else if (readPointer >= 0) sum += input[readPointer]*input[readPointer+lag]; c@28: //else cout << readPointer << " : "<< lag << "/" << m_windowLength << endl; c@28: c@28: readPointer++; c@28: } c@28: autocorrelationBlock.push_back(sum/(2*m_windowLength + 1 - lag)); c@26: } c@26: c@28: //autocorrelation.push_back(processBlock()); c@28: autocorrelation.push_back(autocorrelationBlock); c@25: readBlockPointerIndex += m_hopSize; c@25: } c@25: c@25: return autocorrelation; c@25: }