libcm is a C development framework with an emphasis on audio signal processing applications.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

cmAudDspIF.h 7.8KB

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