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.

cmAudDspIF.h 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. // Start the audio streaming.
  99. // An audio configuration must have been selected via cmAdIfSetAudioSysCfg()
  100. // and a DSP program must have been selected via cmAdIfLoadProgram()
  101. // prior to calling this function.
  102. cmAiRC_t cmAdIfEnableAudio( cmAiH_t h, bool enableFl );
  103. // Enable/disable periodic audio system status notifications.
  104. cmAiRC_t cmAdIfEnableStatusNotify( cmAiH_t h, bool enableFl );
  105. // Send a kUiSelAsId style message to the audio DSP system.
  106. cmAiRC_t cmAdIfSendMsgToAudioDSP(
  107. cmAiH_t h,
  108. unsigned asSubIdx,
  109. unsigned msgTypeId,
  110. unsigned selId,
  111. unsigned flags,
  112. unsigned instId,
  113. unsigned instVarId,
  114. const cmDspValue_t* valPtr );
  115. // The client application must periodically call this function to
  116. // receive pending messages from the audio DSP system. The
  117. // messages are delivered via callbacks provided by cmAdIfDispatch_t.
  118. // This function should only be called from the client thread.
  119. cmAiRC_t cmAdIfDispatchMsgToHost( cmAiH_t h );
  120. /*
  121. Local call chain:
  122. cmAdIfDispatchMsgToHost() -> p->parms.audDspFunc = cmAudDspLocal::_cmAdlAudDspSendFunc()
  123. -> cmAudioDsp::cmAudDspReceiveClientMsg()
  124. -> cmAudioDsp::_cmAudDspClientMsgPoll()
  125. -> cmAudioSys::cmAudioSysReceiveMsg()
  126. -> cmThread::cmTs1p1cDequeueMsg()
  127. -> cmAudioSysCfg_t::clientCbFunc = cmAudDsp::_cmAudioSysToClientCallback()
  128. -> cmAudDsp::cmAd_t::cbFunc = cmAudDspLocal::_cmAudDspLocalCallback()
  129. -> cmAudDspIF::cmAdIfRecvAudDspMsg()
  130. -> cmAudDspIF::_cmAiDispatchMsgToClient()
  131. -> cmAudDspIF::cmAdIfDispatch_t.uiFunc = kcApp::_s_handleUiMsg()
  132. */
  133. #ifdef __cplusplus
  134. }
  135. #endif
  136. #endif