annotate dsp/onsets/DetectionFunction.h @ 120:b0e98fcfacd7 pvoc

Comments
author Chris Cannam
date Thu, 03 Oct 2013 13:03:31 +0100
parents 2020c73dc997
children 2053a308bb4d
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();
Chris@119 46
Chris@119 47 /**
Chris@119 48 * Process a single time-domain frame of audio, provided as
Chris@119 49 * frameLength samples.
Chris@119 50 */
Chris@119 51 double processTimeDomain(const double* samples);
Chris@119 52
Chris@119 53 /**
Chris@119 54 * Process a single frequency-domain frame, provided as
Chris@119 55 * frameLength/2+1 real and imaginary component values.
Chris@119 56 */
Chris@119 57 double processFrequencyDomain(const double* reals, const double* imags);
cannam@0 58
cannam@0 59 private:
cannam@14 60 void whiten();
cannam@2 61 double runDF();
cannam@2 62
cannam@0 63 double HFC( unsigned int length, double* src);
cannam@0 64 double specDiff( unsigned int length, double* src);
cannam@14 65 double phaseDev(unsigned int length, double *srcPhase);
cannam@0 66 double complexSD(unsigned int length, double *srcMagnitude, double *srcPhase);
cannam@14 67 double broadband(unsigned int length, double *srcMagnitude);
cannam@0 68
cannam@0 69 private:
cannam@0 70 void initialise( DFConfig Config );
cannam@0 71 void deInitialise();
cannam@0 72
cannam@0 73 int m_DFType;
cannam@0 74 unsigned int m_dataLength;
cannam@0 75 unsigned int m_halfLength;
cannam@13 76 unsigned int m_stepSize;
cannam@12 77 double m_dbRise;
cannam@14 78 bool m_whiten;
cannam@14 79 double m_whitenRelaxCoeff;
cannam@14 80 double m_whitenFloor;
cannam@0 81
cannam@2 82 double* m_magHistory;
cannam@2 83 double* m_phaseHistory;
cannam@2 84 double* m_phaseHistoryOld;
cannam@14 85 double* m_magPeaks;
cannam@0 86
Chris@119 87 double* m_windowed; // Array for windowed analysis frame
cannam@0 88 double* m_magnitude; // Magnitude of analysis frame ( frequency domain )
cannam@0 89 double* m_thetaAngle;// Phase of analysis frame ( frequency domain )
Chris@115 90 double* m_unwrapped; // Unwrapped phase of analysis frame
cannam@0 91
cannam@0 92 Window<double> *m_window;
cannam@2 93 PhaseVocoder* m_phaseVoc; // Phase Vocoder
cannam@0 94 };
cannam@0 95
cannam@0 96 #endif