annotate maths/MathUtilities.h @ 73:dcb555b90924

* Key detector: when returning key strengths, use the peak value of the three underlying chromagram correlations (from 36-bin chromagram) corresponding to each key, instead of the mean. Rationale: This is the same method as used when returning the key value, and it's nice to have the same results in both returned value and plot. The peak performed better than the sum with a simple test set of triads, so it seems reasonable to change the plot to match the key output rather than the other way around. * FFT: kiss_fftr returns only the non-conjugate bins, synthesise the rest rather than leaving them (perhaps dangerously) undefined. Fixes an uninitialised data error in chromagram that could cause garbage results from key detector. * Constant Q: remove precalculated values again, I reckon they're not proving such a good tradeoff.
author cannam
date Fri, 05 Jun 2009 15:12:39 +0000
parents 7fe29d8a7eaf
children 054c384d860d
rev   line source
cannam@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@0 2
cannam@0 3 /*
cannam@0 4 QM DSP Library
cannam@0 5
cannam@0 6 Centre for Digital Music, Queen Mary, University of London.
cannam@0 7 This file copyright 2005-2006 Christian Landone.
cannam@0 8 All rights reserved.
cannam@0 9 */
cannam@0 10
cannam@0 11 #ifndef MATHUTILITIES_H
cannam@0 12 #define MATHUTILITIES_H
cannam@0 13
cannam@0 14 #include <vector>
cannam@0 15
cannam@0 16 class MathUtilities
cannam@0 17 {
cannam@0 18 public:
cannam@0 19 static double round( double x );
cannam@34 20
cannam@0 21 static void getFrameMinMax( const double* data, unsigned int len, double* min, double* max );
cannam@34 22
cannam@0 23 static double mean( const double* src, unsigned int len );
cannam@54 24 static double mean( const std::vector<double> &data,
cannam@54 25 unsigned int start, unsigned int count );
cannam@0 26 static double sum( const double* src, unsigned int len );
cannam@34 27 static double median( const double* src, unsigned int len );
cannam@34 28
cannam@0 29 static double princarg( double ang );
cannam@0 30 static double mod( double x, double y);
cannam@34 31
cannam@0 32 static void getAlphaNorm(const double *data, unsigned int len, unsigned int alpha, double* ANorm);
cannam@0 33 static double getAlphaNorm(const std::vector <double> &data, unsigned int alpha );
cannam@34 34
cannam@7 35 static void circShift( double* data, int length, int shift);
cannam@34 36
cannam@54 37 static int getMax( double* data, unsigned int length, double* max = 0 );
cannam@54 38 static int getMax( const std::vector<double> &data, double* max = 0 );
cannam@7 39 static int compareInt(const void * a, const void * b);
cannam@34 40
cannam@34 41 enum NormaliseType {
cannam@34 42 NormaliseNone,
cannam@34 43 NormaliseUnitSum,
cannam@34 44 NormaliseUnitMax
cannam@34 45 };
cannam@34 46
cannam@34 47 static void normalise(double *data, int length,
cannam@34 48 NormaliseType n = NormaliseUnitMax);
cannam@34 49
cannam@34 50 static void normalise(std::vector<double> &data,
cannam@34 51 NormaliseType n = NormaliseUnitMax);
cannam@54 52
cannam@54 53 // moving mean threshholding:
cannam@54 54 static void adaptiveThreshold(std::vector<double> &data);
cannam@55 55
cannam@55 56 static bool isPowerOfTwo(int x);
cannam@55 57 static int nextPowerOfTwo(int x); // e.g. 1300 -> 2048, 2048 -> 2048
cannam@55 58 static int previousPowerOfTwo(int x); // e.g. 1300 -> 1024, 2048 -> 2048
cannam@55 59 static int nearestPowerOfTwo(int x); // e.g. 1300 -> 1024, 1700 -> 2048
cannam@0 60 };
cannam@0 61
cannam@0 62 #endif