c@264: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@264: c@264: /* c@264: QM DSP Library c@264: c@264: Centre for Digital Music, Queen Mary, University of London. c@264: This file copyright 2005-2006 Christian Landone. c@264: All rights reserved. c@264: */ c@264: c@264: #include "TempoTrack.h" c@264: c@264: #include "maths/MathAliases.h" c@264: #include "maths/MathUtilities.h" c@264: c@264: #include c@264: c@264: c@264: #define RAY43VAL c@264: c@264: ////////////////////////////////////////////////////////////////////// c@264: // Construction/Destruction c@264: ////////////////////////////////////////////////////////////////////// c@264: c@264: TempoTrack::TempoTrack( TTParams Params ) c@264: { c@264: m_tempoScratch = NULL; c@264: m_rawDFFrame = NULL; c@264: m_smoothDFFrame = NULL; c@264: m_frameACF = NULL; c@264: m_smoothRCF = NULL; c@264: c@264: m_dataLength = 0; c@264: m_winLength = 0; c@264: m_lagLength = 0; c@264: c@264: m_rayparam = 0; c@264: m_sigma = 0; c@264: m_DFWVNnorm = 0; c@264: c@264: initialise( Params ); c@264: } c@264: c@264: TempoTrack::~TempoTrack() c@264: { c@264: deInitialise(); c@264: } c@264: c@264: void TempoTrack::initialise( TTParams Params ) c@264: { c@264: m_winLength = Params.winLength; c@264: m_lagLength = Params.lagLength; c@264: c@264: m_rayparam = 43.0; c@264: m_sigma = sqrt(3.9017); c@264: m_DFWVNnorm = exp( ( log( 2.0 ) / m_rayparam ) * ( m_winLength + 2 ) ); c@264: c@264: m_rawDFFrame = new double[ m_winLength ]; c@264: m_smoothDFFrame = new double[ m_winLength ]; c@264: m_frameACF = new double[ m_winLength ]; c@264: m_tempoScratch = new double[ m_lagLength ]; c@264: m_smoothRCF = new double[ m_lagLength ]; c@264: c@264: c@264: unsigned int winPre = Params.WinT.pre; c@264: unsigned int winPost = Params.WinT.post; c@264: c@264: m_DFFramer.configure( m_winLength, m_lagLength ); c@264: c@264: m_DFPParams.length = m_winLength; c@264: m_DFPParams.AlphaNormParam = Params.alpha; c@264: m_DFPParams.LPOrd = Params.LPOrd; c@264: m_DFPParams.LPACoeffs = Params.LPACoeffs; c@264: m_DFPParams.LPBCoeffs = Params.LPBCoeffs; c@264: m_DFPParams.winPre = Params.WinT.pre; c@264: m_DFPParams.winPost = Params.WinT.post; c@264: m_DFPParams.isMedianPositive = true; c@264: c@264: m_DFConditioning = new DFProcess( m_DFPParams ); c@264: c@264: c@264: // these are parameters for smoothing m_tempoScratch c@264: m_RCFPParams.length = m_lagLength; c@264: m_RCFPParams.AlphaNormParam = Params.alpha; c@264: m_RCFPParams.LPOrd = Params.LPOrd; c@264: m_RCFPParams.LPACoeffs = Params.LPACoeffs; c@264: m_RCFPParams.LPBCoeffs = Params.LPBCoeffs; c@264: m_RCFPParams.winPre = Params.WinT.pre; c@264: m_RCFPParams.winPost = Params.WinT.post; c@264: m_RCFPParams.isMedianPositive = true; c@264: c@264: m_RCFConditioning = new DFProcess( m_RCFPParams ); c@264: c@264: } c@264: c@264: void TempoTrack::deInitialise() c@264: { c@264: delete [] m_rawDFFrame; c@264: c@264: delete [] m_smoothDFFrame; c@264: c@264: delete [] m_smoothRCF; c@264: c@264: delete [] m_frameACF; c@264: c@264: delete [] m_tempoScratch; c@264: c@264: delete m_DFConditioning; c@264: c@264: delete m_RCFConditioning; c@264: c@264: } c@264: c@264: void TempoTrack::createCombFilter(double* Filter, unsigned int winLength, unsigned int TSig, double beatLag) c@264: { c@264: unsigned int i; c@264: c@264: if( beatLag == 0 ) c@264: { c@264: for( i = 0; i < winLength; i++ ) c@264: { c@264: Filter[ i ] = ( ( i + 1 ) / pow( m_rayparam, 2.0) ) * exp( ( -pow(( i + 1 ),2.0 ) / ( 2.0 * pow( m_rayparam, 2.0)))); c@264: } c@264: } c@264: else c@264: { c@264: m_sigma = beatLag/4; c@264: for( i = 0; i < winLength; i++ ) c@264: { c@264: double dlag = (double)(i+1) - beatLag; c@264: Filter[ i ] = exp(-0.5 * pow(( dlag / m_sigma), 2.0) ) / (sqrt( 2 * PI) * m_sigma); c@264: } c@264: } c@264: } c@264: c@264: double TempoTrack::tempoMM(double* ACF, double* weight, int tsig) c@264: { c@264: c@264: double period = 0; c@264: double maxValRCF = 0.0; c@264: unsigned int maxIndexRCF = 0; c@264: c@264: double* pdPeaks; c@264: c@264: unsigned int maxIndexTemp; c@264: double maxValTemp; c@264: unsigned int count; c@264: c@264: unsigned int numelem,i,j; c@264: int a, b; c@264: c@264: for( i = 0; i < m_lagLength; i++ ) c@264: m_tempoScratch[ i ] = 0.0; c@264: c@264: if( tsig == 0 ) c@264: { c@264: //if time sig is unknown, use metrically unbiased version of Filterbank c@264: numelem = 4; c@264: } c@264: else c@264: { c@264: numelem = tsig; c@264: } c@264: c@264: for(i=1;iprocess( m_tempoScratch, m_smoothRCF); c@264: c@264: if (tsig != 0) // i.e. in context dependent state c@264: { c@264: // NOW FIND MAX INDEX OF ACFOUT c@264: for( i = 0; i < m_lagLength; i++) c@264: { c@264: if( m_tempoScratch[ i ] > maxValRCF) c@264: { c@264: maxValRCF = m_tempoScratch[ i ]; c@264: maxIndexRCF = i; c@264: } c@264: } c@264: } c@264: else // using rayleigh weighting c@264: { c@264: vector > rcfMat; c@264: c@264: double sumRcf = 0.; c@264: c@264: double maxVal = 0.; c@264: // now find the two values which minimise rcfMat c@264: double minVal = 0.; c@264: int p_i = 1; // periodicity for row i; c@264: int p_j = 1; //periodicity for column j; c@264: c@264: c@264: for ( i=0; i() ); // adds a new row... c@264: } c@264: c@264: for (i=0; i(i)/static_cast(j) ) / log(2.0); c@264: rcfMat[i][j] = ( abs(1.0-abs(log2PeriodRatio)) ); c@264: rcfMat[i][j] += ( 0.01*( 1./(m_tempoScratch[i]+m_tempoScratch[j]) ) ); c@264: } c@264: } c@264: c@264: // set diagonal equal to maximum value in rcfMat c@264: // we don't want to pick one strong middle peak - we need a combination of two peaks. c@264: c@264: for ( i=1; i maxVal) c@264: { c@264: maxVal = rcfMat[i][j]; c@264: } c@264: } c@264: } c@264: c@264: for ( i=1; i m_tempoScratch[p_j]) c@264: { c@264: beatPeriod = p_i; c@264: } c@264: c@264: // now write the output c@264: maxIndexRCF = static_cast(beatPeriod); c@264: c@264: } c@264: c@264: c@264: double locked = 5168.f / maxIndexRCF; c@264: if (locked >= 30 && locked <= 180) { c@264: m_lockedTempo = locked; c@264: } c@264: c@264: if( tsig == 0 ) c@264: tsig = 4; c@264: c@264: c@264: if( tsig == 4 ) c@264: { c@264: pdPeaks = new double[ 4 ]; c@264: for( i = 0; i < 4; i++ ){ pdPeaks[ i ] = 0.0;} c@264: c@264: pdPeaks[ 0 ] = ( double )maxIndexRCF + 1; c@264: c@264: maxIndexTemp = 0; c@264: maxValTemp = 0.0; c@264: count = 0; c@264: c@264: for( i = (2 * maxIndexRCF + 1) - 1; i < (2 * maxIndexRCF + 1) + 2; i++ ) c@264: { c@264: if( ACF[ i ] > maxValTemp ) c@264: { c@264: maxValTemp = ACF[ i ]; c@264: maxIndexTemp = count; c@264: } c@264: count++; c@264: } c@264: pdPeaks[ 1 ] = (double)( maxIndexTemp + 1 + ( (2 * maxIndexRCF + 1 ) - 2 ) + 1 )/2; c@264: c@264: maxIndexTemp = 0; c@264: maxValTemp = 0.0; c@264: count = 0; c@264: c@264: for( i = (3 * maxIndexRCF + 2 ) - 2; i < (3 * maxIndexRCF + 2 ) + 3; i++ ) c@264: { c@264: if( ACF[ i ] > maxValTemp ) c@264: { c@264: maxValTemp = ACF[ i ]; c@264: maxIndexTemp = count; c@264: } c@264: count++; c@264: } c@264: pdPeaks[ 2 ] = (double)( maxIndexTemp + 1 + ( (3 * maxIndexRCF + 2) - 4 ) + 1 )/3; c@264: c@264: maxIndexTemp = 0; c@264: maxValTemp = 0.0; c@264: count = 0; c@264: c@264: for( i = ( 4 * maxIndexRCF + 3) - 3; i < ( 4 * maxIndexRCF + 3) + 4; i++ ) c@264: { c@264: if( ACF[ i ] > maxValTemp ) c@264: { c@264: maxValTemp = ACF[ i ]; c@264: maxIndexTemp = count; c@264: } c@264: count++; c@264: } c@264: pdPeaks[ 3 ] = (double)( maxIndexTemp + 1 + ( (4 * maxIndexRCF + 3) - 9 ) + 1 )/4 ; c@264: c@264: c@264: period = MathUtilities::mean( pdPeaks, 4 ); c@264: } c@264: else c@264: { c@264: pdPeaks = new double[ 3 ]; c@264: for( i = 0; i < 3; i++ ){ pdPeaks[ i ] = 0.0;} c@264: c@264: pdPeaks[ 0 ] = ( double )maxIndexRCF + 1; c@264: c@264: maxIndexTemp = 0; c@264: maxValTemp = 0.0; c@264: count = 0; c@264: c@264: for( i = (2 * maxIndexRCF + 1) - 1; i < (2 * maxIndexRCF + 1) + 2; i++ ) c@264: { c@264: if( ACF[ i ] > maxValTemp ) c@264: { c@264: maxValTemp = ACF[ i ]; c@264: maxIndexTemp = count; c@264: } c@264: count++; c@264: } c@264: pdPeaks[ 1 ] = (double)( maxIndexTemp + 1 + ( (2 * maxIndexRCF + 1 ) - 2 ) + 1 )/2; c@264: c@264: maxIndexTemp = 0; c@264: maxValTemp = 0.0; c@264: count = 0; c@264: c@264: for( i = (3 * maxIndexRCF + 2 ) - 2; i < (3 * maxIndexRCF + 2 ) + 3; i++ ) c@264: { c@264: if( ACF[ i ] > maxValTemp ) c@264: { c@264: maxValTemp = ACF[ i ]; c@264: maxIndexTemp = count; c@264: } c@264: count++; c@264: } c@264: pdPeaks[ 2 ] = (double)( maxIndexTemp + 1 + ( (3 * maxIndexRCF + 2) - 4 ) + 1 )/3; c@264: c@264: c@264: period = MathUtilities::mean( pdPeaks, 3 ); c@264: } c@264: c@264: delete [] pdPeaks; c@264: c@264: return period; c@264: } c@264: c@264: void TempoTrack::stepDetect( double* periodP, double* periodG, int currentIdx, int* flag ) c@264: { c@264: double stepthresh = 1 * 3.9017; c@264: c@264: if( *flag ) c@264: { c@264: if(abs(periodG[ currentIdx ] - periodP[ currentIdx ]) > stepthresh) c@264: { c@264: // do nuffin' c@264: } c@264: } c@264: else c@264: { c@264: if(fabs(periodG[ currentIdx ]-periodP[ currentIdx ]) > stepthresh) c@264: { c@264: *flag = 3; c@264: } c@264: } c@264: } c@264: c@264: void TempoTrack::constDetect( double* periodP, int currentIdx, int* flag ) c@264: { c@264: double constthresh = 2 * 3.9017; c@264: c@264: if( fabs( 2 * periodP[ currentIdx ] - periodP[ currentIdx - 1] - periodP[ currentIdx - 2] ) < constthresh) c@264: { c@264: *flag = 1; c@264: } c@264: else c@264: { c@264: *flag = 0; c@264: } c@264: } c@264: c@264: int TempoTrack::findMeter(double *ACF, unsigned int len, double period) c@264: { c@264: int i; c@264: int p = (int)MathUtilities::round( period ); c@264: int tsig; c@264: c@264: double Energy_3 = 0.0; c@264: double Energy_4 = 0.0; c@264: c@264: double temp3A = 0.0; c@264: double temp3B = 0.0; c@264: double temp4A = 0.0; c@264: double temp4B = 0.0; c@264: c@264: double* dbf = new double[ len ]; int t = 0; c@264: for( unsigned int u = 0; u < len; u++ ){ dbf[ u ] = 0.0; } c@264: c@264: if( (double)len < 6 * p + 2 ) c@264: { c@264: for( i = ( 3 * p - 2 ); i < ( 3 * p + 2 ) + 1; i++ ) c@264: { c@264: temp3A += ACF[ i ]; c@264: dbf[ t++ ] = ACF[ i ]; c@264: } c@264: c@264: for( i = ( 4 * p - 2 ); i < ( 4 * p + 2 ) + 1; i++ ) c@264: { c@264: temp4A += ACF[ i ]; c@264: } c@264: c@264: Energy_3 = temp3A; c@264: Energy_4 = temp4A; c@264: } c@264: else c@264: { c@264: for( i = ( 3 * p - 2 ); i < ( 3 * p + 2 ) + 1; i++ ) c@264: { c@264: temp3A += ACF[ i ]; c@264: } c@264: c@264: for( i = ( 4 * p - 2 ); i < ( 4 * p + 2 ) + 1; i++ ) c@264: { c@264: temp4A += ACF[ i ]; c@264: } c@264: c@264: for( i = ( 6 * p - 2 ); i < ( 6 * p + 2 ) + 1; i++ ) c@264: { c@264: temp3B += ACF[ i ]; c@264: } c@264: c@264: for( i = ( 2 * p - 2 ); i < ( 2 * p + 2 ) + 1; i++ ) c@264: { c@264: temp4B += ACF[ i ]; c@264: } c@264: c@264: Energy_3 = temp3A + temp3B; c@264: Energy_4 = temp4A + temp4B; c@264: } c@264: c@264: if (Energy_3 > Energy_4) c@264: { c@264: tsig = 3; c@264: } c@264: else c@264: { c@264: tsig = 4; c@264: } c@264: c@264: c@264: return tsig; c@264: } c@264: c@264: void TempoTrack::createPhaseExtractor(double *Filter, unsigned int winLength, double period, unsigned int fsp, unsigned int lastBeat) c@264: { c@264: int p = (int)MathUtilities::round( period ); c@264: int predictedOffset = 0; c@264: c@264: double* phaseScratch = new double[ p*2 ]; c@264: c@264: c@264: if( lastBeat != 0 ) c@264: { c@264: lastBeat = (int)MathUtilities::round((double)lastBeat );///(double)winLength); c@264: c@264: predictedOffset = lastBeat + p - fsp; c@264: c@264: if (predictedOffset < 0) c@264: { c@264: lastBeat = 0; c@264: } c@264: } c@264: c@264: if( lastBeat != 0 ) c@264: { c@264: int mu = p; c@264: double sigma = (double)p/8; c@264: double PhaseMin = 0.0; c@264: double PhaseMax = 0.0; c@264: unsigned int scratchLength = p*2; c@264: double temp = 0.0; c@264: c@264: for( int i = 0; i < scratchLength; i++ ) c@264: { c@264: phaseScratch[ i ] = exp( -0.5 * pow( ( i - mu ) / sigma, 2 ) ) / ( sqrt( 2*PI ) *sigma ); c@264: } c@264: c@264: MathUtilities::getFrameMinMax( phaseScratch, scratchLength, &PhaseMin, &PhaseMax ); c@264: c@264: for(int i = 0; i < scratchLength; i ++) c@264: { c@264: temp = phaseScratch[ i ]; c@264: phaseScratch[ i ] = (temp - PhaseMin)/PhaseMax; c@264: } c@264: c@264: unsigned int index = 0; c@264: for(int i = p - ( predictedOffset - 1); i < p + ( p - predictedOffset) + 1; i++) c@264: { c@264: Filter[ index++ ] = phaseScratch[ i ]; c@264: } c@264: } c@264: else c@264: { c@264: for( int i = 0; i < p; i ++) c@264: { c@264: Filter[ i ] = 1; c@264: } c@264: } c@264: c@264: delete [] phaseScratch; c@264: } c@264: c@264: int TempoTrack::phaseMM(double *DF, double *weighting, unsigned int winLength, double period) c@264: { c@264: int alignment = 0; c@264: int p = (int)MathUtilities::round( period ); c@264: c@264: double temp = 0.0; c@264: c@264: double* y = new double[ winLength ]; c@264: double* align = new double[ p ]; c@264: c@264: for( int i = 0; i < winLength; i++ ) c@264: { c@264: y[ i ] = (double)( -i + winLength )/(double)winLength; c@264: y[ i ] = pow(y [i ],2.0); // raise to power 2. c@264: } c@264: c@264: for( int o = 0; o < p; o++ ) c@264: { c@264: temp = 0.0; c@264: for(int i = 1 + (o - 1); i< winLength; i += (p + 1)) c@264: { c@264: temp = temp + DF[ i ] * y[ i ]; c@264: } c@264: align[ o ] = temp * weighting[ o ]; c@264: } c@264: c@264: c@264: double valTemp = 0.0; c@264: for(int i = 0; i < p; i++) c@264: { c@264: if( align[ i ] > valTemp ) c@264: { c@264: valTemp = align[ i ]; c@264: alignment = i; c@264: } c@264: } c@264: c@264: delete [] y; c@264: delete [] align; c@264: c@264: return alignment; c@264: } c@264: c@264: int TempoTrack::beatPredict(unsigned int FSP0, double alignment, double period, unsigned int step ) c@264: { c@264: int beat = 0; c@264: c@264: int p = (int)MathUtilities::round( period ); c@264: int align = (int)MathUtilities::round( alignment ); c@264: int FSP = (int)MathUtilities::round( FSP0 ); c@264: c@264: int FEP = FSP + ( step ); c@264: c@264: beat = FSP + align; c@264: c@264: m_beats.push_back( beat ); c@264: c@264: while( beat + p < FEP ) c@264: { c@264: beat += p; c@264: c@264: m_beats.push_back( beat ); c@264: } c@264: c@264: return beat; c@264: } c@264: c@264: vector TempoTrack::process(double *DF, unsigned int length) c@264: { c@264: m_dataLength = length; c@264: c@264: double period = 0.0; c@264: int stepFlag = 0; c@264: int constFlag = 0; c@264: int FSP = 0; c@264: int tsig = 0; c@264: int lastBeat = 0; c@264: c@264: c@264: double* RW = new double[ m_lagLength ]; c@264: for( unsigned int clear = 0; clear < m_lagLength; clear++){ RW[ clear ] = 0.0;} c@264: c@264: double* GW = new double[ m_lagLength ]; c@264: for(unsigned int clear = 0; clear < m_lagLength; clear++){ GW[ clear ] = 0.0;} c@264: c@264: double* PW = new double[ m_lagLength ]; c@264: for(unsigned int clear = 0; clear < m_lagLength; clear++){ PW[ clear ] = 0.0;} c@264: c@264: m_DFFramer.setSource( DF, m_dataLength ); c@264: c@264: unsigned int TTFrames = m_DFFramer.getMaxNoFrames(); c@264: c@264: double* periodP = new double[ TTFrames ]; c@264: for(unsigned int clear = 0; clear < TTFrames; clear++){ periodP[ clear ] = 0.0;} c@264: c@264: double* periodG = new double[ TTFrames ]; c@264: for(unsigned int clear = 0; clear < TTFrames; clear++){ periodG[ clear ] = 0.0;} c@264: c@264: double* alignment = new double[ TTFrames ]; c@264: for(unsigned int clear = 0; clear < TTFrames; clear++){ alignment[ clear ] = 0.0;} c@264: c@264: m_beats.clear(); c@264: c@264: createCombFilter( RW, m_lagLength, 0, 0 ); c@264: c@264: int TTLoopIndex = 0; c@264: c@264: for( unsigned int i = 0; i < TTFrames; i++ ) c@264: { c@264: m_DFFramer.getFrame( m_rawDFFrame ); c@264: c@264: m_DFConditioning->process( m_rawDFFrame, m_smoothDFFrame ); c@264: c@264: m_correlator.doAutoUnBiased( m_smoothDFFrame, m_frameACF, m_winLength ); c@264: c@264: periodP[ TTLoopIndex ] = tempoMM( m_frameACF, RW, 0 ); c@264: c@264: if( GW[ 0 ] != 0 ) c@264: { c@264: periodG[ TTLoopIndex ] = tempoMM( m_frameACF, GW, tsig ); c@264: } c@264: else c@264: { c@264: periodG[ TTLoopIndex ] = 0.0; c@264: } c@264: c@264: stepDetect( periodP, periodG, TTLoopIndex, &stepFlag ); c@264: c@264: if( stepFlag == 1) c@264: { c@264: constDetect( periodP, TTLoopIndex, &constFlag ); c@264: stepFlag = 0; c@264: } c@264: else c@264: { c@264: stepFlag -= 1; c@264: } c@264: c@264: if( stepFlag < 0 ) c@264: { c@264: stepFlag = 0; c@264: } c@264: c@264: if( constFlag != 0) c@264: { c@264: tsig = findMeter( m_frameACF, m_winLength, periodP[ TTLoopIndex ] ); c@264: c@264: createCombFilter( GW, m_lagLength, tsig, periodP[ TTLoopIndex ] ); c@264: c@264: periodG[ TTLoopIndex ] = tempoMM( m_frameACF, GW, tsig ); c@264: c@264: period = periodG[ TTLoopIndex ]; c@264: c@264: // am temporarily changing the last input parameter to lastBeat instead of '0' c@264: createPhaseExtractor( PW, m_winLength, period, FSP, lastBeat ); c@264: c@264: constFlag = 0; c@264: c@264: } c@264: else c@264: { c@264: if( GW[ 0 ] != 0 ) c@264: { c@264: period = periodG[ TTLoopIndex ]; c@264: createPhaseExtractor( PW, m_winLength, period, FSP, lastBeat ); c@264: c@264: } c@264: else c@264: { c@264: period = periodP[ TTLoopIndex ]; c@264: createPhaseExtractor( PW, m_winLength, period, FSP, 0 ); c@264: } c@264: } c@264: c@264: alignment[ TTLoopIndex ] = phaseMM( m_rawDFFrame, PW, m_winLength, period ); c@264: c@264: lastBeat = beatPredict(FSP, alignment[ TTLoopIndex ], period, m_lagLength ); c@264: c@264: FSP += (m_lagLength); c@264: c@264: TTLoopIndex++; c@264: } c@264: c@264: c@264: delete [] periodP; c@264: delete [] periodG; c@264: delete [] alignment; c@264: c@264: delete [] RW; c@264: delete [] GW; c@264: delete [] PW; c@264: c@264: return m_beats; c@264: } c@264: c@264: c@264: c@264: c@264: c@264: vector TempoTrack::process( vector DF, c@264: vector *tempoReturn ) c@264: { c@264: m_dataLength = DF.size(); c@264: c@264: m_lockedTempo = 0.0; c@264: c@264: double period = 0.0; c@264: int stepFlag = 0; c@264: int constFlag = 0; c@264: int FSP = 0; c@264: int tsig = 0; c@264: int lastBeat = 0; c@264: c@264: vector causalDF; c@264: c@264: causalDF = DF; c@264: c@264: //Prepare Causal Extension DFData c@264: unsigned int DFCLength = m_dataLength + m_winLength; c@264: c@264: for( unsigned int j = 0; j < m_winLength; j++ ) c@264: { c@264: causalDF.push_back( 0 ); c@264: } c@264: c@264: c@264: double* RW = new double[ m_lagLength ]; c@264: for( unsigned int clear = 0; clear < m_lagLength; clear++){ RW[ clear ] = 0.0;} c@264: c@264: double* GW = new double[ m_lagLength ]; c@264: for(unsigned int clear = 0; clear < m_lagLength; clear++){ GW[ clear ] = 0.0;} c@264: c@264: double* PW = new double[ m_lagLength ]; c@264: for(unsigned clear = 0; clear < m_lagLength; clear++){ PW[ clear ] = 0.0;} c@264: c@264: m_DFFramer.setSource( &causalDF[0], m_dataLength ); c@264: c@264: unsigned int TTFrames = m_DFFramer.getMaxNoFrames(); c@264: c@264: double* periodP = new double[ TTFrames ]; c@264: for(unsigned clear = 0; clear < TTFrames; clear++){ periodP[ clear ] = 0.0;} c@264: c@264: double* periodG = new double[ TTFrames ]; c@264: for(unsigned clear = 0; clear < TTFrames; clear++){ periodG[ clear ] = 0.0;} c@264: c@264: double* alignment = new double[ TTFrames ]; c@264: for(unsigned clear = 0; clear < TTFrames; clear++){ alignment[ clear ] = 0.0;} c@264: c@264: m_beats.clear(); c@264: c@264: createCombFilter( RW, m_lagLength, 0, 0 ); c@264: c@264: int TTLoopIndex = 0; c@264: c@264: for( unsigned int i = 0; i < TTFrames; i++ ) c@264: { c@264: m_DFFramer.getFrame( m_rawDFFrame ); c@264: c@264: m_DFConditioning->process( m_rawDFFrame, m_smoothDFFrame ); c@264: c@264: m_correlator.doAutoUnBiased( m_smoothDFFrame, m_frameACF, m_winLength ); c@264: c@264: periodP[ TTLoopIndex ] = tempoMM( m_frameACF, RW, 0 ); c@264: c@264: if( GW[ 0 ] != 0 ) c@264: { c@264: periodG[ TTLoopIndex ] = tempoMM( m_frameACF, GW, tsig ); c@264: } c@264: else c@264: { c@264: periodG[ TTLoopIndex ] = 0.0; c@264: } c@264: c@264: stepDetect( periodP, periodG, TTLoopIndex, &stepFlag ); c@264: c@264: if( stepFlag == 1) c@264: { c@264: constDetect( periodP, TTLoopIndex, &constFlag ); c@264: stepFlag = 0; c@264: } c@264: else c@264: { c@264: stepFlag -= 1; c@264: } c@264: c@264: if( stepFlag < 0 ) c@264: { c@264: stepFlag = 0; c@264: } c@264: c@264: if( constFlag != 0) c@264: { c@264: tsig = findMeter( m_frameACF, m_winLength, periodP[ TTLoopIndex ] ); c@264: c@264: createCombFilter( GW, m_lagLength, tsig, periodP[ TTLoopIndex ] ); c@264: c@264: periodG[ TTLoopIndex ] = tempoMM( m_frameACF, GW, tsig ); c@264: c@264: period = periodG[ TTLoopIndex ]; c@264: c@264: createPhaseExtractor( PW, m_winLength, period, FSP, 0 ); c@264: c@264: constFlag = 0; c@264: c@264: } c@264: else c@264: { c@264: if( GW[ 0 ] != 0 ) c@264: { c@264: period = periodG[ TTLoopIndex ]; c@264: createPhaseExtractor( PW, m_winLength, period, FSP, lastBeat ); c@264: c@264: } c@264: else c@264: { c@264: period = periodP[ TTLoopIndex ]; c@264: createPhaseExtractor( PW, m_winLength, period, FSP, 0 ); c@264: } c@264: } c@264: c@264: alignment[ TTLoopIndex ] = phaseMM( m_rawDFFrame, PW, m_winLength, period ); c@264: c@264: lastBeat = beatPredict(FSP, alignment[ TTLoopIndex ], period, m_lagLength ); c@264: c@264: FSP += (m_lagLength); c@264: c@264: if (tempoReturn) tempoReturn->push_back(m_lockedTempo); c@264: c@264: TTLoopIndex++; c@264: } c@264: c@264: c@264: delete [] periodP; c@264: delete [] periodG; c@264: delete [] alignment; c@264: c@264: delete [] RW; c@264: delete [] GW; c@264: delete [] PW; c@264: c@264: return m_beats; c@264: }