libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmOnset.h 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //| Copyright: (C) 2009-2020 Kevin Larke <contact AT larke DOT org>
  2. //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
  3. #ifndef cmOnset_h
  4. #define cmOnset_h
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. //( { file_desc:"Musical event onset detector." kw:[audio] }
  9. enum
  10. {
  11. kOkOnRC = cmOkRC,
  12. kDspProcFailOnRC,
  13. kDspAudioFileFailOnRC,
  14. kDspTextFileFailOnRC,
  15. };
  16. typedef cmRC_t cmOnRC_t;
  17. typedef cmHandle_t cmOnH_t;
  18. enum { kNoneFiltId, kSmoothFiltId, kMedianFiltId };
  19. typedef struct
  20. {
  21. double wndMs;
  22. unsigned hopFact;
  23. unsigned audioChIdx;
  24. unsigned wndFrmCnt; // Detection window length
  25. double preWndMult; // Detection window stretch factor prior to current location.
  26. double threshold; // Spectal flux detection threshold
  27. double maxFrqHz; // Ignore frequencies above maxFrqHz during processing.
  28. double filtCoeff; // smoothing filter coeff (-.7)
  29. double medFiltWndMs;// median filter window in milliseconds
  30. unsigned filterId; // kSmoothFiltId || kMedianFiltId
  31. double preDelayMs; // move each detection preDelayMs backwards in time
  32. // on the audio output. (compensates for detection delay due to filtering)
  33. } cmOnsetCfg_t;
  34. extern cmOnH_t cmOnsetNullHandle;
  35. cmOnRC_t cmOnsetInitialize( cmCtx_t* c, cmOnH_t* hp );
  36. cmOnRC_t cmOnsetFinalize( cmOnH_t* hp );
  37. bool cmOnsetIsValid( cmOnH_t h );
  38. cmOnRC_t cmOnsetProc(
  39. cmOnH_t h,
  40. const cmOnsetCfg_t* cfg,
  41. const cmChar_t* inAudioFn );
  42. // Return count of detected onsets.
  43. unsigned cmOnsetCount( cmOnH_t h );
  44. // Return location of detected onsets as a sample offset into the file.
  45. unsigned cmOnsetSampleIndex( cmOnH_t h, unsigned idx );
  46. unsigned cmOnsetHopSampleCount( cmOnH_t h );
  47. cmOnRC_t cmOnsetWrite(
  48. cmOnH_t h,
  49. const cmChar_t* outAudioFn,
  50. const cmChar_t* outTextFn);
  51. cmOnRC_t cmOnsetTest( cmCtx_t* c );
  52. //)
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56. #endif