annotate dsp/onsets/DetectionFunction.h @ 12:da277e8b5244

* Some fixes to peak picker * Add broadband energy rise detection function (same as the percussive onset detector in the Vamp example plugins)
author cannam
date Fri, 18 May 2007 16:43:17 +0000
parents c539af5259da
children f2b5c4251bf3
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@0 14 #include "dsp/maths/MathUtilities.h"
cannam@0 15 #include "dsp/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 double stepSecs; // DF step in seconds
cannam@0 27 unsigned int stepSize; // DF step in samples
cannam@0 28 unsigned int frameLength; // DF analysis window - usually 2*step
cannam@0 29 int DFType; // type of detection function ( see defines )
cannam@12 30 double dbRise; // only used for broadband df (and required for it)
cannam@0 31 };
cannam@0 32
cannam@0 33 class DetectionFunction
cannam@0 34 {
cannam@0 35 public:
cannam@0 36 double* getSpectrumMagnitude();
cannam@0 37 DetectionFunction( DFConfig Config );
cannam@0 38 virtual ~DetectionFunction();
cannam@0 39 double process( double* TDomain );
cannam@2 40 double process( double* magnitudes, double* phases );
cannam@0 41
cannam@0 42 private:
cannam@2 43 double runDF();
cannam@2 44
cannam@0 45 double HFC( unsigned int length, double* src);
cannam@0 46 double specDiff( unsigned int length, double* src);
cannam@0 47 double phaseDev(unsigned int length, double *srcMagnitude, double *srcPhase);
cannam@0 48 double complexSD(unsigned int length, double *srcMagnitude, double *srcPhase);
cannam@12 49 double broadband(unsigned int length, double *srcMagnitude, double *srcPhase);
cannam@0 50
cannam@0 51 private:
cannam@0 52 void initialise( DFConfig Config );
cannam@0 53 void deInitialise();
cannam@0 54
cannam@0 55 int m_DFType;
cannam@0 56 unsigned int m_dataLength;
cannam@0 57 unsigned int m_halfLength;
cannam@12 58 double m_dbRise;
cannam@0 59
cannam@2 60 double* m_magHistory;
cannam@2 61 double* m_phaseHistory;
cannam@2 62 double* m_phaseHistoryOld;
cannam@0 63
cannam@0 64 double* m_DFWindowedFrame; // Array for windowed analysis frame
cannam@0 65 double* m_magnitude; // Magnitude of analysis frame ( frequency domain )
cannam@0 66 double* m_thetaAngle;// Phase of analysis frame ( frequency domain )
cannam@0 67
cannam@0 68 Window<double> *m_window;
cannam@2 69 PhaseVocoder* m_phaseVoc; // Phase Vocoder
cannam@0 70 };
cannam@0 71
cannam@0 72 #endif