annotate AutocorrelationProcessor.cpp @ 43:4cf2d163127b

Copyrights and tidying
author Chris Cannam
date Thu, 25 Sep 2014 15:13:45 +0100
parents 1ad47a9afc2e
children a908a5a56267
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
c@26 19 AutocorrelationProcessor::AutocorrelationProcessor(const size_t &windowLength, const unsigned 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
c@25 31 AutoCorrelation AutocorrelationProcessor::process(float * input, const size_t &inputLength) const
c@25 32 {
c@25 33 int readBlockPointerIndex = 0;
c@25 34 AutoCorrelation autocorrelation;
c@25 35
c@25 36 while(readBlockPointerIndex <= (int)inputLength) {
c@25 37
c@28 38 vector<float> autocorrelationBlock;
c@28 39
c@28 40 for (int lag = 0; lag < (int)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++){
c@28 45 if (readPointer+lag >= (int)inputLength) break;
c@28 46 else if (readPointer >= 0) sum += input[readPointer]*input[readPointer+lag];
c@28 47 //else cout << readPointer << " : "<< lag << "/" << m_windowLength << endl;
c@28 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(processBlock());
c@28 55 autocorrelation.push_back(autocorrelationBlock);
c@25 56 readBlockPointerIndex += m_hopSize;
c@25 57 }
c@25 58
c@25 59 return autocorrelation;
c@25 60 }