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.2KB

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