From feae7dc12c54a725ec1ece7644a3d04dfc08d33d Mon Sep 17 00:00:00 2001 From: kpl Date: Wed, 25 Sep 2013 23:39:40 -0700 Subject: [PATCH] cmOnset.h/c : Added cmOnsetCount(), cmOnsetSampleIndex() and cmOnsetHopSampleCount(). --- app/cmOnset.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- app/cmOnset.h | 8 ++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/app/cmOnset.c b/app/cmOnset.c index 1089cbf..924a4a8 100644 --- a/app/cmOnset.c +++ b/app/cmOnset.c @@ -214,13 +214,13 @@ cmOnRC_t _cmOnsetExec( _cmOn_t* p ) // normalize the spectral flux vector cmReal_t mean = cmVOR_Mean(p->sfV,p->frmCnt); cmReal_t stdDev = sqrt(cmVOR_Variance(p->sfV, p->frmCnt, &mean )); + unsigned detectCnt = 0; cmVOR_SubVS(p->sfV,p->frmCnt,mean); cmVOR_DivVS(p->sfV,p->frmCnt,stdDev); p->maxSf = cmVOR_Max(p->sfV,p->frmCnt,1); prog = 0.1; - printf("max:%f ",maxVal); - printf("mean:%f max:%f sd:%f\n",mean,p->maxSf,stdDev); + cmRptPrintf(p->err.rpt,"magn. max:%f flux mean:%f max:%f sd:%f\n",maxVal,mean,p->maxSf,stdDev); // Pick peaks from the onset detection function using a subset // of the rules from Dixon, 2006, Onset Detection Revisited. @@ -246,6 +246,7 @@ cmOnRC_t _cmOnsetExec( _cmOn_t* p ) if( p->sfV[fi] > cmVOR_Mean(p->sfV + bi, nn ) + p->cfg.threshold ) { p->dfV[fi] = p->sfV[fi]; + ++detectCnt; } } @@ -258,6 +259,7 @@ cmOnRC_t _cmOnsetExec( _cmOn_t* p ) } + cmRptPrintf(p->err.rpt,"Detect Count:%i\n",detectCnt); return rc; } @@ -308,6 +310,47 @@ cmOnRC_t cmOnsetProc( cmOnH_t h, const cmOnsetCfg_t* cfg, const cmChar_t* inAudi return rc; } +unsigned cmOnsetCount( cmOnH_t h ) +{ + _cmOn_t* p = _cmOnsetHandleToPtr(h); + unsigned i; + unsigned n = 0; + for(i=0; ifrmCnt; ++i) + if( p->dfV[i] > 0 ) + ++n; + + return n; +} + +unsigned cmOnsetSampleIndex( cmOnH_t h, unsigned idx ) +{ + _cmOn_t* p = _cmOnsetHandleToPtr(h); + unsigned i; + unsigned n = 0; + for(i=0; ifrmCnt; ++i) + if( p->dfV[i] > 0 ) + { + if( n == idx ) + { + unsigned r = i * p->hopSmpCnt; + if( r > p->preDelaySmpCnt ) + return r-p->preDelaySmpCnt; + return 0; + } + + ++n; + } + + return cmInvalidIdx; +} + +unsigned cmOnsetHopSampleCount( cmOnH_t h ) +{ + _cmOn_t* p = _cmOnsetHandleToPtr(h); + return p->hopSmpCnt; +} + + cmOnRC_t cmOnsetWrite( cmOnH_t h, const cmChar_t* outAudioFn, const cmChar_t* outTextFn) { enum { kChCnt = 2 }; diff --git a/app/cmOnset.h b/app/cmOnset.h index ec4fd57..a5645e3 100644 --- a/app/cmOnset.h +++ b/app/cmOnset.h @@ -50,6 +50,14 @@ extern "C" { const cmOnsetCfg_t* cfg, const cmChar_t* inAudioFn ); + // Return count of detected onsets. + unsigned cmOnsetCount( cmOnH_t h ); + + // Return location of detected onsets as a sample offset into the file. + unsigned cmOnsetSampleIndex( cmOnH_t h, unsigned idx ); + + unsigned cmOnsetHopSampleCount( cmOnH_t h ); + cmOnRC_t cmOnsetWrite( cmOnH_t h, const cmChar_t* outAudioFn,