annotate AutocorrelationProcessor.cpp @ 55:7a29d9ecd7d6

Added tag v1.0 for changeset 180624d62a4c
author Chris Cannam
date Thu, 16 Oct 2014 14:22:15 +0100
parents a908a5a56267
children
rev   line source
Chris@43 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@43 2
Chris@43 3 /*
Chris@43 4 Vamp Tempogram Plugin
Chris@43 5 Carl Bussey, Centre for Digital Music, Queen Mary University of London
Chris@43 6 Copyright 2014 Queen Mary University of London.
Chris@43 7
Chris@43 8 This program is free software; you can redistribute it and/or
Chris@43 9 modify it under the terms of the GNU General Public License as
Chris@43 10 published by the Free Software Foundation; either version 2 of the
Chris@43 11 License, or (at your option) any later version. See the file
Chris@43 12 COPYING included with this distribution for more information.
Chris@43 13 */
c@25 14
c@25 15 #include "AutocorrelationProcessor.h"
c@25 16 using namespace std;
c@28 17 #include <iostream>
c@25 18
Chris@44 19 AutocorrelationProcessor::AutocorrelationProcessor(int windowLength, int hopSize) :
c@25 20 m_windowLength(windowLength),
c@28 21 m_hopSize(hopSize)
c@25 22 {
c@28 23
c@26 24 }
c@26 25
c@29 26 AutocorrelationProcessor::~AutocorrelationProcessor()
c@29 27 {
c@28 28
c@25 29 }
c@25 30
Chris@44 31 AutoCorrelation AutocorrelationProcessor::process(float * input, int inputLength) const
c@25 32 {
c@25 33 int readBlockPointerIndex = 0;
c@25 34 AutoCorrelation autocorrelation;
c@25 35
Chris@44 36 while(readBlockPointerIndex <= inputLength) {
c@25 37
c@28 38 vector<float> autocorrelationBlock;
c@28 39
Chris@44 40 for (int lag = 0; lag < m_windowLength; lag++){
c@28 41 float sum = 0;
c@28 42 int readPointer = readBlockPointerIndex - m_windowLength/2;
c@26 43
c@28 44 for (int n = 0; n < (int)m_windowLength; n++){
Chris@44 45 if (readPointer+lag >= inputLength) break;
Chris@44 46 else if (readPointer >= 0) {
Chris@44 47 sum += input[readPointer]*input[readPointer+lag];
Chris@44 48 }
c@28 49 readPointer++;
c@28 50 }
c@28 51 autocorrelationBlock.push_back(sum/(2*m_windowLength + 1 - lag));
c@26 52 }
c@26 53
c@28 54 autocorrelation.push_back(autocorrelationBlock);
c@25 55 readBlockPointerIndex += m_hopSize;
c@25 56 }
c@25 57
c@25 58 return autocorrelation;
c@25 59 }