rlm@0
|
1 #include "config.h"
|
rlm@0
|
2 #include <stdlib.h>
|
rlm@0
|
3 #include "alMain.h"
|
rlm@0
|
4 #include "AL/al.h"
|
rlm@0
|
5 #include "AL/alc.h"
|
rlm@0
|
6 #include "alSource.h"
|
rlm@0
|
7 #include <jni.h>
|
rlm@0
|
8
|
rlm@0
|
9 //////////////////// Summary
|
rlm@0
|
10
|
rlm@0
|
11 struct send_data;
|
rlm@0
|
12 struct context_data;
|
rlm@0
|
13
|
rlm@0
|
14 static void addContext(ALCdevice *, ALCcontext *);
|
rlm@0
|
15 static void syncContexts(ALCcontext *master, ALCcontext *slave);
|
rlm@0
|
16 static void syncSources(ALsource *master, ALsource *slave,
|
rlm@0
|
17 ALCcontext *masterCtx, ALCcontext *slaveCtx);
|
rlm@0
|
18
|
rlm@0
|
19 static void syncSourcei(ALuint master, ALuint slave,
|
rlm@0
|
20 ALCcontext *masterCtx, ALCcontext *ctx2, ALenum param);
|
rlm@0
|
21 static void syncSourcef(ALuint master, ALuint slave,
|
rlm@0
|
22 ALCcontext *masterCtx, ALCcontext *ctx2, ALenum param);
|
rlm@0
|
23 static void syncSource3f(ALuint master, ALuint slave,
|
rlm@0
|
24 ALCcontext *masterCtx, ALCcontext *ctx2, ALenum param);
|
rlm@0
|
25
|
rlm@0
|
26 static void swapInContext(ALCdevice *, struct context_data *);
|
rlm@0
|
27 static void saveContext(ALCdevice *, struct context_data *);
|
rlm@0
|
28 static void limitContext(ALCdevice *, ALCcontext *);
|
rlm@0
|
29 static void unLimitContext(ALCdevice *);
|
rlm@0
|
30
|
rlm@0
|
31 static void init(ALCdevice *);
|
rlm@0
|
32 static void renderData(ALCdevice *, int samples);
|
rlm@0
|
33
|
rlm@0
|
34 #define UNUSED(x) (void)(x)
|
rlm@0
|
35
|
rlm@0
|
36 //////////////////// State
|
rlm@0
|
37
|
rlm@0
|
38 typedef struct context_data {
|
rlm@0
|
39 ALfloat ClickRemoval[MAXCHANNELS];
|
rlm@0
|
40 ALfloat PendingClicks[MAXCHANNELS];
|
rlm@0
|
41 ALvoid *renderBuffer;
|
rlm@0
|
42 ALCcontext *ctx;
|
rlm@0
|
43 } context_data;
|
rlm@0
|
44
|
rlm@0
|
45 typedef struct send_data {
|
rlm@0
|
46 ALuint size;
|
rlm@0
|
47 context_data **contexts;
|
rlm@0
|
48 ALuint numContexts;
|
rlm@0
|
49 ALuint maxContexts;
|
rlm@0
|
50 } send_data;
|
rlm@0
|
51
|
rlm@0
|
52
|
rlm@0
|
53
|
rlm@0
|
54 //////////////////// Context Creation / Synchronization
|
rlm@0
|
55
|
rlm@0
|
56 #define _MAKE_SYNC(NAME, INIT_EXPR, GET_EXPR, SET_EXPR) \
|
rlm@0
|
57 void NAME (ALuint sourceID1, ALuint sourceID2, \
|
rlm@0
|
58 ALCcontext *ctx1, ALCcontext *ctx2, \
|
rlm@0
|
59 ALenum param){ \
|
rlm@0
|
60 INIT_EXPR; \
|
rlm@0
|
61 ALCcontext *current = alcGetCurrentContext(); \
|
rlm@0
|
62 alcMakeContextCurrent(ctx1); \
|
rlm@0
|
63 GET_EXPR; \
|
rlm@0
|
64 alcMakeContextCurrent(ctx2); \
|
rlm@0
|
65 SET_EXPR; \
|
rlm@0
|
66 alcMakeContextCurrent(current); \
|
rlm@0
|
67 }
|
rlm@0
|
68
|
rlm@0
|
69 #define MAKE_SYNC(NAME, TYPE, GET, SET) \
|
rlm@0
|
70 _MAKE_SYNC(NAME, \
|
rlm@0
|
71 TYPE value, \
|
rlm@0
|
72 GET(sourceID1, param, &value), \
|
rlm@0
|
73 SET(sourceID2, param, value))
|
rlm@0
|
74
|
rlm@0
|
75 #define MAKE_SYNC3(NAME, TYPE, GET, SET) \
|
rlm@0
|
76 _MAKE_SYNC(NAME, \
|
rlm@0
|
77 TYPE value1; TYPE value2; TYPE value3;, \
|
rlm@0
|
78 GET(sourceID1, param, &value1, &value2, &value3), \
|
rlm@0
|
79 SET(sourceID2, param, value1, value2, value3))
|
rlm@0
|
80
|
rlm@0
|
81 MAKE_SYNC( syncSourcei, ALint, alGetSourcei, alSourcei);
|
rlm@0
|
82 MAKE_SYNC( syncSourcef, ALfloat, alGetSourcef, alSourcef);
|
rlm@0
|
83 MAKE_SYNC3(syncSource3i, ALint, alGetSource3i, alSource3i);
|
rlm@0
|
84 MAKE_SYNC3(syncSource3f, ALfloat, alGetSource3f, alSource3f);
|
rlm@0
|
85
|
rlm@0
|
86 void syncSources(ALsource *masterSource, ALsource *slaveSource,
|
rlm@0
|
87 ALCcontext *masterCtx, ALCcontext *slaveCtx){
|
rlm@0
|
88 ALuint master = masterSource->source;
|
rlm@0
|
89 ALuint slave = slaveSource->source;
|
rlm@0
|
90 ALCcontext *current = alcGetCurrentContext();
|
rlm@0
|
91
|
rlm@0
|
92 syncSourcef(master,slave,masterCtx,slaveCtx,AL_PITCH);
|
rlm@0
|
93 syncSourcef(master,slave,masterCtx,slaveCtx,AL_GAIN);
|
rlm@0
|
94 syncSourcef(master,slave,masterCtx,slaveCtx,AL_MAX_DISTANCE);
|
rlm@0
|
95 syncSourcef(master,slave,masterCtx,slaveCtx,AL_ROLLOFF_FACTOR);
|
rlm@0
|
96 syncSourcef(master,slave,masterCtx,slaveCtx,AL_REFERENCE_DISTANCE);
|
rlm@0
|
97 syncSourcef(master,slave,masterCtx,slaveCtx,AL_MIN_GAIN);
|
rlm@0
|
98 syncSourcef(master,slave,masterCtx,slaveCtx,AL_MAX_GAIN);
|
rlm@0
|
99 syncSourcef(master,slave,masterCtx,slaveCtx,AL_CONE_OUTER_GAIN);
|
rlm@0
|
100 syncSourcef(master,slave,masterCtx,slaveCtx,AL_CONE_INNER_ANGLE);
|
rlm@0
|
101 syncSourcef(master,slave,masterCtx,slaveCtx,AL_CONE_OUTER_ANGLE);
|
rlm@0
|
102 syncSourcef(master,slave,masterCtx,slaveCtx,AL_SEC_OFFSET);
|
rlm@0
|
103 syncSourcef(master,slave,masterCtx,slaveCtx,AL_SAMPLE_OFFSET);
|
rlm@0
|
104 syncSourcef(master,slave,masterCtx,slaveCtx,AL_BYTE_OFFSET);
|
rlm@0
|
105
|
rlm@0
|
106 syncSource3f(master,slave,masterCtx,slaveCtx,AL_POSITION);
|
rlm@0
|
107 syncSource3f(master,slave,masterCtx,slaveCtx,AL_VELOCITY);
|
rlm@0
|
108 syncSource3f(master,slave,masterCtx,slaveCtx,AL_DIRECTION);
|
rlm@0
|
109
|
rlm@0
|
110 syncSourcei(master,slave,masterCtx,slaveCtx,AL_SOURCE_RELATIVE);
|
rlm@0
|
111 syncSourcei(master,slave,masterCtx,slaveCtx,AL_LOOPING);
|
rlm@0
|
112
|
rlm@0
|
113 alcMakeContextCurrent(masterCtx);
|
rlm@0
|
114 ALint source_type;
|
rlm@0
|
115 alGetSourcei(master, AL_SOURCE_TYPE, &source_type);
|
rlm@0
|
116
|
rlm@0
|
117 // Only static sources are currently synchronized!
|
rlm@0
|
118 if (AL_STATIC == source_type){
|
rlm@0
|
119 ALint master_buffer;
|
rlm@0
|
120 ALint slave_buffer;
|
rlm@0
|
121 alGetSourcei(master, AL_BUFFER, &master_buffer);
|
rlm@0
|
122 alcMakeContextCurrent(slaveCtx);
|
rlm@0
|
123 alGetSourcei(slave, AL_BUFFER, &slave_buffer);
|
rlm@0
|
124 if (master_buffer != slave_buffer){
|
rlm@0
|
125 alSourcei(slave, AL_BUFFER, master_buffer);
|
rlm@0
|
126 }
|
rlm@0
|
127 }
|
rlm@0
|
128
|
rlm@0
|
129 // Synchronize the state of the two sources.
|
rlm@0
|
130 alcMakeContextCurrent(masterCtx);
|
rlm@0
|
131 ALint masterState;
|
rlm@0
|
132 ALint slaveState;
|
rlm@0
|
133
|
rlm@0
|
134 alGetSourcei(master, AL_SOURCE_STATE, &masterState);
|
rlm@0
|
135 alcMakeContextCurrent(slaveCtx);
|
rlm@0
|
136 alGetSourcei(slave, AL_SOURCE_STATE, &slaveState);
|
rlm@0
|
137
|
rlm@0
|
138 if (masterState != slaveState){
|
rlm@0
|
139 switch (masterState){
|
rlm@0
|
140 case AL_INITIAL : alSourceRewind(slave); break;
|
rlm@0
|
141 case AL_PLAYING : alSourcePlay(slave); break;
|
rlm@0
|
142 case AL_PAUSED : alSourcePause(slave); break;
|
rlm@0
|
143 case AL_STOPPED : alSourceStop(slave); break;
|
rlm@0
|
144 }
|
rlm@0
|
145 }
|
rlm@0
|
146 // Restore whatever context was previously active.
|
rlm@0
|
147 alcMakeContextCurrent(current);
|
rlm@0
|
148 }
|
rlm@0
|
149
|
rlm@0
|
150
|
rlm@0
|
151 void syncContexts(ALCcontext *master, ALCcontext *slave){
|
rlm@0
|
152 /* If there aren't sufficient sources in slave to mirror
|
rlm@0
|
153 the sources in master, create them. */
|
rlm@0
|
154 ALCcontext *current = alcGetCurrentContext();
|
rlm@0
|
155
|
rlm@0
|
156 UIntMap *masterSourceMap = &(master->SourceMap);
|
rlm@0
|
157 UIntMap *slaveSourceMap = &(slave->SourceMap);
|
rlm@0
|
158 ALuint numMasterSources = masterSourceMap->size;
|
rlm@0
|
159 ALuint numSlaveSources = slaveSourceMap->size;
|
rlm@0
|
160
|
rlm@0
|
161 alcMakeContextCurrent(slave);
|
rlm@0
|
162 if (numSlaveSources < numMasterSources){
|
rlm@0
|
163 ALuint numMissingSources = numMasterSources - numSlaveSources;
|
rlm@0
|
164 ALuint newSources[numMissingSources];
|
rlm@0
|
165 alGenSources(numMissingSources, newSources);
|
rlm@0
|
166 }
|
rlm@0
|
167
|
rlm@0
|
168 /* Now, slave is gauranteed to have at least as many sources
|
rlm@0
|
169 as master. Sync each source from master to the corresponding
|
rlm@0
|
170 source in slave. */
|
rlm@0
|
171 int i;
|
rlm@0
|
172 for(i = 0; i < masterSourceMap->size; i++){
|
rlm@0
|
173 syncSources((ALsource*)masterSourceMap->array[i].value,
|
rlm@0
|
174 (ALsource*)slaveSourceMap->array[i].value,
|
rlm@0
|
175 master, slave);
|
rlm@0
|
176 }
|
rlm@0
|
177 alcMakeContextCurrent(current);
|
rlm@0
|
178 }
|
rlm@0
|
179
|
rlm@0
|
180 static void addContext(ALCdevice *Device, ALCcontext *context){
|
rlm@0
|
181 send_data *data = (send_data*)Device->ExtraData;
|
rlm@0
|
182 // expand array if necessary
|
rlm@0
|
183 if (data->numContexts >= data->maxContexts){
|
rlm@0
|
184 ALuint newMaxContexts = data->maxContexts*2 + 1;
|
rlm@0
|
185 data->contexts = realloc(data->contexts, newMaxContexts*sizeof(context_data));
|
rlm@0
|
186 data->maxContexts = newMaxContexts;
|
rlm@0
|
187 }
|
rlm@0
|
188 // create context_data and add it to the main array
|
rlm@0
|
189 context_data *ctxData;
|
rlm@0
|
190 ctxData = (context_data*)calloc(1, sizeof(*ctxData));
|
rlm@0
|
191 ctxData->renderBuffer = malloc(data->size);
|
rlm@0
|
192 ctxData->ctx = context;
|
rlm@0
|
193
|
rlm@0
|
194 data->contexts[data->numContexts] = ctxData;
|
rlm@0
|
195 data->numContexts++;
|
rlm@0
|
196 }
|
rlm@0
|
197
|
rlm@0
|
198
|
rlm@0
|
199 //////////////////// Context Switching
|
rlm@0
|
200
|
rlm@0
|
201 /* A device brings along with it two pieces of state
|
rlm@0
|
202 * which have to be swapped in and out with each context.
|
rlm@0
|
203 */
|
rlm@0
|
204 static void swapInContext(ALCdevice *Device, context_data *ctxData){
|
rlm@0
|
205 memcpy(Device->ClickRemoval, ctxData->ClickRemoval, sizeof(ALfloat)*MAXCHANNELS);
|
rlm@0
|
206 memcpy(Device->PendingClicks, ctxData->PendingClicks, sizeof(ALfloat)*MAXCHANNELS);
|
rlm@0
|
207 }
|
rlm@0
|
208
|
rlm@0
|
209 static void saveContext(ALCdevice *Device, context_data *ctxData){
|
rlm@0
|
210 memcpy(ctxData->ClickRemoval, Device->ClickRemoval, sizeof(ALfloat)*MAXCHANNELS);
|
rlm@0
|
211 memcpy(ctxData->PendingClicks, Device->PendingClicks, sizeof(ALfloat)*MAXCHANNELS);
|
rlm@0
|
212 }
|
rlm@0
|
213
|
rlm@0
|
214 static ALCcontext **currentContext;
|
rlm@0
|
215 static ALuint currentNumContext;
|
rlm@0
|
216
|
rlm@0
|
217 /* By default, all contexts are rendered at once for each call to aluMixData.
|
rlm@0
|
218 * This function uses the internals of the ALCdecice struct to temporarly
|
rlm@0
|
219 * cause aluMixData to only render the chosen context.
|
rlm@0
|
220 */
|
rlm@0
|
221 static void limitContext(ALCdevice *Device, ALCcontext *ctx){
|
rlm@0
|
222 currentContext = Device->Contexts;
|
rlm@0
|
223 currentNumContext = Device->NumContexts;
|
rlm@0
|
224 Device->Contexts = &ctx;
|
rlm@0
|
225 Device->NumContexts = 1;
|
rlm@0
|
226 }
|
rlm@0
|
227
|
rlm@0
|
228 static void unLimitContext(ALCdevice *Device){
|
rlm@0
|
229 Device->Contexts = currentContext;
|
rlm@0
|
230 Device->NumContexts = currentNumContext;
|
rlm@0
|
231 }
|
rlm@0
|
232
|
rlm@0
|
233
|
rlm@0
|
234 //////////////////// Main Device Loop
|
rlm@0
|
235
|
rlm@0
|
236 /* Establish the LWJGL context as the main context, which will
|
rlm@0
|
237 * be synchronized to all the slave contexts
|
rlm@0
|
238 */
|
rlm@0
|
239 static void init(ALCdevice *Device){
|
rlm@0
|
240 ALCcontext *masterContext = alcGetCurrentContext();
|
rlm@0
|
241 addContext(Device, masterContext);
|
rlm@0
|
242 }
|
rlm@0
|
243
|
rlm@0
|
244
|
rlm@0
|
245 static void renderData(ALCdevice *Device, int samples){
|
rlm@0
|
246 if(!Device->Connected){return;}
|
rlm@0
|
247 send_data *data = (send_data*)Device->ExtraData;
|
rlm@0
|
248 ALCcontext *current = alcGetCurrentContext();
|
rlm@0
|
249
|
rlm@0
|
250 ALuint i;
|
rlm@0
|
251 for (i = 1; i < data->numContexts; i++){
|
rlm@0
|
252 syncContexts(data->contexts[0]->ctx , data->contexts[i]->ctx);
|
rlm@0
|
253 }
|
rlm@0
|
254
|
rlm@0
|
255 if ((uint) samples > Device->UpdateSize){
|
rlm@0
|
256 printf("exceeding internal buffer size; dropping samples\n");
|
rlm@0
|
257 printf("requested %d; available %d\n", samples, Device->UpdateSize);
|
rlm@0
|
258 samples = (int) Device->UpdateSize;
|
rlm@0
|
259 }
|
rlm@0
|
260
|
rlm@0
|
261 for (i = 0; i < data->numContexts; i++){
|
rlm@0
|
262 context_data *ctxData = data->contexts[i];
|
rlm@0
|
263 ALCcontext *ctx = ctxData->ctx;
|
rlm@0
|
264 alcMakeContextCurrent(ctx);
|
rlm@0
|
265 limitContext(Device, ctx);
|
rlm@0
|
266 swapInContext(Device, ctxData);
|
rlm@0
|
267 aluMixData(Device, ctxData->renderBuffer, samples);
|
rlm@0
|
268 saveContext(Device, ctxData);
|
rlm@0
|
269 unLimitContext(Device);
|
rlm@0
|
270 }
|
rlm@0
|
271 alcMakeContextCurrent(current);
|
rlm@0
|
272 }
|
rlm@0
|
273
|
rlm@0
|
274
|
rlm@0
|
275 //////////////////// JNI Methods
|
rlm@0
|
276
|
rlm@0
|
277 #include "com_aurellem_capture_AudioSend.h"
|
rlm@0
|
278
|
rlm@0
|
279 /*
|
rlm@0
|
280 * Class: com_aurellem_capture_AudioSend
|
rlm@0
|
281 * Method: nstep
|
rlm@0
|
282 * Signature: (JI)V
|
rlm@0
|
283 */
|
rlm@0
|
284 JNIEXPORT void JNICALL Java_com_aurellem_capture_AudioSend_nstep
|
rlm@0
|
285 (JNIEnv *env, jclass clazz, jlong device, jint samples){
|
rlm@0
|
286 UNUSED(env);UNUSED(clazz);UNUSED(device);
|
rlm@0
|
287 renderData((ALCdevice*)((intptr_t)device), samples);
|
rlm@0
|
288 }
|
rlm@0
|
289
|
rlm@0
|
290 /*
|
rlm@0
|
291 * Class: com_aurellem_capture_AudioSend
|
rlm@0
|
292 * Method: ngetSamples
|
rlm@0
|
293 * Signature: (JLjava/nio/ByteBuffer;III)V
|
rlm@0
|
294 */
|
rlm@0
|
295 JNIEXPORT void JNICALL Java_com_aurellem_capture_AudioSend_ngetSamples
|
rlm@0
|
296 (JNIEnv *env, jclass clazz, jlong device, jobject buffer, jint position,
|
rlm@0
|
297 jint samples, jint n){
|
rlm@0
|
298 UNUSED(clazz);
|
rlm@0
|
299
|
rlm@0
|
300 ALvoid *buffer_address =
|
rlm@0
|
301 ((ALbyte *)(((char*)(*env)->GetDirectBufferAddress(env, buffer)) + position));
|
rlm@0
|
302 ALCdevice *recorder = (ALCdevice*) ((intptr_t)device);
|
rlm@0
|
303 send_data *data = (send_data*)recorder->ExtraData;
|
rlm@0
|
304 if ((ALuint)n > data->numContexts){return;}
|
rlm@0
|
305 if ((uint) samples > data->size){
|
rlm@0
|
306 samples = (int) data->size;
|
rlm@0
|
307 }
|
rlm@0
|
308 memcpy(buffer_address, data->contexts[n]->renderBuffer, samples*sizeof(ALfloat));
|
rlm@0
|
309 }
|
rlm@0
|
310
|
rlm@0
|
311 /*
|
rlm@0
|
312 * Class: com_aurellem_capture_AudioSend
|
rlm@0
|
313 * Method: naddListener
|
rlm@0
|
314 * Signature: (J)V
|
rlm@0
|
315 */
|
rlm@0
|
316 JNIEXPORT void JNICALL Java_com_aurellem_capture_AudioSend_naddListener
|
rlm@0
|
317 (JNIEnv *env, jclass clazz, jlong device){
|
rlm@0
|
318 UNUSED(env); UNUSED(clazz);
|
rlm@0
|
319 printf("creating new context via naddListener\n");
|
rlm@0
|
320 ALCdevice *Device = (ALCdevice*) ((intptr_t)device);
|
rlm@0
|
321 ALCcontext *new = alcCreateContext(Device, NULL);
|
rlm@0
|
322 addContext(Device, new);
|
rlm@0
|
323 }
|
rlm@0
|
324
|
rlm@0
|
325 /*
|
rlm@0
|
326 * Class: com_aurellem_capture_AudioSend
|
rlm@0
|
327 * Method: nsetNthListener3f
|
rlm@0
|
328 * Signature: (IFFFJI)V
|
rlm@0
|
329 */
|
rlm@0
|
330 JNIEXPORT void JNICALL Java_com_aurellem_capture_AudioSend_nsetNthListener3f
|
rlm@0
|
331 (JNIEnv *env, jclass clazz, jint param,
|
rlm@0
|
332 jfloat v1, jfloat v2, jfloat v3, jlong device, jint contextNum){
|
rlm@0
|
333 UNUSED(env);UNUSED(clazz);
|
rlm@0
|
334
|
rlm@0
|
335 ALCdevice *Device = (ALCdevice*) ((intptr_t)device);
|
rlm@0
|
336 send_data *data = (send_data*)Device->ExtraData;
|
rlm@0
|
337
|
rlm@0
|
338 ALCcontext *current = alcGetCurrentContext();
|
rlm@0
|
339 if ((ALuint)contextNum > data->numContexts){return;}
|
rlm@0
|
340 alcMakeContextCurrent(data->contexts[contextNum]->ctx);
|
rlm@0
|
341 alListener3f(param, v1, v2, v3);
|
rlm@0
|
342 alcMakeContextCurrent(current);
|
rlm@0
|
343 }
|
rlm@0
|
344
|
rlm@0
|
345 /*
|
rlm@0
|
346 * Class: com_aurellem_capture_AudioSend
|
rlm@0
|
347 * Method: nsetNthListenerf
|
rlm@0
|
348 * Signature: (IFJI)V
|
rlm@0
|
349 */
|
rlm@0
|
350 JNIEXPORT void JNICALL Java_com_aurellem_capture_AudioSend_nsetNthListenerf
|
rlm@0
|
351 (JNIEnv *env, jclass clazz, jint param, jfloat v1, jlong device,
|
rlm@0
|
352 jint contextNum){
|
rlm@0
|
353
|
rlm@0
|
354 UNUSED(env);UNUSED(clazz);
|
rlm@0
|
355
|
rlm@0
|
356 ALCdevice *Device = (ALCdevice*) ((intptr_t)device);
|
rlm@0
|
357 send_data *data = (send_data*)Device->ExtraData;
|
rlm@0
|
358
|
rlm@0
|
359 ALCcontext *current = alcGetCurrentContext();
|
rlm@0
|
360 if ((ALuint)contextNum > data->numContexts){return;}
|
rlm@0
|
361 alcMakeContextCurrent(data->contexts[contextNum]->ctx);
|
rlm@0
|
362 alListenerf(param, v1);
|
rlm@0
|
363 alcMakeContextCurrent(current);
|
rlm@0
|
364 }
|
rlm@0
|
365
|
rlm@0
|
366 /*
|
rlm@0
|
367 * Class: com_aurellem_capture_AudioSend
|
rlm@0
|
368 * Method: ninitDevice
|
rlm@0
|
369 * Signature: (J)V
|
rlm@0
|
370 */
|
rlm@0
|
371 JNIEXPORT void JNICALL Java_com_aurellem_capture_AudioSend_ninitDevice
|
rlm@0
|
372 (JNIEnv *env, jclass clazz, jlong device){
|
rlm@0
|
373 UNUSED(env);UNUSED(clazz);
|
rlm@0
|
374
|
rlm@0
|
375 ALCdevice *Device = (ALCdevice*) ((intptr_t)device);
|
rlm@0
|
376 init(Device);
|
rlm@0
|
377
|
rlm@0
|
378 }
|
rlm@0
|
379
|
rlm@0
|
380
|
rlm@0
|
381 //////////////////// Device Initilization / Management
|
rlm@0
|
382
|
rlm@0
|
383 static const ALCchar sendDevice[] = "Multiple Audio Send";
|
rlm@0
|
384
|
rlm@0
|
385 static ALCboolean send_open_playback(ALCdevice *device,
|
rlm@0
|
386 const ALCchar *deviceName)
|
rlm@0
|
387 {
|
rlm@0
|
388 send_data *data;
|
rlm@0
|
389 // stop any buffering for stdout, so that I can
|
rlm@0
|
390 // see the printf statements in my terminal immediatley
|
rlm@0
|
391 setbuf(stdout, NULL);
|
rlm@0
|
392
|
rlm@0
|
393 if(!deviceName)
|
rlm@0
|
394 deviceName = sendDevice;
|
rlm@0
|
395 else if(strcmp(deviceName, sendDevice) != 0)
|
rlm@0
|
396 return ALC_FALSE;
|
rlm@0
|
397 data = (send_data*)calloc(1, sizeof(*data));
|
rlm@0
|
398 device->szDeviceName = strdup(deviceName);
|
rlm@0
|
399 device->ExtraData = data;
|
rlm@0
|
400 return ALC_TRUE;
|
rlm@0
|
401 }
|
rlm@0
|
402
|
rlm@0
|
403 static void send_close_playback(ALCdevice *device)
|
rlm@0
|
404 {
|
rlm@0
|
405 send_data *data = (send_data*)device->ExtraData;
|
rlm@0
|
406 alcMakeContextCurrent(NULL);
|
rlm@0
|
407 ALuint i;
|
rlm@0
|
408 // Destroy all slave contexts. LWJGL will take care of
|
rlm@0
|
409 // its own context.
|
rlm@0
|
410 for (i = 1; i < data->numContexts; i++){
|
rlm@0
|
411 context_data *ctxData = data->contexts[i];
|
rlm@0
|
412 alcDestroyContext(ctxData->ctx);
|
rlm@0
|
413 free(ctxData->renderBuffer);
|
rlm@0
|
414 free(ctxData);
|
rlm@0
|
415 }
|
rlm@0
|
416 free(data);
|
rlm@0
|
417 device->ExtraData = NULL;
|
rlm@0
|
418 }
|
rlm@0
|
419
|
rlm@0
|
420 static ALCboolean send_reset_playback(ALCdevice *device)
|
rlm@0
|
421 {
|
rlm@0
|
422 send_data *data = (send_data*)device->ExtraData;
|
rlm@0
|
423 ALuint channels=0, bits=0;
|
rlm@0
|
424 device->FmtType = DevFmtShort;
|
rlm@0
|
425 bits = BytesFromDevFmt(device->FmtType) * 8;
|
rlm@0
|
426 channels = ChannelsFromDevFmt(device->FmtChans);
|
rlm@0
|
427 data->size = device->UpdateSize * channels * bits / 8;
|
rlm@0
|
428
|
rlm@0
|
429 return ALC_TRUE;
|
rlm@0
|
430 }
|
rlm@0
|
431
|
rlm@0
|
432 static void send_stop_playback(ALCdevice *Device){
|
rlm@0
|
433 UNUSED(Device);
|
rlm@0
|
434 }
|
rlm@0
|
435
|
rlm@0
|
436 static const BackendFuncs send_funcs = {
|
rlm@0
|
437 send_open_playback,
|
rlm@0
|
438 send_close_playback,
|
rlm@0
|
439 send_reset_playback,
|
rlm@0
|
440 send_stop_playback,
|
rlm@0
|
441 NULL,
|
rlm@0
|
442 NULL, /* These would be filled with functions to */
|
rlm@0
|
443 NULL, /* handle capturing audio if we we into that */
|
rlm@0
|
444 NULL, /* sort of thing... */
|
rlm@0
|
445 NULL,
|
rlm@0
|
446 NULL
|
rlm@0
|
447 };
|
rlm@0
|
448
|
rlm@0
|
449 ALCboolean alc_send_init(BackendFuncs *func_list){
|
rlm@0
|
450 *func_list = send_funcs;
|
rlm@0
|
451 return ALC_TRUE;
|
rlm@0
|
452 }
|
rlm@0
|
453
|
rlm@0
|
454 void alc_send_deinit(void){}
|
rlm@0
|
455
|
rlm@0
|
456 void alc_send_probe(enum DevProbe type)
|
rlm@0
|
457 {
|
rlm@0
|
458 switch(type)
|
rlm@0
|
459 {
|
rlm@0
|
460 case DEVICE_PROBE:
|
rlm@0
|
461 AppendDeviceList(sendDevice);
|
rlm@0
|
462 break;
|
rlm@0
|
463 case ALL_DEVICE_PROBE:
|
rlm@0
|
464 AppendAllDeviceList(sendDevice);
|
rlm@0
|
465 break;
|
rlm@0
|
466 case CAPTURE_DEVICE_PROBE:
|
rlm@0
|
467 break;
|
rlm@0
|
468 }
|
rlm@0
|
469 }
|
rlm@0
|
470
|
rlm@0
|
471
|
rlm@0
|
472
|