comparison src/BTrack.cpp @ 47:9f45f9dbc6b5

Added a license file, fixed some small issues
author Adam Stark <adamstark@users.noreply.github.com>
date Tue, 21 Jan 2014 01:29:44 +0000
parents af7739411685
children 18fc3c248436 bb3803edaa17
comparison
equal deleted inserted replaced
46:af7739411685 47:9f45f9dbc6b5
1 //======================================================================= 1 //=======================================================================
2 /** @file BTrack.cpp 2 /** @file BTrack.cpp
3 * @brief Implementation file for the BTrack beat tracker 3 * @brief BTrack - a real-time beat tracker
4 * @author Adam Stark 4 * @author Adam Stark
5 * @copyright Copyright (C) 2008-2014 Queen Mary University of London 5 * @copyright Copyright (C) 2008-2014 Queen Mary University of London
6 * 6 *
7 * This program is free software: you can redistribute it and/or modify 7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
473 //------------------------------------------------------------------------------- 473 //-------------------------------------------------------------------------------
474 // calculates the mean of values in an array from index locations [start,end] 474 // calculates the mean of values in an array from index locations [start,end]
475 float BTrack :: mean_array(float array[],int start,int end) 475 float BTrack :: mean_array(float array[],int start,int end)
476 { 476 {
477 int i; 477 int i;
478 float sum = 0; 478 double sum = 0;
479 int length = end - start + 1; 479
480 int length = end - start;
480 481
481 // find sum 482 // find sum
482 for (i = start;i < end+1;i++) 483 for (i = start;i < end;i++)
483 { 484 {
484 sum = sum + array[i]; 485 sum = sum + array[i];
485 } 486 }
486 487
487 return sum / length; // average and return 488 if (length > 0)
489 {
490 return sum / length; // average and return
491 }
492 else
493 {
494 return 0;
495 }
488 } 496 }
489 497
490 //------------------------------------------------------------------------------- 498 //-------------------------------------------------------------------------------
491 // normalise the array 499 // normalise the array
492 void BTrack :: normalise(float array[],int N) 500 void BTrack :: normalise(float array[],int N)