annotate dsp/onsets/DetectionFunction.h @ 239:135f16b49065

* add adaptive whitening and simple power metric
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 09 Aug 2007 16:30:26 +0000
parents e8e5f9130b49
children 2e3f5d2d62c1
rev   line source
c@225 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@225 2
c@225 3 /*
c@225 4 QM DSP Library
c@225 5
c@225 6 Centre for Digital Music, Queen Mary, University of London.
c@225 7 This file copyright 2005-2006 Christian Landone.
c@225 8 All rights reserved.
c@225 9 */
c@225 10
c@225 11 #ifndef DETECTIONFUNCTION_H
c@225 12 #define DETECTIONFUNCTION_H
c@225 13
c@225 14 #include "dsp/maths/MathUtilities.h"
c@225 15 #include "dsp/maths/MathAliases.h"
c@225 16 #include "dsp/phasevocoder/PhaseVocoder.h"
c@225 17 #include "base/Window.h"
c@225 18
c@225 19 #define DF_HFC (1)
c@225 20 #define DF_SPECDIFF (2)
c@225 21 #define DF_PHASEDEV (3)
c@225 22 #define DF_COMPLEXSD (4)
c@237 23 #define DF_BROADBAND (5)
c@239 24 #define DF_POWER (6)
c@225 25
c@225 26 struct DFConfig{
c@225 27 double stepSecs; // DF step in seconds
c@225 28 unsigned int stepSize; // DF step in samples
c@225 29 unsigned int frameLength; // DF analysis window - usually 2*step
c@225 30 int DFType; // type of detection function ( see defines )
c@237 31 double dbRise; // only used for broadband df (and required for it)
c@239 32 bool adaptiveWhitening; // perform adaptive whitening
c@239 33 double whiteningRelaxCoeff; // if < 0, a sensible default will be used
c@239 34 double whiteningFloor; // if < 0, a sensible default will be used
c@225 35 };
c@225 36
c@225 37 class DetectionFunction
c@225 38 {
c@225 39 public:
c@225 40 double* getSpectrumMagnitude();
c@225 41 DetectionFunction( DFConfig Config );
c@225 42 virtual ~DetectionFunction();
c@225 43 double process( double* TDomain );
c@227 44 double process( double* magnitudes, double* phases );
c@225 45
c@225 46 private:
c@239 47 void whiten();
c@227 48 double runDF();
c@227 49
c@225 50 double HFC( unsigned int length, double* src);
c@225 51 double specDiff( unsigned int length, double* src);
c@239 52 double phaseDev(unsigned int length, double *srcPhase);
c@225 53 double complexSD(unsigned int length, double *srcMagnitude, double *srcPhase);
c@239 54 double broadband(unsigned int length, double *srcMagnitude);
c@239 55 double power(unsigned int length, double *src);
c@225 56
c@225 57 private:
c@225 58 void initialise( DFConfig Config );
c@225 59 void deInitialise();
c@225 60
c@225 61 int m_DFType;
c@225 62 unsigned int m_dataLength;
c@225 63 unsigned int m_halfLength;
c@238 64 double m_stepSecs;
c@238 65 unsigned int m_stepSize;
c@237 66 double m_dbRise;
c@239 67 bool m_whiten;
c@239 68 double m_whitenRelaxCoeff;
c@239 69 double m_whitenFloor;
c@225 70
c@227 71 double* m_magHistory;
c@227 72 double* m_phaseHistory;
c@227 73 double* m_phaseHistoryOld;
c@239 74 double* m_magPeaks;
c@225 75
c@225 76 double* m_DFWindowedFrame; // Array for windowed analysis frame
c@225 77 double* m_magnitude; // Magnitude of analysis frame ( frequency domain )
c@225 78 double* m_thetaAngle;// Phase of analysis frame ( frequency domain )
c@225 79
c@225 80 Window<double> *m_window;
c@227 81 PhaseVocoder* m_phaseVoc; // Phase Vocoder
c@225 82 };
c@225 83
c@225 84 #endif