libcm is a C development framework with an emphasis on audio signal processing applications.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

cmSaProc.c 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. #include "cmPrefix.h"
  2. #include "cmGlobal.h"
  3. #include "cmRpt.h"
  4. #include "cmErr.h"
  5. #include "cmCtx.h"
  6. #include "cmMem.h"
  7. #include "cmMallocDebug.h"
  8. #include "cmLinkedHeap.h"
  9. #include "cmFloatTypes.h"
  10. #include "cmComplexTypes.h"
  11. #include "cmFileSys.h"
  12. #include "cmJson.h"
  13. #include "cmSymTbl.h"
  14. #include "cmAudioFile.h"
  15. #include "cmText.h"
  16. #include "cmProcObj.h"
  17. #include "cmProcTemplate.h"
  18. #include "cmMath.h"
  19. #include "cmProc.h"
  20. #include "cmSaProc.h"
  21. #include "cmVectOps.h"
  22. #ifdef CM_SONICART
  23. #include "ss0/surroundstereo.h"
  24. #include "ss1/surroundstereo_1.h"
  25. #else
  26. void binauralEncoderProcessInit(long pNumInputs, long frames, int hrtfSet) {}
  27. void binauralEncoderProcessSetPosition(int clientNum, float cazimuth, float celevation) {}
  28. void binauralEncoderProcess(float **inputs, float **outputs, long numInputs, long sampleFrames){}
  29. typedef struct
  30. {
  31. void* h;
  32. } binauralEncoderH_t;
  33. binauralEncoderH_t binauralEncoderNullH = cmSTATIC_NULL_HANDLE;
  34. void binauralEncProcessInit(binauralEncoderH_t* hp, long pNumInputs, long frames, int hrtfSet)
  35. { if(hp!=NULL) hp->h=NULL; }
  36. void binauralEncProcessFree( binauralEncoderH_t* hp ){}
  37. void binauralEncProcessSetPosition(binauralEncoderH_t h, int clientNum, float cazimuth, float celevation){}
  38. void binauralEncProcess(binauralEncoderH_t h, float **inputs, float **outputs, long numInputs, long sampleFrames){}
  39. #endif
  40. cmBinEnc* cmBinEncAlloc( cmCtx* c, cmBinEnc* p, double srate, unsigned procSmpCnt )
  41. {
  42. cmBinEnc* op = cmObjAlloc(cmBinEnc,c,p);
  43. if( srate > 0 )
  44. if( cmBinEncInit(op,srate,procSmpCnt) != cmOkRC )
  45. cmBinEncFree(&op);
  46. return op;
  47. }
  48. cmRC_t cmBinEncFree( cmBinEnc** pp )
  49. {
  50. cmRC_t rc = cmOkRC;
  51. if( pp==NULL || *pp==NULL )
  52. return rc;
  53. cmBinEnc* p = *pp;
  54. if((rc = cmBinEncFinal(p)) != cmOkRC )
  55. return rc;
  56. cmObjFree(pp);
  57. return rc;
  58. }
  59. cmRC_t cmBinEncInit( cmBinEnc* p, double srate, unsigned procSmpCnt )
  60. {
  61. cmRC_t rc;
  62. binauralEncoderH_t h = binauralEncoderNullH;
  63. if((rc = cmBinEncFinal(p)) != cmOkRC )
  64. return rc;
  65. p->srate = srate;
  66. p->procSmpCnt = procSmpCnt;
  67. p->freeFl = false;
  68. long numInputs = 1;
  69. int hrtfSet = 1;
  70. switch(p->mode)
  71. {
  72. case 0:
  73. binauralEncoderProcessInit(numInputs, procSmpCnt, hrtfSet);
  74. break;
  75. case 1:
  76. binauralEncProcessInit(&h,numInputs, procSmpCnt, hrtfSet);
  77. p->freeFl = true;
  78. p->h = h.h;
  79. break;
  80. }
  81. return rc;
  82. }
  83. cmRC_t cmBinEncFinal(cmBinEnc* p )
  84. {
  85. if( p->h != NULL && p->freeFl )
  86. {
  87. binauralEncoderH_t h;
  88. h.h = p->h;
  89. binauralEncProcessFree(&h);
  90. p->freeFl = false;
  91. }
  92. return cmOkRC;
  93. }
  94. cmRC_t cmBinEncSetMode(cmBinEnc* p, unsigned mode )
  95. {
  96. if( mode != p->mode )
  97. {
  98. p->mode = mode;
  99. return cmBinEncInit(p,p->srate,p->procSmpCnt);
  100. }
  101. return cmOkRC;
  102. }
  103. cmRC_t cmBinEncSetLoc( cmBinEnc* p, float azimDegrees, float elevDegrees, float dist )
  104. {
  105. int clientNum = 0;
  106. if( elevDegrees > 90.0f )
  107. elevDegrees = 90.0f;
  108. if( elevDegrees < -40.0f )
  109. elevDegrees = -40.0f;
  110. float elev = (elevDegrees + 40.0f) / (90.0f + 40.0f);
  111. //printf("az:%f el:%f dist:%f\n",azimDegrees,elev,dist);
  112. switch( p->mode )
  113. {
  114. case 0:
  115. binauralEncoderProcessSetPosition(clientNum, azimDegrees/360.0f, elev);
  116. break;
  117. case 1:
  118. {
  119. binauralEncoderH_t h;
  120. h.h = p->h;
  121. binauralEncProcessSetPosition(h,clientNum, azimDegrees/360.0f, elev);
  122. }
  123. break;
  124. }
  125. return cmOkRC;
  126. }
  127. cmRC_t cmBinEncExec( cmBinEnc* p, const cmSample_t* x, cmSample_t* y0, cmSample_t* y1, unsigned xyN )
  128. {
  129. float *inputs[] = {(float*)x};
  130. float *outputs[] = {y0,y1};
  131. int numInputs = sizeof(inputs)/sizeof(inputs[0]);
  132. switch( p->mode )
  133. {
  134. case 0:
  135. binauralEncoderProcess(inputs,outputs,numInputs,xyN);
  136. break;
  137. case 1:
  138. {
  139. binauralEncoderH_t h;
  140. h.h = p->h;
  141. binauralEncProcess(h,inputs,outputs,numInputs,xyN);
  142. }
  143. break;
  144. }
  145. return cmOkRC;
  146. }