Chris@43: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@43: Chris@43: /* Chris@43: Vamp Tempogram Plugin Chris@43: Carl Bussey, Centre for Digital Music, Queen Mary University of London Chris@43: Copyright 2014 Queen Mary University of London. Chris@43: Chris@43: This program is free software; you can redistribute it and/or Chris@43: modify it under the terms of the GNU General Public License as Chris@43: published by the Free Software Foundation; either version 2 of the Chris@43: License, or (at your option) any later version. See the file Chris@43: COPYING included with this distribution for more information. Chris@43: */ 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: }