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