|
@@ -0,0 +1,183 @@
|
|
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
|
+
|
|
23
|
+#define SS_IMPL
|
|
24
|
+#ifdef SS_IMPL
|
|
25
|
+#include "ss0/surroundstereo.h"
|
|
26
|
+#include "ss1/surroundstereo_1.h"
|
|
27
|
+#else
|
|
28
|
+void binauralEncoderProcessInit(long pNumInputs, long frames, int hrtfSet) {}
|
|
29
|
+void binauralEncoderProcessSetPosition(int clientNum, float cazimuth, float celevation) {}
|
|
30
|
+void binauralEncoderProcess(float **inputs, float **outputs, long numInputs, long sampleFrames){}
|
|
31
|
+
|
|
32
|
+typedef struct
|
|
33
|
+{
|
|
34
|
+ void* h;
|
|
35
|
+} binauralEncoderH_t;
|
|
36
|
+
|
|
37
|
+binauralEncoderH_t binauralEncoderNullH = cmSTATIC_NULL_HANDLE;
|
|
38
|
+
|
|
39
|
+void binauralEncProcessInit(binauralEncoderH_t* hp, long pNumInputs, long frames, int hrtfSet)
|
|
40
|
+{ if(hp!=NULL) hp->h=NULL; }
|
|
41
|
+
|
|
42
|
+void binauralEncProcessFree( binauralEncoderH_t* hp ){}
|
|
43
|
+void binauralEncProcessSetPosition(binauralEncoderH_t h, int clientNum, float cazimuth, float celevation){}
|
|
44
|
+void binauralEncProcess(binauralEncoderH_t h, float **inputs, float **outputs, long numInputs, long sampleFrames){}
|
|
45
|
+#endif
|
|
46
|
+
|
|
47
|
+cmBinEnc* cmBinEncAlloc( cmCtx* c, cmBinEnc* p, double srate, unsigned procSmpCnt )
|
|
48
|
+{
|
|
49
|
+ cmBinEnc* op = cmObjAlloc(cmBinEnc,c,p);
|
|
50
|
+
|
|
51
|
+ if( srate > 0 )
|
|
52
|
+ if( cmBinEncInit(op,srate,procSmpCnt) != cmOkRC )
|
|
53
|
+ cmBinEncFree(&op);
|
|
54
|
+
|
|
55
|
+ return op;
|
|
56
|
+
|
|
57
|
+}
|
|
58
|
+
|
|
59
|
+cmRC_t cmBinEncFree( cmBinEnc** pp )
|
|
60
|
+{
|
|
61
|
+ cmRC_t rc = cmOkRC;
|
|
62
|
+ if( pp==NULL || *pp==NULL )
|
|
63
|
+ return rc;
|
|
64
|
+
|
|
65
|
+ cmBinEnc* p = *pp;
|
|
66
|
+ if((rc = cmBinEncFinal(p)) != cmOkRC )
|
|
67
|
+ return rc;
|
|
68
|
+
|
|
69
|
+ cmObjFree(pp);
|
|
70
|
+ return rc;
|
|
71
|
+
|
|
72
|
+}
|
|
73
|
+
|
|
74
|
+cmRC_t cmBinEncInit( cmBinEnc* p, double srate, unsigned procSmpCnt )
|
|
75
|
+{
|
|
76
|
+ cmRC_t rc;
|
|
77
|
+ binauralEncoderH_t h = binauralEncoderNullH;
|
|
78
|
+
|
|
79
|
+ if((rc = cmBinEncFinal(p)) != cmOkRC )
|
|
80
|
+ return rc;
|
|
81
|
+
|
|
82
|
+ p->srate = srate;
|
|
83
|
+ p->procSmpCnt = procSmpCnt;
|
|
84
|
+ p->freeFl = false;
|
|
85
|
+
|
|
86
|
+ long numInputs = 1;
|
|
87
|
+ int hrtfSet = 1;
|
|
88
|
+
|
|
89
|
+ switch(p->mode)
|
|
90
|
+ {
|
|
91
|
+ case 0:
|
|
92
|
+ binauralEncoderProcessInit(numInputs, procSmpCnt, hrtfSet);
|
|
93
|
+ break;
|
|
94
|
+
|
|
95
|
+ case 1:
|
|
96
|
+ binauralEncProcessInit(&h,numInputs, procSmpCnt, hrtfSet);
|
|
97
|
+ p->freeFl = true;
|
|
98
|
+ p->h = h.h;
|
|
99
|
+ break;
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ return rc;
|
|
103
|
+}
|
|
104
|
+
|
|
105
|
+cmRC_t cmBinEncFinal(cmBinEnc* p )
|
|
106
|
+{
|
|
107
|
+ if( p->h != NULL && p->freeFl )
|
|
108
|
+ {
|
|
109
|
+ binauralEncoderH_t h;
|
|
110
|
+ h.h = p->h;
|
|
111
|
+ binauralEncProcessFree(&h);
|
|
112
|
+ p->freeFl = false;
|
|
113
|
+ }
|
|
114
|
+ return cmOkRC;
|
|
115
|
+}
|
|
116
|
+
|
|
117
|
+cmRC_t cmBinEncSetMode(cmBinEnc* p, unsigned mode )
|
|
118
|
+{
|
|
119
|
+ if( mode != p->mode )
|
|
120
|
+ {
|
|
121
|
+ p->mode = mode;
|
|
122
|
+ return cmBinEncInit(p,p->srate,p->procSmpCnt);
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ return cmOkRC;
|
|
126
|
+}
|
|
127
|
+
|
|
128
|
+cmRC_t cmBinEncSetLoc( cmBinEnc* p, float azimDegrees, float elevDegrees, float dist )
|
|
129
|
+{
|
|
130
|
+ int clientNum = 0;
|
|
131
|
+
|
|
132
|
+ if( elevDegrees > 90.0f )
|
|
133
|
+ elevDegrees = 90.0f;
|
|
134
|
+
|
|
135
|
+ if( elevDegrees < -40.0f )
|
|
136
|
+ elevDegrees = -40.0f;
|
|
137
|
+
|
|
138
|
+ float elev = (elevDegrees + 40.0f) / (90.0f + 40.0f);
|
|
139
|
+
|
|
140
|
+ //printf("az:%f el:%f dist:%f\n",azimDegrees,elev,dist);
|
|
141
|
+
|
|
142
|
+ switch( p->mode )
|
|
143
|
+ {
|
|
144
|
+ case 0:
|
|
145
|
+ binauralEncoderProcessSetPosition(clientNum, azimDegrees/360.0f, elev);
|
|
146
|
+ break;
|
|
147
|
+
|
|
148
|
+ case 1:
|
|
149
|
+ {
|
|
150
|
+ binauralEncoderH_t h;
|
|
151
|
+ h.h = p->h;
|
|
152
|
+ binauralEncProcessSetPosition(h,clientNum, azimDegrees/360.0f, elev);
|
|
153
|
+ }
|
|
154
|
+ break;
|
|
155
|
+ }
|
|
156
|
+
|
|
157
|
+ return cmOkRC;
|
|
158
|
+}
|
|
159
|
+
|
|
160
|
+cmRC_t cmBinEncExec( cmBinEnc* p, const cmSample_t* x, cmSample_t* y0, cmSample_t* y1, unsigned xyN )
|
|
161
|
+{
|
|
162
|
+ float *inputs[] = {(float*)x};
|
|
163
|
+ float *outputs[] = {y0,y1};
|
|
164
|
+ int numInputs = sizeof(inputs)/sizeof(inputs[0]);
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+ switch( p->mode )
|
|
168
|
+ {
|
|
169
|
+ case 0:
|
|
170
|
+ binauralEncoderProcess(inputs,outputs,numInputs,xyN);
|
|
171
|
+ break;
|
|
172
|
+
|
|
173
|
+ case 1:
|
|
174
|
+ {
|
|
175
|
+ binauralEncoderH_t h;
|
|
176
|
+ h.h = p->h;
|
|
177
|
+ binauralEncProcess(h,inputs,outputs,numInputs,xyN);
|
|
178
|
+ }
|
|
179
|
+ break;
|
|
180
|
+ }
|
|
181
|
+
|
|
182
|
+ return cmOkRC;
|
|
183
|
+}
|