cmOnset.h/c : Added cmOnsetCount(), cmOnsetSampleIndex() and

cmOnsetHopSampleCount().
This commit is contained in:
kpl 2013-09-25 23:39:40 -07:00
parent 797e73e958
commit feae7dc12c
2 changed files with 53 additions and 2 deletions

View File

@ -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; i<p->frmCnt; ++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; i<p->frmCnt; ++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 };

View File

@ -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,