annotate dsp/onsets/DetectionFunction.h @ 115:f3c69325cca2 pvoc

Do actual phase unwrapping in the phase vocoder!
author Chris Cannam
date Wed, 02 Oct 2013 15:05:34 +0100
parents e5907ae6de17
children 2020c73dc997
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.
Chris@84 7 This file 2005-2006 Christian Landone.
Chris@84 8
Chris@84 9 This program is free software; you can redistribute it and/or
Chris@84 10 modify it under the terms of the GNU General Public License as
Chris@84 11 published by the Free Software Foundation; either version 2 of the
Chris@84 12 License, or (at your option) any later version. See the file
Chris@84 13 COPYING included with this distribution for more information.
cannam@0 14 */
cannam@0 15
cannam@0 16 #ifndef DETECTIONFUNCTION_H
cannam@0 17 #define DETECTIONFUNCTION_H
cannam@0 18
cannam@16 19 #include "maths/MathUtilities.h"
cannam@16 20 #include "maths/MathAliases.h"
cannam@0 21 #include "dsp/phasevocoder/PhaseVocoder.h"
cannam@0 22 #include "base/Window.h"
cannam@0 23
cannam@0 24 #define DF_HFC (1)
cannam@0 25 #define DF_SPECDIFF (2)
cannam@0 26 #define DF_PHASEDEV (3)
cannam@0 27 #define DF_COMPLEXSD (4)
cannam@12 28 #define DF_BROADBAND (5)
cannam@0 29
cannam@0 30 struct DFConfig{
cannam@0 31 unsigned int stepSize; // DF step in samples
cannam@0 32 unsigned int frameLength; // DF analysis window - usually 2*step
cannam@0 33 int DFType; // type of detection function ( see defines )
cannam@12 34 double dbRise; // only used for broadband df (and required for it)
cannam@14 35 bool adaptiveWhitening; // perform adaptive whitening
cannam@14 36 double whiteningRelaxCoeff; // if < 0, a sensible default will be used
cannam@14 37 double whiteningFloor; // if < 0, a sensible default will be used
cannam@0 38 };
cannam@0 39
cannam@0 40 class DetectionFunction
cannam@0 41 {
cannam@0 42 public:
cannam@0 43 double* getSpectrumMagnitude();
cannam@0 44 DetectionFunction( DFConfig Config );
cannam@0 45 virtual ~DetectionFunction();
cannam@55 46 double process( const double* TDomain );
cannam@55 47 double process( const double* magnitudes, const double* phases );
cannam@0 48
cannam@0 49 private:
cannam@14 50 void whiten();
cannam@2 51 double runDF();
cannam@2 52
cannam@0 53 double HFC( unsigned int length, double* src);
cannam@0 54 double specDiff( unsigned int length, double* src);
cannam@14 55 double phaseDev(unsigned int length, double *srcPhase);
cannam@0 56 double complexSD(unsigned int length, double *srcMagnitude, double *srcPhase);
cannam@14 57 double broadband(unsigned int length, double *srcMagnitude);
cannam@0 58
cannam@0 59 private:
cannam@0 60 void initialise( DFConfig Config );
cannam@0 61 void deInitialise();
cannam@0 62
cannam@0 63 int m_DFType;
cannam@0 64 unsigned int m_dataLength;
cannam@0 65 unsigned int m_halfLength;
cannam@13 66 unsigned int m_stepSize;
cannam@12 67 double m_dbRise;
cannam@14 68 bool m_whiten;
cannam@14 69 double m_whitenRelaxCoeff;
cannam@14 70 double m_whitenFloor;
cannam@0 71
cannam@2 72 double* m_magHistory;
cannam@2 73 double* m_phaseHistory;
cannam@2 74 double* m_phaseHistoryOld;
cannam@14 75 double* m_magPeaks;
cannam@0 76
cannam@0 77 double* m_DFWindowedFrame; // Array for windowed analysis frame
cannam@0 78 double* m_magnitude; // Magnitude of analysis frame ( frequency domain )
cannam@0 79 double* m_thetaAngle;// Phase of analysis frame ( frequency domain )
Chris@115 80 double* m_unwrapped; // Unwrapped phase of analysis frame
cannam@0 81
cannam@0 82 Window<double> *m_window;
cannam@2 83 PhaseVocoder* m_phaseVoc; // Phase Vocoder
cannam@0 84 };
cannam@0 85
cannam@0 86 #endif