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.

cmPickup.h 4.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef cmPickup_h
  2. #define cmPickup_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. //( { file_desc:"'fluxo' channel calibration and gain normalization program." kw:[fluxo]}
  7. enum
  8. {
  9. kOkPuRC = cmOkRC,
  10. kProcFailPuRC,
  11. kJsonFailPuRC
  12. };
  13. typedef cmRC_t cmPuRC_t;
  14. typedef cmHandle_t cmPuH_t;
  15. // This record holds information which is maintained on a per-pickup basis
  16. typedef struct
  17. {
  18. unsigned begSmpIdx; // during auto-gain cfg set to the first sample in the audio example file where the group of notes from this pickup begin.
  19. unsigned endSmpIdx; // ... end of the example notes for this pickup
  20. unsigned midiPitch; // midi pitch associated with this pickup
  21. unsigned onCnt; // during auto-gain cfg set to the count of onsets detected for this pickup
  22. unsigned offCnt; // ... offset detected
  23. cmReal_t gateMaxAvg; // avg of the the max gate RMS values for all detected notes
  24. cmReal_t gain; // auto-gain coeff for this pickup
  25. } cmPuCh_t;
  26. extern cmPuH_t cmPuNullHandle;
  27. cmPuRC_t cmPuAlloc( cmCtx_t* ctx, cmPuH_t* hp );
  28. cmPuRC_t cmPuFree( cmPuH_t* hp );
  29. bool cmPuIsValid( cmPuH_t h );
  30. // Given a recorded audio file containing a set of notes recorded from each pickup,
  31. // an Audacity label file which marks the beginning of teach set of notes,
  32. // and a set of gate detector parameters attempt to calculate a set of gain
  33. // coefficients to equalize the relative gain of all the pickup channels.
  34. // This algorithm works in two passes: In the first pass the gain coefficient
  35. // is established by finding an average RMS value among the examples and
  36. // then increasing and decreasing the pickups to move the examples closer
  37. // to the average. The gain is then adjusted and a second pass is made to
  38. // examine how well the gate detectors work with the new gain setttings.
  39. cmPuRC_t cmPuAutoGainCfg(
  40. cmPuH_t h,
  41. const cmChar_t* audioFn, // audio file containing a set of examples for each note
  42. const cmChar_t* labelFn, // audicity label file with one marker preceding each set of notes
  43. const cmChar_t* outMtx0Fn, // octave binary matrix file containing the intermediate and final results of the gate detector analysis after the first pass
  44. const cmChar_t* outMtx1Fn, // octave binary matrix file containing the intermediate and final results of the gate detector analysis after the second pass
  45. const cmChar_t* outAudFn, // audioFn rewritten with auto-gain applied
  46. unsigned procSmpCnt, // analysis DSP frame size in samples
  47. cmReal_t hopMs, // analysis window hop size in milliseconds
  48. const cmGateDetectParams* gd0Args, // first pass gate detector args
  49. const cmGateDetectParams* gd1Args ); // second pass gate detector args
  50. // Calls cmPuReadJson() and then prepends the fileDir to each of the
  51. // file names. All the files are then read and written to this directory.
  52. // and calls cmPuAutoGainCfg().
  53. cmPuRC_t cmPuAutoGainCfgFromJson(
  54. cmPuH_t h,
  55. const cmChar_t* fileDir,
  56. cmJsonH_t jsH,
  57. cmJsonNode_t* onp,
  58. unsigned procSmpCnt );
  59. cmPuRC_t cmPuAutoGainExec( cmPuH_t h, const cmChar_t* fileDir, unsigned procSmpCnt );
  60. // Load the 'parmsCfg', 'gdArgs' and 'gain' array from the JSON
  61. // 'autoTune' object contained in the JSON object 'onp'.
  62. cmPuRC_t cmPuReadJson( cmPuH_t h, cmJsonH_t jsH, cmJsonNode_t* onp );
  63. unsigned cmPuChannelCount( cmPuH_t h );
  64. const cmPuCh_t* cmPuChannel( cmPuH_t h, unsigned chIdx );
  65. // Update the 'autoTune' JSON object contained the JSON object 'onp'.
  66. cmPuRC_t cmPuWriteJson( cmPuH_t h, cmJsonH_t jsH, cmJsonNode_t* onp );
  67. // Update the 'autoTune' JSON object in the JSON file 'jsonFn'.
  68. // (Same as cmPuWriteJson() except the JSON tree to update is contained in a file.)
  69. cmPuRC_t cmPuWriteJsonFile( cmPuH_t h, const cmChar_t* jsonFn );
  70. void cmPuReport( cmPuH_t h, cmRpt_t* rpt );
  71. void cmPuTest(cmCtx_t* ctx);
  72. //)
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. #endif