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: Chris@44: AutocorrelationProcessor::AutocorrelationProcessor(int windowLength, 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: Chris@44: AutoCorrelation AutocorrelationProcessor::process(float * input, int inputLength) const c@25: { c@25: int readBlockPointerIndex = 0; c@25: AutoCorrelation autocorrelation; c@25: Chris@44: while(readBlockPointerIndex <= inputLength) { c@25: c@28: vector autocorrelationBlock; c@28: Chris@44: for (int lag = 0; lag < 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++){ Chris@44: if (readPointer+lag >= inputLength) break; Chris@44: else if (readPointer >= 0) { Chris@44: sum += input[readPointer]*input[readPointer+lag]; Chris@44: } 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(autocorrelationBlock); c@25: readBlockPointerIndex += m_hopSize; c@25: } c@25: c@25: return autocorrelation; c@25: }