Mercurial > hg > qm-dsp
comparison dsp/tempotracking/TempoTrack.cpp @ 46:4f1870dbab2c
* Add lots of debug output
author | cannam |
---|---|
date | Thu, 24 Jul 2008 16:09:25 +0000 |
parents | 200677638f5b |
children | 38bf09927942 |
comparison
equal
deleted
inserted
replaced
45:6458bc785aed | 46:4f1870dbab2c |
---|---|
12 | 12 |
13 #include "maths/MathAliases.h" | 13 #include "maths/MathAliases.h" |
14 #include "maths/MathUtilities.h" | 14 #include "maths/MathUtilities.h" |
15 | 15 |
16 #include <iostream> | 16 #include <iostream> |
17 | |
18 #include <cassert> | |
17 | 19 |
18 | 20 |
19 #define RAY43VAL | 21 #define RAY43VAL |
20 | 22 |
21 ////////////////////////////////////////////////////////////////////// | 23 ////////////////////////////////////////////////////////////////////// |
160 else | 162 else |
161 { | 163 { |
162 numelem = tsig; | 164 numelem = tsig; |
163 } | 165 } |
164 | 166 |
167 std::cerr << "tempoMM: m_winLength = " << m_winLength << ", m_lagLength = " << m_lagLength << ", numelem = " << numelem << std::endl; | |
168 | |
165 for(i=1;i<m_lagLength-1;i++) | 169 for(i=1;i<m_lagLength-1;i++) |
166 { | 170 { |
167 //first and last output values are left intentionally as zero | 171 //first and last output values are left intentionally as zero |
168 for (a=1;a<=numelem;a++) | 172 for (a=1;a<=numelem;a++) |
169 { | 173 { |
190 m_RCFConditioning->process( m_tempoScratch, m_smoothRCF); | 194 m_RCFConditioning->process( m_tempoScratch, m_smoothRCF); |
191 | 195 |
192 if (tsig != 0) // i.e. in context dependent state | 196 if (tsig != 0) // i.e. in context dependent state |
193 { | 197 { |
194 // NOW FIND MAX INDEX OF ACFOUT | 198 // NOW FIND MAX INDEX OF ACFOUT |
195 for( i = 0; i < m_lagLength; i++) | 199 for( i = 0; i < m_lagLength; i++) |
196 { | 200 { |
197 if( m_tempoScratch[ i ] > maxValRCF) | 201 if( m_tempoScratch[ i ] > maxValRCF) |
198 { | 202 { |
199 maxValRCF = m_tempoScratch[ i ]; | 203 maxValRCF = m_tempoScratch[ i ]; |
200 maxIndexRCF = i; | 204 maxIndexRCF = i; |
201 } | 205 } |
202 } | 206 } |
203 } | 207 } |
204 else // using rayleigh weighting | 208 else // using rayleigh weighting |
205 { | 209 { |
206 vector <vector<double> > rcfMat; | 210 vector <vector<double> > rcfMat; |
207 | 211 |
298 beatPeriod = p_i; | 302 beatPeriod = p_i; |
299 } | 303 } |
300 | 304 |
301 // now write the output | 305 // now write the output |
302 maxIndexRCF = static_cast<int>(beatPeriod); | 306 maxIndexRCF = static_cast<int>(beatPeriod); |
303 | |
304 } | 307 } |
305 | 308 |
306 | 309 |
307 double locked = 5168.f / maxIndexRCF; | 310 double locked = 5168.f / maxIndexRCF; |
308 if (locked >= 30 && locked <= 180) { | 311 if (locked >= 30 && locked <= 180) { |
310 } | 313 } |
311 | 314 |
312 if( tsig == 0 ) | 315 if( tsig == 0 ) |
313 tsig = 4; | 316 tsig = 4; |
314 | 317 |
318 | |
319 std::cerr << "tempoMM: maxIndexRCF = " << maxIndexRCF << std::endl; | |
315 | 320 |
316 if( tsig == 4 ) | 321 if( tsig == 4 ) |
317 { | 322 { |
318 pdPeaks = new double[ 4 ]; | 323 pdPeaks = new double[ 4 ]; |
319 for( i = 0; i < 4; i++ ){ pdPeaks[ i ] = 0.0;} | 324 for( i = 0; i < 4; i++ ){ pdPeaks[ i ] = 0.0;} |
522 | 527 |
523 void TempoTrack::createPhaseExtractor(double *Filter, unsigned int winLength, double period, unsigned int fsp, unsigned int lastBeat) | 528 void TempoTrack::createPhaseExtractor(double *Filter, unsigned int winLength, double period, unsigned int fsp, unsigned int lastBeat) |
524 { | 529 { |
525 int p = (int)MathUtilities::round( period ); | 530 int p = (int)MathUtilities::round( period ); |
526 int predictedOffset = 0; | 531 int predictedOffset = 0; |
532 | |
533 std::cerr << "TempoTrack::createPhaseExtractor: period = " << period << ", p = " << p << std::endl; | |
534 | |
535 assert(p < 10000); | |
527 | 536 |
528 double* phaseScratch = new double[ p*2 ]; | 537 double* phaseScratch = new double[ p*2 ]; |
529 | 538 |
530 | 539 |
531 if( lastBeat != 0 ) | 540 if( lastBeat != 0 ) |
560 { | 569 { |
561 temp = phaseScratch[ i ]; | 570 temp = phaseScratch[ i ]; |
562 phaseScratch[ i ] = (temp - PhaseMin)/PhaseMax; | 571 phaseScratch[ i ] = (temp - PhaseMin)/PhaseMax; |
563 } | 572 } |
564 | 573 |
574 std::cerr << "predictedOffset = " << predictedOffset << std::endl; | |
575 | |
565 unsigned int index = 0; | 576 unsigned int index = 0; |
566 for(int i = p - ( predictedOffset - 1); i < p + ( p - predictedOffset) + 1; i++) | 577 for(int i = p - ( predictedOffset - 1); i < p + ( p - predictedOffset) + 1; i++) |
567 { | 578 { |
579 std::cerr << "assigning to filter index " << index << " (size = " << p*2 << ")" << std::endl; | |
568 Filter[ index++ ] = phaseScratch[ i ]; | 580 Filter[ index++ ] = phaseScratch[ i ]; |
569 } | 581 } |
570 } | 582 } |
571 else | 583 else |
572 { | 584 { |
877 | 889 |
878 periodG[ TTLoopIndex ] = tempoMM( m_frameACF, GW, tsig ); | 890 periodG[ TTLoopIndex ] = tempoMM( m_frameACF, GW, tsig ); |
879 | 891 |
880 period = periodG[ TTLoopIndex ]; | 892 period = periodG[ TTLoopIndex ]; |
881 | 893 |
894 std::cerr << "TempoTrack::process(2): constFlag == " << constFlag << ", TTLoopIndex = " << TTLoopIndex << ", period from periodG = " << period << std::endl; | |
895 | |
882 createPhaseExtractor( PW, m_winLength, period, FSP, 0 ); | 896 createPhaseExtractor( PW, m_winLength, period, FSP, 0 ); |
883 | 897 |
884 constFlag = 0; | 898 constFlag = 0; |
885 | 899 |
886 } | 900 } |
887 else | 901 else |
888 { | 902 { |
889 if( GW[ 0 ] != 0 ) | 903 if( GW[ 0 ] != 0 ) |
890 { | 904 { |
891 period = periodG[ TTLoopIndex ]; | 905 period = periodG[ TTLoopIndex ]; |
906 | |
907 std::cerr << "TempoTrack::process(2): GW[0] == " << GW[0] << ", TTLoopIndex = " << TTLoopIndex << ", period from periodG = " << period << std::endl; | |
908 | |
909 if (period > 10000) { | |
910 std::cerr << "WARNING! Highly implausible period value!" << std::endl; | |
911 std::cerr << "periodG contains (of " << TTFrames << " frames): " << std::endl; | |
912 for (int i = 0; i < TTLoopIndex + 3 && i < TTFrames; ++i) { | |
913 std::cerr << i << " -> " << periodG[i] << std::endl; | |
914 } | |
915 std::cerr << "periodP contains (of " << TTFrames << " frames): " << std::endl; | |
916 for (int i = 0; i < TTLoopIndex + 3 && i < TTFrames; ++i) { | |
917 std::cerr << i << " -> " << periodP[i] << std::endl; | |
918 } | |
919 } | |
920 | |
892 createPhaseExtractor( PW, m_winLength, period, FSP, lastBeat ); | 921 createPhaseExtractor( PW, m_winLength, period, FSP, lastBeat ); |
893 | 922 |
894 } | 923 } |
895 else | 924 else |
896 { | 925 { |
897 period = periodP[ TTLoopIndex ]; | 926 period = periodP[ TTLoopIndex ]; |
927 | |
928 std::cerr << "TempoTrack::process(2): GW[0] == " << GW[0] << ", TTLoopIndex = " << TTLoopIndex << ", period from periodP = " << period << std::endl; | |
929 | |
898 createPhaseExtractor( PW, m_winLength, period, FSP, 0 ); | 930 createPhaseExtractor( PW, m_winLength, period, FSP, 0 ); |
899 } | 931 } |
900 } | 932 } |
901 | 933 |
902 alignment[ TTLoopIndex ] = phaseMM( m_rawDFFrame, PW, m_winLength, period ); | 934 alignment[ TTLoopIndex ] = phaseMM( m_rawDFFrame, PW, m_winLength, period ); |