libcm is a C development framework with an emphasis on audio signal processing applications.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

cmAudDspIF.h 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef cmAudDspIF_h
  2. #define cmAudDspIF_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. // This API has two basic responsibilities:
  7. //
  8. // 1) Provides a function based interface to the audio DSP system for the
  9. // client application.
  10. // The client calls these API functions to send commands to the audio DSP
  11. // system. Internally the cmAdIfxxx functions converts the commands to
  12. // raw message packets and passes them to a transmission service
  13. // via cmAdIfParm_t audioDspFunc().
  14. //
  15. // 2) Acts as the receiver of raw message streams from whatever external
  16. // service (e.g. cmAudDspLocal, cmAudDspUdp) is receiving raw message packets
  17. // from audio DSP system.
  18. //
  19. // This process is driven by periodic calls from the client to
  20. // cmAdIfDispatchMsgToHost().
  21. // cmAdIfDispatchMsgToHost() then generates an internal
  22. // 'kClientMsgPollDuiId' msg which is passed toward the
  23. // cmAudDsp system.
  24. // When the msg encounters a sub-system with queued msgs waiting
  25. // for the client a callback chain ensues which eventually
  26. // calls cmAdIfRecvAudDspMsg() which in turn calls the appropriate
  27. // client provided cmAdIfDispatch_t function (ssInitFunc,statusFunc or uiFunc).
  28. // Note that this entire chain of calls occurs in the client thread
  29. // and in the context of the cmAdIfDispatchMsgToHost() procedure.
  30. enum
  31. {
  32. kOkAiRC = cmOkRC,
  33. kAudDspFailAiRC,
  34. kLHeapFailAiRC,
  35. kUnknownMsgTypeAiRC,
  36. kMsgCorruptAiRC,
  37. kSendFailAiRC,
  38. kQueueFailAiRC,
  39. kNoMsgAiRC,
  40. kJsonFailAiRC,
  41. kDeserialFailAiRC,
  42. kFileSysFailAiRC
  43. };
  44. typedef cmRC_t cmAiRC_t;
  45. typedef cmHandle_t cmAiH_t;
  46. // These functions are provided by the client to receive messages
  47. // from the audio DSP sytem. These functions are only called from the client thread
  48. // from within cmAdIfDispatchMsgToHost().
  49. typedef struct
  50. {
  51. void* cbDataPtr; // data to send as the first arg. to app. callbacks
  52. cmRC_t (*ssInitFunc)( void* cbDataPtr, const cmAudioSysSsInitMsg_t* r, const char* iDevLabel, const char* oDevLabel );
  53. cmRC_t (*statusFunc)( void* cbDataPtr, const cmAudioSysStatus_t* r, const double* iMeterArray, const double* oMeterArray );
  54. cmRC_t (*uiFunc)( void* cbDataPtr, const cmDspUiHdr_t* r );
  55. } cmAdIfDispatch_t;
  56. typedef struct
  57. {
  58. cmAdIfDispatch_t dispatchRecd; // client application callback pointers
  59. cmMsgSendFuncPtr_t audDspFunc; // the cmAdIfXXX functions use the callback to send msgs to the audio DSP system.
  60. void* audDspFuncDataPtr; // data to send with the audio DSP callback function
  61. } cmAdIfParm_t;
  62. extern cmAiH_t cmAiNullHandle;
  63. cmAiRC_t cmAdIfAllocate( cmCtx_t* ctx, cmAiH_t* hp, const cmAdIfParm_t* parms );
  64. cmAiRC_t cmAdIfFree( cmAiH_t* hp );
  65. bool cmAdIfIsValid( cmAiH_t h );
  66. // Receive a msg from the audio DSP system. This is the main point of entry
  67. // for all calls from the audio DSP system to the client.
  68. // This function is provided as a callback to the owner of this cmAudDspIF
  69. // (e.g. cmAudDspLocal, cmAudDspUdpClient) it should never need to be called
  70. // by the client.
  71. cmAiRC_t cmAdIfRecvAudDspMsg( cmAiH_t h, unsigned msgByteCnt, const void* msgDataPtr);
  72. //-------------------------------------------------------------------------
  73. //
  74. // The functions below are used to send commands to the audio DSP system
  75. // from the client application.
  76. //
  77. // Print a hardware report.
  78. cmAiRC_t cmAdIfDeviceReport( cmAiH_t h );
  79. // Select a audio system configuration. This must be done prior to
  80. // sending any other commands.
  81. cmAiRC_t cmAdIfSetAudioSysCfg( cmAiH_t h, unsigned asCfgIdx );
  82. // Select an audio input or output device for a given audio sub-system.
  83. // An audio configuration must have been selected via cmAdIfSetAudioSysCfg()
  84. // prior to calling this function.
  85. cmAiRC_t cmAdIfSetAudioDevice( cmAiH_t h, unsigned asSubIdx, bool inputFl, unsigned devIdx );
  86. // Set the sample rate for a given audio sub-system or the entire audio system.
  87. // Set asSubIdx to cmInvalidIdx to assign the sample rate to all sub-systems
  88. // of the current audio system configuration.
  89. // An audio configuration must have been selected via cmAdIfSetAudioSysCfg()
  90. // prior to calling this function.
  91. cmAiRC_t cmAdIfSetSampleRate( cmAiH_t h, unsigned asSubIdx, double srate );
  92. // Select a DSP program for a given audio sub-system or the entire audio system.
  93. // Set asSubIdx to cmInvalidIdx to load the program on all sub-systems
  94. // of the current audio system configuration.
  95. // An audio configuration must have been selected via cmAdIfSetAudioSysCfg()
  96. // prior to calling this function.
  97. cmAiRC_t cmAdIfLoadProgram( cmAiH_t h, unsigned asSubIdx, unsigned pgmIdx );
  98. // Print a representation (instances and connections) of the loaded program
  99. // to a JSON file.
  100. cmAiRC_t cmAdIfPrintPgm( cmAiH_t h, unsigned asSubIdx, const cmChar_t* fn );
  101. // Start the audio streaming.
  102. // An audio configuration must have been selected via cmAdIfSetAudioSysCfg()
  103. // and a DSP program must have been selected via cmAdIfLoadProgram()
  104. // prior to calling this function.
  105. cmAiRC_t cmAdIfEnableAudio( cmAiH_t h, bool enableFl );
  106. // Enable/disable periodic audio system status notifications.
  107. cmAiRC_t cmAdIfEnableStatusNotify( cmAiH_t h, bool enableFl );
  108. // Send a kUiSelAsId style message to the audio DSP system.
  109. cmAiRC_t cmAdIfSendMsgToAudioDSP(
  110. cmAiH_t h,
  111. unsigned asSubIdx,
  112. unsigned msgTypeId,
  113. unsigned selId,
  114. unsigned flags,
  115. unsigned instId,
  116. unsigned instVarId,
  117. const cmDspValue_t* valPtr );
  118. // The client application must periodically call this function to
  119. // receive pending messages from the audio DSP system. The
  120. // messages are delivered via callbacks provided by cmAdIfDispatch_t.
  121. // This function should only be called from the client thread.
  122. cmAiRC_t cmAdIfDispatchMsgToHost( cmAiH_t h );
  123. /*
  124. Local call chain:
  125. cmAdIfDispatchMsgToHost() -> p->parms.audDspFunc = cmAudDspLocal::_cmAdlAudDspSendFunc()
  126. -> cmAudioDsp::cmAudDspReceiveClientMsg()
  127. -> cmAudioDsp::_cmAudDspClientMsgPoll()
  128. -> cmAudioSys::cmAudioSysReceiveMsg()
  129. -> cmThread::cmTs1p1cDequeueMsg()
  130. -> cmAudioSysCfg_t::clientCbFunc = cmAudDsp::_cmAudioSysToClientCallback()
  131. -> cmAudDsp::cmAd_t::cbFunc = cmAudDspLocal::_cmAudDspLocalCallback()
  132. -> cmAudDspIF::cmAdIfRecvAudDspMsg()
  133. -> cmAudDspIF::_cmAiDispatchMsgToClient()
  134. -> cmAudDspIF::cmAdIfDispatch_t.uiFunc = kcApp::_s_handleUiMsg()
  135. */
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif