annotate dsp/onsets/DetectionFunction.h @ 55:7fe29d8a7eaf

* Various fixes related to the bar estimator code
author cannam
date Tue, 10 Feb 2009 16:37:11 +0000
parents 5bec06ecc88a
children e5907ae6de17
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 DETECTIONFUNCTION_H
cannam@0 12 #define DETECTIONFUNCTION_H
cannam@0 13
cannam@16 14 #include "maths/MathUtilities.h"
cannam@16 15 #include "maths/MathAliases.h"
cannam@0 16 #include "dsp/phasevocoder/PhaseVocoder.h"
cannam@0 17 #include "base/Window.h"
cannam@0 18
cannam@0 19 #define DF_HFC (1)
cannam@0 20 #define DF_SPECDIFF (2)
cannam@0 21 #define DF_PHASEDEV (3)
cannam@0 22 #define DF_COMPLEXSD (4)
cannam@12 23 #define DF_BROADBAND (5)
cannam@0 24
cannam@0 25 struct DFConfig{
cannam@0 26 unsigned int stepSize; // DF step in samples
cannam@0 27 unsigned int frameLength; // DF analysis window - usually 2*step
cannam@0 28 int DFType; // type of detection function ( see defines )
cannam@12 29 double dbRise; // only used for broadband df (and required for it)
cannam@14 30 bool adaptiveWhitening; // perform adaptive whitening
cannam@14 31 double whiteningRelaxCoeff; // if < 0, a sensible default will be used
cannam@14 32 double whiteningFloor; // if < 0, a sensible default will be used
cannam@0 33 };
cannam@0 34
cannam@0 35 class DetectionFunction
cannam@0 36 {
cannam@0 37 public:
cannam@0 38 double* getSpectrumMagnitude();
cannam@0 39 DetectionFunction( DFConfig Config );
cannam@0 40 virtual ~DetectionFunction();
cannam@55 41 double process( const double* TDomain );
cannam@55 42 double process( const double* magnitudes, const double* phases );
cannam@0 43
cannam@0 44 private:
cannam@14 45 void whiten();
cannam@2 46 double runDF();
cannam@2 47
cannam@0 48 double HFC( unsigned int length, double* src);
cannam@0 49 double specDiff( unsigned int length, double* src);
cannam@14 50 double phaseDev(unsigned int length, double *srcPhase);
cannam@0 51 double complexSD(unsigned int length, double *srcMagnitude, double *srcPhase);
cannam@14 52 double broadband(unsigned int length, double *srcMagnitude);
cannam@0 53
cannam@0 54 private:
cannam@0 55 void initialise( DFConfig Config );
cannam@0 56 void deInitialise();
cannam@0 57
cannam@0 58 int m_DFType;
cannam@0 59 unsigned int m_dataLength;
cannam@0 60 unsigned int m_halfLength;
cannam@13 61 unsigned int m_stepSize;
cannam@12 62 double m_dbRise;
cannam@14 63 bool m_whiten;
cannam@14 64 double m_whitenRelaxCoeff;
cannam@14 65 double m_whitenFloor;
cannam@0 66
cannam@2 67 double* m_magHistory;
cannam@2 68 double* m_phaseHistory;
cannam@2 69 double* m_phaseHistoryOld;
cannam@14 70 double* m_magPeaks;
cannam@0 71
cannam@0 72 double* m_DFWindowedFrame; // Array for windowed analysis frame
cannam@0 73 double* m_magnitude; // Magnitude of analysis frame ( frequency domain )
cannam@0 74 double* m_thetaAngle;// Phase of analysis frame ( frequency domain )
cannam@0 75
cannam@0 76 Window<double> *m_window;
cannam@2 77 PhaseVocoder* m_phaseVoc; // Phase Vocoder
cannam@0 78 };
cannam@0 79
cannam@0 80 #endif