Browse Source

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

cmOnsetHopSampleCount().
master
kpl 11 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
   // normalize the spectral flux vector
214
   // normalize the spectral flux vector
215
   cmReal_t mean   = cmVOR_Mean(p->sfV,p->frmCnt);
215
   cmReal_t mean   = cmVOR_Mean(p->sfV,p->frmCnt);
216
   cmReal_t stdDev = sqrt(cmVOR_Variance(p->sfV, p->frmCnt, &mean ));
216
   cmReal_t stdDev = sqrt(cmVOR_Variance(p->sfV, p->frmCnt, &mean ));
217
+  unsigned detectCnt = 0;
217
   cmVOR_SubVS(p->sfV,p->frmCnt,mean);
218
   cmVOR_SubVS(p->sfV,p->frmCnt,mean);
218
   cmVOR_DivVS(p->sfV,p->frmCnt,stdDev);
219
   cmVOR_DivVS(p->sfV,p->frmCnt,stdDev);
219
   p->maxSf = cmVOR_Max(p->sfV,p->frmCnt,1);
220
   p->maxSf = cmVOR_Max(p->sfV,p->frmCnt,1);
220
   prog = 0.1;
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
   // Pick peaks from the onset detection function using a subset
225
   // Pick peaks from the onset detection function using a subset
226
   // of the rules from Dixon, 2006, Onset Detection Revisited.
226
   // of the rules from Dixon, 2006, Onset Detection Revisited.
246
       if( p->sfV[fi] > cmVOR_Mean(p->sfV + bi, nn ) + p->cfg.threshold )
246
       if( p->sfV[fi] > cmVOR_Mean(p->sfV + bi, nn ) + p->cfg.threshold )
247
       {
247
       {
248
         p->dfV[fi]  = p->sfV[fi];
248
         p->dfV[fi]  = p->sfV[fi];
249
+        ++detectCnt;
249
       }
250
       }
250
     }
251
     }
251
 
252
 
258
 
259
 
259
   }
260
   }
260
     
261
     
262
+  cmRptPrintf(p->err.rpt,"Detect Count:%i\n",detectCnt);
261
   return rc;
263
   return rc;
262
 }
264
 }
263
 
265
 
308
   return rc;
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
 cmOnRC_t cmOnsetWrite( cmOnH_t h, const cmChar_t* outAudioFn, const cmChar_t* outTextFn)
354
 cmOnRC_t cmOnsetWrite( cmOnH_t h, const cmChar_t* outAudioFn, const cmChar_t* outTextFn)
312
 {
355
 {
313
   enum { kChCnt = 2 };
356
   enum { kChCnt = 2 };

+ 8
- 0
app/cmOnset.h View File

50
     const cmOnsetCfg_t* cfg, 
50
     const cmOnsetCfg_t* cfg, 
51
     const cmChar_t* inAudioFn );
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
   cmOnRC_t cmOnsetWrite(
61
   cmOnRC_t cmOnsetWrite(
54
     cmOnH_t h,
62
     cmOnH_t h,
55
     const cmChar_t* outAudioFn, 
63
     const cmChar_t* outAudioFn, 

Loading…
Cancel
Save