c@225: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@225: c@225: /* c@225: QM DSP Library c@225: c@225: Centre for Digital Music, Queen Mary, University of London. c@309: This file 2005-2006 Christian Landone. c@309: c@309: This program is free software; you can redistribute it and/or c@309: modify it under the terms of the GNU General Public License as c@309: published by the Free Software Foundation; either version 2 of the c@309: License, or (at your option) any later version. See the file c@309: COPYING included with this distribution for more information. c@225: */ c@225: c@225: #ifndef DETECTIONFUNCTION_H c@225: #define DETECTIONFUNCTION_H c@225: c@241: #include "maths/MathUtilities.h" c@241: #include "maths/MathAliases.h" c@225: #include "dsp/phasevocoder/PhaseVocoder.h" c@225: #include "base/Window.h" c@225: c@225: #define DF_HFC (1) c@225: #define DF_SPECDIFF (2) c@225: #define DF_PHASEDEV (3) c@225: #define DF_COMPLEXSD (4) c@237: #define DF_BROADBAND (5) c@225: c@225: struct DFConfig{ c@225: unsigned int stepSize; // DF step in samples c@225: unsigned int frameLength; // DF analysis window - usually 2*step c@225: int DFType; // type of detection function ( see defines ) c@237: double dbRise; // only used for broadband df (and required for it) c@239: bool adaptiveWhitening; // perform adaptive whitening c@239: double whiteningRelaxCoeff; // if < 0, a sensible default will be used c@239: double whiteningFloor; // if < 0, a sensible default will be used c@225: }; c@225: c@225: class DetectionFunction c@225: { c@225: public: c@225: double* getSpectrumMagnitude(); c@225: DetectionFunction( DFConfig Config ); c@225: virtual ~DetectionFunction(); c@344: c@344: /** c@344: * Process a single time-domain frame of audio, provided as c@344: * frameLength samples. c@344: */ c@344: double processTimeDomain(const double* samples); c@344: c@344: /** c@344: * Process a single frequency-domain frame, provided as c@344: * frameLength/2+1 real and imaginary component values. c@344: */ c@344: double processFrequencyDomain(const double* reals, const double* imags); c@225: c@225: private: c@239: void whiten(); c@227: double runDF(); c@227: c@225: double HFC( unsigned int length, double* src); c@225: double specDiff( unsigned int length, double* src); c@239: double phaseDev(unsigned int length, double *srcPhase); c@225: double complexSD(unsigned int length, double *srcMagnitude, double *srcPhase); c@239: double broadband(unsigned int length, double *srcMagnitude); c@225: c@225: private: c@225: void initialise( DFConfig Config ); c@225: void deInitialise(); c@225: c@225: int m_DFType; c@225: unsigned int m_dataLength; c@225: unsigned int m_halfLength; c@238: unsigned int m_stepSize; c@237: double m_dbRise; c@239: bool m_whiten; c@239: double m_whitenRelaxCoeff; c@239: double m_whitenFloor; c@225: c@227: double* m_magHistory; c@227: double* m_phaseHistory; c@227: double* m_phaseHistoryOld; c@239: double* m_magPeaks; c@225: c@344: double* m_windowed; // Array for windowed analysis frame c@225: double* m_magnitude; // Magnitude of analysis frame ( frequency domain ) c@225: double* m_thetaAngle;// Phase of analysis frame ( frequency domain ) c@340: double* m_unwrapped; // Unwrapped phase of analysis frame c@225: c@225: Window *m_window; c@227: PhaseVocoder* m_phaseVoc; // Phase Vocoder c@225: }; c@225: c@225: #endif