annotate AutocorrelationProcessor.cpp @ 28:723af5b3303a

* Fixed tempogram via ACT bin names etc
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Thu, 21 Aug 2014 11:07:20 +0100
parents a3a37c8dcee7
children 1ad47a9afc2e
rev   line source
c@25 1 //
c@25 2 // AutocorrelationProcessor.cpp
c@25 3 // Tempogram
c@25 4 //
c@25 5 // Created by Carl Bussey on 20/08/2014.
c@25 6 // Copyright (c) 2014 Carl Bussey. All rights reserved.
c@25 7 //
c@25 8
c@25 9 #include "AutocorrelationProcessor.h"
c@25 10 using namespace std;
c@28 11 #include <iostream>
c@25 12
c@26 13 AutocorrelationProcessor::AutocorrelationProcessor(const size_t &windowLength, const unsigned int &hopSize) :
c@25 14 m_windowLength(windowLength),
c@28 15 m_hopSize(hopSize)
c@25 16 {
c@28 17
c@26 18 }
c@26 19
c@26 20 AutocorrelationProcessor::~AutocorrelationProcessor(){
c@28 21
c@25 22 }
c@25 23
c@25 24 AutoCorrelation AutocorrelationProcessor::process(float * input, const size_t &inputLength) const
c@25 25 {
c@25 26 int readBlockPointerIndex = 0;
c@25 27 AutoCorrelation autocorrelation;
c@25 28
c@25 29 while(readBlockPointerIndex <= (int)inputLength) {
c@25 30
c@28 31 vector<float> autocorrelationBlock;
c@28 32
c@28 33 for (int lag = 0; lag < (int)m_windowLength; lag++){
c@28 34 float sum = 0;
c@28 35 int readPointer = readBlockPointerIndex - m_windowLength/2;
c@26 36
c@28 37 for (int n = 0; n < (int)m_windowLength; n++){
c@28 38 if (readPointer+lag >= (int)inputLength) break;
c@28 39 else if (readPointer >= 0) sum += input[readPointer]*input[readPointer+lag];
c@28 40 //else cout << readPointer << " : "<< lag << "/" << m_windowLength << endl;
c@28 41
c@28 42 readPointer++;
c@28 43 }
c@28 44 autocorrelationBlock.push_back(sum/(2*m_windowLength + 1 - lag));
c@26 45 }
c@26 46
c@28 47 //autocorrelation.push_back(processBlock());
c@28 48 autocorrelation.push_back(autocorrelationBlock);
c@25 49 readBlockPointerIndex += m_hopSize;
c@25 50 }
c@25 51
c@25 52 return autocorrelation;
c@25 53 }