libcm is a C development framework with an emphasis on audio signal processing applications.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

cmAudDspLocal.c 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include "cmPrefix.h"
  2. #include "cmGlobal.h"
  3. #include "cmFloatTypes.h"
  4. #include "cmRpt.h"
  5. #include "cmErr.h"
  6. #include "cmCtx.h"
  7. #include "cmMem.h"
  8. #include "cmMallocDebug.h"
  9. #include "cmJson.h"
  10. #include "dsp/cmDspValue.h"
  11. #include "cmMsgProtocol.h"
  12. #include "cmAudDsp.h"
  13. #include "cmAudDspIF.h"
  14. #include "cmAudDspLocal.h"
  15. cmAdlH_t cmAdlNullHandle = cmSTATIC_NULL_HANDLE;
  16. typedef struct
  17. {
  18. cmErr_t err;
  19. cmAiH_t aiH;
  20. cmAdH_t adH;
  21. } cmAdl_t;
  22. cmAdl_t* _cmAdlHandleToPtr( cmAdlH_t h )
  23. {
  24. cmAdl_t* p = (cmAdl_t*)h.h;
  25. assert( p != NULL );
  26. return p;
  27. }
  28. // Forward messages coming from the audio DSP system to the audio DSP IF
  29. // for later dispatch to the client application.
  30. cmMsgRC_t _cmAudDspLocalCallback(void* cbDataPtr, unsigned msgByteCnt, const void* msg )
  31. {
  32. cmMsgRC_t rc = kOkMsgRC;
  33. cmAdl_t* p = (cmAdl_t*)cbDataPtr;
  34. if( cmAdIfRecvAudDspMsg(p->aiH, msgByteCnt, msg ) != kOkAiRC )
  35. {
  36. cmErrMsg(&p->err,kAudDspIfFailAdlRC,"Message transmission to the audio DSP interface failed.");
  37. rc = kSendFailMsgRC;
  38. }
  39. return rc;
  40. }
  41. // Forward messages from the audio DSP interface to the audio DSP system.
  42. cmMsgRC_t _cmAdlAudDspSendFunc( void* cbDataPtr, unsigned msgByteCnt, const void* msg )
  43. {
  44. cmMsgRC_t rc = kOkMsgRC;
  45. cmAdl_t* p = (cmAdl_t*)cbDataPtr;
  46. if( cmAudDspReceiveClientMsg( p->adH, msgByteCnt, msg ) != kOkAdRC )
  47. {
  48. cmErrMsg(&p->err,kAudDspFailAdlRC,"Message transmission the audio DSP system failed.");
  49. rc = kSendFailMsgRC;
  50. }
  51. return rc;
  52. }
  53. cmAdlRC_t _cmAudDspLocalFree( cmAdl_t* p )
  54. {
  55. cmAdlRC_t rc = kOkAdlRC;
  56. if( cmAdIfFree(&p->aiH) != kOkAiRC )
  57. {
  58. rc = cmErrMsg(&p->err,kAudDspIfFailAdlRC,"The audio DSP interface release failed.");
  59. goto errLabel;
  60. }
  61. if( cmAudDspFree(&p->adH) != kOkAdRC )
  62. {
  63. rc = cmErrMsg(&p->err,kAudDspFailAdlRC,"The audio DSP release failed.");
  64. goto errLabel;
  65. }
  66. cmMemFree(p);
  67. errLabel:
  68. return rc;
  69. }
  70. cmAdlRC_t cmAudDspLocalAllocate( cmCtx_t* ctx, cmAdlH_t* hp, const cmAdIfDispatch_t* recd )
  71. {
  72. cmAdlRC_t rc;
  73. if((rc = cmAudDspLocalFree(hp)) != kOkAdlRC )
  74. return rc;
  75. cmAdl_t* p = cmMemAllocZ(cmAdl_t,1);
  76. cmErrSetup(&p->err,&ctx->rpt,"Audio DSP Local");
  77. cmAdIfParm_t parms;
  78. parms.dispatchRecd = *recd;
  79. parms.audDspFunc = _cmAdlAudDspSendFunc;
  80. parms.audDspFuncDataPtr = p;
  81. if( cmAdIfAllocate(ctx, &p->aiH, &parms ) != kOkAiRC )
  82. {
  83. rc = cmErrMsg(&p->err,kAudDspIfFailAdlRC,"The audio DSP interface system allocation failed.");
  84. goto errLabel;
  85. }
  86. if( cmAudDspAlloc(ctx, &p->adH, _cmAudDspLocalCallback, p ) != kOkAdRC )
  87. {
  88. rc = cmErrMsg(&p->err,kAudDspFailAdlRC,"The audio DSP system allocation failed.");
  89. goto errLabel;
  90. }
  91. hp->h = p;
  92. errLabel:
  93. if( rc != kOkAdlRC )
  94. _cmAudDspLocalFree(p);
  95. return rc;
  96. }
  97. cmAdlRC_t cmAudDspLocalFree( cmAdlH_t* hp )
  98. {
  99. cmAdlRC_t rc = kOkAdlRC;
  100. if( hp == NULL || cmAudDspLocalIsValid(*hp) == false )
  101. return kOkAdlRC;
  102. cmAdl_t* p = _cmAdlHandleToPtr(*hp);
  103. if((rc = _cmAudDspLocalFree(p)) != kOkAdlRC )
  104. return rc;
  105. hp->h = NULL;
  106. return rc;
  107. }
  108. bool cmAudDspLocalIsValid( cmAdlH_t h )
  109. { return h.h != NULL; }
  110. cmAiH_t cmAudDspLocalIF_Handle( cmAdlH_t h )
  111. {
  112. cmAdl_t* p = _cmAdlHandleToPtr(h);
  113. return p->aiH;
  114. }