Mercurial > hg > qm-dsp
changeset 227:f06672e8db10
* Make it possible to provide the detection function with frequency domain
inputs (i.e. phase vocoder already run)
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Mon, 15 May 2006 11:21:47 +0000 |
parents | 55576b901c06 |
children | b7f01ab7045e |
files | dsp/onsets/DetectionFunction.cpp dsp/onsets/DetectionFunction.h |
diffstat | 2 files changed, 47 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/dsp/onsets/DetectionFunction.cpp Thu Apr 06 12:02:03 2006 +0000 +++ b/dsp/onsets/DetectionFunction.cpp Mon May 15 11:21:47 2006 +0000 @@ -17,10 +17,9 @@ DetectionFunction::DetectionFunction( DFConfig Config ) : m_window(0) { - magHistory = NULL; - phaseHistory = NULL; - phaseHistoryOld = NULL; - j = ComplexData( 0, 1 ); + m_magHistory = NULL; + m_phaseHistory = NULL; + m_phaseHistoryOld = NULL; initialise( Config ); } @@ -37,14 +36,14 @@ m_halfLength = m_dataLength/2; m_DFType = Config.DFType; - magHistory = new double[ m_halfLength ]; - memset(magHistory,0, m_halfLength*sizeof(double)); + m_magHistory = new double[ m_halfLength ]; + memset(m_magHistory,0, m_halfLength*sizeof(double)); - phaseHistory = new double[ m_halfLength ]; - memset(phaseHistory,0, m_halfLength*sizeof(double)); + m_phaseHistory = new double[ m_halfLength ]; + memset(m_phaseHistory,0, m_halfLength*sizeof(double)); - phaseHistoryOld = new double[ m_halfLength ]; - memset(phaseHistoryOld,0, m_halfLength*sizeof(double)); + m_phaseHistoryOld = new double[ m_halfLength ]; + memset(m_phaseHistoryOld,0, m_halfLength*sizeof(double)); m_phaseVoc = new PhaseVocoder; @@ -57,9 +56,9 @@ void DetectionFunction::deInitialise() { - delete [] magHistory ; - delete [] phaseHistory ; - delete [] phaseHistoryOld ; + delete [] m_magHistory ; + delete [] m_phaseHistory ; + delete [] m_phaseHistoryOld ; delete m_phaseVoc; @@ -72,12 +71,27 @@ double DetectionFunction::process( double *TDomain ) { - double retVal = 0; - m_window->cut( TDomain, m_DFWindowedFrame ); m_phaseVoc->process( m_dataLength, m_DFWindowedFrame, m_magnitude, m_thetaAngle ); + return runDF(); +} + +double DetectionFunction::process( double *magnitudes, double *phases ) +{ + for (size_t i = 0; i < m_halfLength; ++i) { + m_magnitude[i] = magnitudes[i]; + m_thetaAngle[i] = phases[i]; + } + + return runDF(); +} + +double DetectionFunction::runDF() +{ + double retVal = 0; + switch( m_DFType ) { case DF_HFC: @@ -121,7 +135,7 @@ for( i = 0; i < length; i++) { - temp = fabs( (src[ i ] * src[ i ]) - (magHistory[ i ] * magHistory[ i ]) ); + temp = fabs( (src[ i ] * src[ i ]) - (m_magHistory[ i ] * m_magHistory[ i ]) ); diff= sqrt(temp); @@ -130,7 +144,7 @@ val += diff; } - magHistory[ i ] = src[ i ]; + m_magHistory[ i ] = src[ i ]; } return val; @@ -148,7 +162,7 @@ for( i = 0; i < length; i++) { - tmpPhase = (srcPhase[ i ]- 2*phaseHistory[ i ]+phaseHistoryOld[ i ]); + tmpPhase = (srcPhase[ i ]- 2*m_phaseHistory[ i ]+m_phaseHistoryOld[ i ]); dev = MathUtilities::princarg( tmpPhase ); if( srcMagnitude[ i ] > 0.1) @@ -157,8 +171,8 @@ val += tmpVal ; } - phaseHistoryOld[ i ] = phaseHistory[ i ] ; - phaseHistory[ i ] = srcPhase[ i ]; + m_phaseHistoryOld[ i ] = m_phaseHistory[ i ] ; + m_phaseHistory[ i ] = srcPhase[ i ]; } @@ -176,22 +190,23 @@ double dev = 0; ComplexData meas = ComplexData( 0, 0 ); + ComplexData j = ComplexData( 0, 1 ); for( i = 0; i < length; i++) { - tmpPhase = (srcPhase[ i ]- 2*phaseHistory[ i ]+phaseHistoryOld[ i ]); + tmpPhase = (srcPhase[ i ]- 2*m_phaseHistory[ i ]+m_phaseHistoryOld[ i ]); dev= MathUtilities::princarg( tmpPhase ); - meas = magHistory[i] - ( srcMagnitude[ i ] * exp( j * dev) ); + meas = m_magHistory[i] - ( srcMagnitude[ i ] * exp( j * dev) ); tmpReal = real( meas ); tmpImag = imag( meas ); val += sqrt( (tmpReal * tmpReal) + (tmpImag * tmpImag) ); - phaseHistoryOld[ i ] = phaseHistory[ i ] ; - phaseHistory[ i ] = srcPhase[ i ]; - magHistory[ i ] = srcMagnitude[ i ]; + m_phaseHistoryOld[ i ] = m_phaseHistory[ i ] ; + m_phaseHistory[ i ] = srcPhase[ i ]; + m_magHistory[ i ] = srcMagnitude[ i ]; } return val;
--- a/dsp/onsets/DetectionFunction.h Thu Apr 06 12:02:03 2006 +0000 +++ b/dsp/onsets/DetectionFunction.h Mon May 15 11:21:47 2006 +0000 @@ -35,8 +35,11 @@ DetectionFunction( DFConfig Config ); virtual ~DetectionFunction(); double process( double* TDomain ); + double process( double* magnitudes, double* phases ); private: + double runDF(); + double HFC( unsigned int length, double* src); double specDiff( unsigned int length, double* src); double phaseDev(unsigned int length, double *srcMagnitude, double *srcPhase); @@ -50,23 +53,16 @@ unsigned int m_dataLength; unsigned int m_halfLength; - double* magHistory; - double* phaseHistory; - double* phaseHistoryOld; + double* m_magHistory; + double* m_phaseHistory; + double* m_phaseHistoryOld; double* m_DFWindowedFrame; // Array for windowed analysis frame double* m_magnitude; // Magnitude of analysis frame ( frequency domain ) double* m_thetaAngle;// Phase of analysis frame ( frequency domain ) - - vector < ComplexData > meas ; - - ComplexData j; - Window<double> *m_window; - - PhaseVocoder* m_phaseVoc; // Phase Vocoder - + PhaseVocoder* m_phaseVoc; // Phase Vocoder }; #endif