qm-dsp  1.8
DetectionFunction.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     QM DSP Library
00005 
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file 2005-2006 Christian Landone.
00008 
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef DETECTIONFUNCTION_H
00017 #define DETECTIONFUNCTION_H
00018 
00019 #include "maths/MathUtilities.h"
00020 #include "maths/MathAliases.h"
00021 #include "dsp/phasevocoder/PhaseVocoder.h"
00022 #include "base/Window.h"
00023 
00024 #define DF_HFC (1)
00025 #define DF_SPECDIFF (2)
00026 #define DF_PHASEDEV (3)
00027 #define DF_COMPLEXSD (4)
00028 #define DF_BROADBAND (5)
00029 
00030 struct DFConfig{
00031     unsigned int stepSize; // DF step in samples
00032     unsigned int frameLength; // DF analysis window - usually 2*step. Must be even!
00033     int DFType; // type of detection function ( see defines )
00034     double dbRise; // only used for broadband df (and required for it)
00035     bool adaptiveWhitening; // perform adaptive whitening
00036     double whiteningRelaxCoeff; // if < 0, a sensible default will be used
00037     double whiteningFloor; // if < 0, a sensible default will be used
00038 };
00039 
00040 class DetectionFunction  
00041 {
00042 public:
00043     double* getSpectrumMagnitude();
00044     DetectionFunction( DFConfig Config );
00045     virtual ~DetectionFunction();
00046 
00051     double processTimeDomain(const double* samples);
00052 
00057     double processFrequencyDomain(const double* reals, const double* imags);
00058 
00059 private:
00060     void whiten();
00061     double runDF();
00062 
00063     double HFC( unsigned int length, double* src);
00064     double specDiff( unsigned int length, double* src);
00065     double phaseDev(unsigned int length, double *srcPhase);
00066     double complexSD(unsigned int length, double *srcMagnitude, double *srcPhase);
00067     double broadband(unsigned int length, double *srcMagnitude);
00068         
00069 private:
00070     void initialise( DFConfig Config );
00071     void deInitialise();
00072 
00073     int m_DFType;
00074     unsigned int m_dataLength;
00075     unsigned int m_halfLength;
00076     unsigned int m_stepSize;
00077     double m_dbRise;
00078     bool m_whiten;
00079     double m_whitenRelaxCoeff;
00080     double m_whitenFloor;
00081 
00082     double* m_magHistory;
00083     double* m_phaseHistory;
00084     double* m_phaseHistoryOld;
00085     double* m_magPeaks;
00086 
00087     double* m_windowed; // Array for windowed analysis frame
00088     double* m_magnitude; // Magnitude of analysis frame ( frequency domain )
00089     double* m_thetaAngle;// Phase of analysis frame ( frequency domain )
00090     double* m_unwrapped; // Unwrapped phase of analysis frame
00091 
00092     Window<double> *m_window;
00093     PhaseVocoder* m_phaseVoc;   // Phase Vocoder
00094 };
00095 
00096 #endif