Browse Source

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

cmOnsetHopSampleCount().
master
kpl 10 years ago
parent
commit
feae7dc12c
2 changed files with 53 additions and 2 deletions
  1. 45
    2
      app/cmOnset.c
  2. 8
    0
      app/cmOnset.h

+ 45
- 2
app/cmOnset.c View File

@@ -214,13 +214,13 @@ cmOnRC_t _cmOnsetExec( _cmOn_t* p )
214 214
   // normalize the spectral flux vector
215 215
   cmReal_t mean   = cmVOR_Mean(p->sfV,p->frmCnt);
216 216
   cmReal_t stdDev = sqrt(cmVOR_Variance(p->sfV, p->frmCnt, &mean ));
217
+  unsigned detectCnt = 0;
217 218
   cmVOR_SubVS(p->sfV,p->frmCnt,mean);
218 219
   cmVOR_DivVS(p->sfV,p->frmCnt,stdDev);
219 220
   p->maxSf = cmVOR_Max(p->sfV,p->frmCnt,1);
220 221
   prog = 0.1;
221 222
 
222
-  printf("max:%f ",maxVal);
223
-  printf("mean:%f max:%f sd:%f\n",mean,p->maxSf,stdDev);
223
+  cmRptPrintf(p->err.rpt,"magn. max:%f flux mean:%f max:%f sd:%f\n",maxVal,mean,p->maxSf,stdDev);
224 224
 
225 225
   // Pick peaks from the onset detection function using a subset
226 226
   // of the rules from Dixon, 2006, Onset Detection Revisited.
@@ -246,6 +246,7 @@ cmOnRC_t _cmOnsetExec( _cmOn_t* p )
246 246
       if( p->sfV[fi] > cmVOR_Mean(p->sfV + bi, nn ) + p->cfg.threshold )
247 247
       {
248 248
         p->dfV[fi]  = p->sfV[fi];
249
+        ++detectCnt;
249 250
       }
250 251
     }
251 252
 
@@ -258,6 +259,7 @@ cmOnRC_t _cmOnsetExec( _cmOn_t* p )
258 259
 
259 260
   }
260 261
     
262
+  cmRptPrintf(p->err.rpt,"Detect Count:%i\n",detectCnt);
261 263
   return rc;
262 264
 }
263 265
 
@@ -308,6 +310,47 @@ cmOnRC_t cmOnsetProc( cmOnH_t h, const cmOnsetCfg_t* cfg, const cmChar_t* inAudi
308 310
   return rc;
309 311
 }
310 312
 
313
+unsigned cmOnsetCount( cmOnH_t h )
314
+{
315
+  _cmOn_t* p   = _cmOnsetHandleToPtr(h);
316
+  unsigned i;
317
+  unsigned n = 0;
318
+  for(i=0; i<p->frmCnt; ++i)
319
+    if( p->dfV[i] > 0 )
320
+      ++n;
321
+
322
+  return n;
323
+}
324
+
325
+unsigned cmOnsetSampleIndex( cmOnH_t h, unsigned idx )
326
+{
327
+  _cmOn_t* p   = _cmOnsetHandleToPtr(h);
328
+  unsigned i;
329
+  unsigned n = 0;
330
+  for(i=0; i<p->frmCnt; ++i)
331
+    if( p->dfV[i] > 0 )
332
+    {
333
+      if( n == idx )
334
+      {
335
+        unsigned r = i * p->hopSmpCnt;
336
+        if( r > p->preDelaySmpCnt )
337
+          return r-p->preDelaySmpCnt;
338
+        return 0;
339
+      }
340
+
341
+      ++n;
342
+    }
343
+
344
+  return cmInvalidIdx;
345
+}
346
+
347
+unsigned cmOnsetHopSampleCount( cmOnH_t h )
348
+{
349
+  _cmOn_t* p   = _cmOnsetHandleToPtr(h);
350
+  return p->hopSmpCnt;
351
+}
352
+
353
+
311 354
 cmOnRC_t cmOnsetWrite( cmOnH_t h, const cmChar_t* outAudioFn, const cmChar_t* outTextFn)
312 355
 {
313 356
   enum { kChCnt = 2 };

+ 8
- 0
app/cmOnset.h View File

@@ -50,6 +50,14 @@ extern "C" {
50 50
     const cmOnsetCfg_t* cfg, 
51 51
     const cmChar_t* inAudioFn );
52 52
 
53
+  // Return count of detected onsets.
54
+  unsigned cmOnsetCount( cmOnH_t h );
55
+
56
+  // Return location of detected onsets as a sample offset into the file.
57
+  unsigned cmOnsetSampleIndex( cmOnH_t h, unsigned idx );
58
+
59
+  unsigned cmOnsetHopSampleCount( cmOnH_t h );
60
+
53 61
   cmOnRC_t cmOnsetWrite(
54 62
     cmOnH_t h,
55 63
     const cmChar_t* outAudioFn, 

Loading…
Cancel
Save