annotate Alc/backends/send.c @ 14:63312ec4a2bf

limit to 16bit mono for now.
author Robert McIntyre <rlm@mit.edu>
date Mon, 31 Oct 2011 08:01:08 -0700
parents 92b416b4e027
children 19ff95c69cf5
rev   line source
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@13 191 ctxData->renderBuffer =
rlm@13 192 malloc(BytesFromDevFmt(Device->FmtType) *
rlm@13 193 Device->NumChan * Device->UpdateSize);
rlm@0 194 ctxData->ctx = context;
rlm@0 195
rlm@0 196 data->contexts[data->numContexts] = ctxData;
rlm@0 197 data->numContexts++;
rlm@0 198 }
rlm@0 199
rlm@0 200
rlm@0 201 //////////////////// Context Switching
rlm@0 202
rlm@0 203 /* A device brings along with it two pieces of state
rlm@0 204 * which have to be swapped in and out with each context.
rlm@0 205 */
rlm@0 206 static void swapInContext(ALCdevice *Device, context_data *ctxData){
rlm@0 207 memcpy(Device->ClickRemoval, ctxData->ClickRemoval, sizeof(ALfloat)*MAXCHANNELS);
rlm@0 208 memcpy(Device->PendingClicks, ctxData->PendingClicks, sizeof(ALfloat)*MAXCHANNELS);
rlm@0 209 }
rlm@0 210
rlm@0 211 static void saveContext(ALCdevice *Device, context_data *ctxData){
rlm@0 212 memcpy(ctxData->ClickRemoval, Device->ClickRemoval, sizeof(ALfloat)*MAXCHANNELS);
rlm@0 213 memcpy(ctxData->PendingClicks, Device->PendingClicks, sizeof(ALfloat)*MAXCHANNELS);
rlm@0 214 }
rlm@0 215
rlm@0 216 static ALCcontext **currentContext;
rlm@0 217 static ALuint currentNumContext;
rlm@0 218
rlm@0 219 /* By default, all contexts are rendered at once for each call to aluMixData.
rlm@0 220 * This function uses the internals of the ALCdecice struct to temporarly
rlm@0 221 * cause aluMixData to only render the chosen context.
rlm@0 222 */
rlm@0 223 static void limitContext(ALCdevice *Device, ALCcontext *ctx){
rlm@0 224 currentContext = Device->Contexts;
rlm@0 225 currentNumContext = Device->NumContexts;
rlm@0 226 Device->Contexts = &ctx;
rlm@0 227 Device->NumContexts = 1;
rlm@0 228 }
rlm@0 229
rlm@0 230 static void unLimitContext(ALCdevice *Device){
rlm@0 231 Device->Contexts = currentContext;
rlm@0 232 Device->NumContexts = currentNumContext;
rlm@0 233 }
rlm@0 234
rlm@0 235
rlm@0 236 //////////////////// Main Device Loop
rlm@0 237
rlm@0 238 /* Establish the LWJGL context as the main context, which will
rlm@0 239 * be synchronized to all the slave contexts
rlm@0 240 */
rlm@0 241 static void init(ALCdevice *Device){
rlm@0 242 ALCcontext *masterContext = alcGetCurrentContext();
rlm@0 243 addContext(Device, masterContext);
rlm@0 244 }
rlm@0 245
rlm@0 246
rlm@0 247 static void renderData(ALCdevice *Device, int samples){
rlm@0 248 if(!Device->Connected){return;}
rlm@0 249 send_data *data = (send_data*)Device->ExtraData;
rlm@0 250 ALCcontext *current = alcGetCurrentContext();
rlm@0 251
rlm@0 252 ALuint i;
rlm@0 253 for (i = 1; i < data->numContexts; i++){
rlm@0 254 syncContexts(data->contexts[0]->ctx , data->contexts[i]->ctx);
rlm@0 255 }
rlm@0 256
rlm@0 257 if ((uint) samples > Device->UpdateSize){
rlm@0 258 printf("exceeding internal buffer size; dropping samples\n");
rlm@0 259 printf("requested %d; available %d\n", samples, Device->UpdateSize);
rlm@0 260 samples = (int) Device->UpdateSize;
rlm@0 261 }
rlm@0 262
rlm@0 263 for (i = 0; i < data->numContexts; i++){
rlm@0 264 context_data *ctxData = data->contexts[i];
rlm@0 265 ALCcontext *ctx = ctxData->ctx;
rlm@0 266 alcMakeContextCurrent(ctx);
rlm@0 267 limitContext(Device, ctx);
rlm@0 268 swapInContext(Device, ctxData);
rlm@0 269 aluMixData(Device, ctxData->renderBuffer, samples);
rlm@0 270 saveContext(Device, ctxData);
rlm@0 271 unLimitContext(Device);
rlm@0 272 }
rlm@0 273 alcMakeContextCurrent(current);
rlm@0 274 }
rlm@0 275
rlm@0 276
rlm@0 277 //////////////////// JNI Methods
rlm@0 278
rlm@7 279 #include "com_aurellem_send_AudioSend.h"
rlm@0 280
rlm@0 281 /*
rlm@7 282 * Class: com_aurellem_send_AudioSend
rlm@0 283 * Method: nstep
rlm@0 284 * Signature: (JI)V
rlm@0 285 */
rlm@7 286 JNIEXPORT void JNICALL Java_com_aurellem_send_AudioSend_nstep
rlm@0 287 (JNIEnv *env, jclass clazz, jlong device, jint samples){
rlm@0 288 UNUSED(env);UNUSED(clazz);UNUSED(device);
rlm@0 289 renderData((ALCdevice*)((intptr_t)device), samples);
rlm@0 290 }
rlm@0 291
rlm@0 292 /*
rlm@7 293 * Class: com_aurellem_send_AudioSend
rlm@0 294 * Method: ngetSamples
rlm@0 295 * Signature: (JLjava/nio/ByteBuffer;III)V
rlm@0 296 */
rlm@7 297 JNIEXPORT void JNICALL Java_com_aurellem_send_AudioSend_ngetSamples
rlm@0 298 (JNIEnv *env, jclass clazz, jlong device, jobject buffer, jint position,
rlm@0 299 jint samples, jint n){
rlm@0 300 UNUSED(clazz);
rlm@0 301
rlm@0 302 ALvoid *buffer_address =
rlm@0 303 ((ALbyte *)(((char*)(*env)->GetDirectBufferAddress(env, buffer)) + position));
rlm@0 304 ALCdevice *recorder = (ALCdevice*) ((intptr_t)device);
rlm@0 305 send_data *data = (send_data*)recorder->ExtraData;
rlm@0 306 if ((ALuint)n > data->numContexts){return;}
rlm@13 307 //if ((uint) samples > data->size){
rlm@13 308 // samples = (int) data->size;
rlm@13 309 //}
rlm@13 310 printf("Want %d samples for listener %d\n", samples, n);
rlm@13 311 printf("Device's format type is %d bytes per sample,\n",
rlm@13 312 BytesFromDevFmt(recorder->FmtType));
rlm@13 313 printf("and it has %d channels, making for %d requested bytes\n",
rlm@13 314 recorder->NumChan,
rlm@13 315 BytesFromDevFmt(recorder->FmtType) * recorder->NumChan * samples);
rlm@13 316
rlm@13 317 memcpy(buffer_address, data->contexts[n]->renderBuffer,
rlm@13 318 BytesFromDevFmt(recorder->FmtType) * recorder->NumChan * samples);
rlm@13 319 //samples*sizeof(ALfloat));
rlm@0 320 }
rlm@0 321
rlm@0 322 /*
rlm@7 323 * Class: com_aurellem_send_AudioSend
rlm@0 324 * Method: naddListener
rlm@0 325 * Signature: (J)V
rlm@0 326 */
rlm@7 327 JNIEXPORT void JNICALL Java_com_aurellem_send_AudioSend_naddListener
rlm@0 328 (JNIEnv *env, jclass clazz, jlong device){
rlm@0 329 UNUSED(env); UNUSED(clazz);
rlm@0 330 printf("creating new context via naddListener\n");
rlm@0 331 ALCdevice *Device = (ALCdevice*) ((intptr_t)device);
rlm@0 332 ALCcontext *new = alcCreateContext(Device, NULL);
rlm@0 333 addContext(Device, new);
rlm@0 334 }
rlm@0 335
rlm@0 336 /*
rlm@7 337 * Class: com_aurellem_send_AudioSend
rlm@0 338 * Method: nsetNthListener3f
rlm@0 339 * Signature: (IFFFJI)V
rlm@0 340 */
rlm@7 341 JNIEXPORT void JNICALL Java_com_aurellem_send_AudioSend_nsetNthListener3f
rlm@0 342 (JNIEnv *env, jclass clazz, jint param,
rlm@0 343 jfloat v1, jfloat v2, jfloat v3, jlong device, jint contextNum){
rlm@0 344 UNUSED(env);UNUSED(clazz);
rlm@0 345
rlm@0 346 ALCdevice *Device = (ALCdevice*) ((intptr_t)device);
rlm@0 347 send_data *data = (send_data*)Device->ExtraData;
rlm@0 348
rlm@0 349 ALCcontext *current = alcGetCurrentContext();
rlm@0 350 if ((ALuint)contextNum > data->numContexts){return;}
rlm@0 351 alcMakeContextCurrent(data->contexts[contextNum]->ctx);
rlm@0 352 alListener3f(param, v1, v2, v3);
rlm@0 353 alcMakeContextCurrent(current);
rlm@0 354 }
rlm@0 355
rlm@0 356 /*
rlm@7 357 * Class: com_aurellem_send_AudioSend
rlm@0 358 * Method: nsetNthListenerf
rlm@0 359 * Signature: (IFJI)V
rlm@0 360 */
rlm@7 361 JNIEXPORT void JNICALL Java_com_aurellem_send_AudioSend_nsetNthListenerf
rlm@0 362 (JNIEnv *env, jclass clazz, jint param, jfloat v1, jlong device,
rlm@0 363 jint contextNum){
rlm@0 364
rlm@0 365 UNUSED(env);UNUSED(clazz);
rlm@0 366
rlm@0 367 ALCdevice *Device = (ALCdevice*) ((intptr_t)device);
rlm@0 368 send_data *data = (send_data*)Device->ExtraData;
rlm@0 369
rlm@0 370 ALCcontext *current = alcGetCurrentContext();
rlm@0 371 if ((ALuint)contextNum > data->numContexts){return;}
rlm@0 372 alcMakeContextCurrent(data->contexts[contextNum]->ctx);
rlm@0 373 alListenerf(param, v1);
rlm@0 374 alcMakeContextCurrent(current);
rlm@0 375 }
rlm@0 376
rlm@0 377 /*
rlm@7 378 * Class: com_aurellem_send_AudioSend
rlm@0 379 * Method: ninitDevice
rlm@0 380 * Signature: (J)V
rlm@0 381 */
rlm@7 382 JNIEXPORT void JNICALL Java_com_aurellem_send_AudioSend_ninitDevice
rlm@0 383 (JNIEnv *env, jclass clazz, jlong device){
rlm@0 384 UNUSED(env);UNUSED(clazz);
rlm@0 385
rlm@0 386 ALCdevice *Device = (ALCdevice*) ((intptr_t)device);
rlm@0 387 init(Device);
rlm@0 388
rlm@0 389 }
rlm@0 390
rlm@0 391
rlm@13 392 /*
rlm@13 393 * Class: com_aurellem_send_AudioSend
rlm@13 394 * Method: ngetAudioFormat
rlm@13 395 * Signature: (J)Ljavax/sound/sampled/AudioFormat;
rlm@13 396 */
rlm@13 397 JNIEXPORT jobject JNICALL Java_com_aurellem_send_AudioSend_ngetAudioFormat
rlm@13 398 (JNIEnv *env, jclass clazz, jlong device){
rlm@13 399 UNUSED(clazz);
rlm@13 400 jclass AudioFormatClass =
rlm@13 401 (*env)->FindClass(env, "javax/sound/sampled/AudioFormat");
rlm@13 402 jmethodID AudioFormatConstructor =
rlm@13 403 (*env)->GetMethodID(env, AudioFormatClass, "<init>", "(FIIZZ)V");
rlm@13 404
rlm@13 405 ALCdevice *Device = (ALCdevice*) ((intptr_t)device);
rlm@13 406
rlm@13 407 //float frequency
rlm@13 408
rlm@13 409 int isSigned;
rlm@13 410 switch (Device->FmtType)
rlm@13 411 {
rlm@13 412 case DevFmtUByte:
rlm@13 413 case DevFmtUShort: isSigned = 0; break;
rlm@13 414 default : isSigned = 1;
rlm@13 415 }
rlm@13 416 float frequency = Device->Frequency;
rlm@13 417 int bitsPerFrame = (8 * BytesFromDevFmt(Device->FmtType));
rlm@13 418 int channels = Device->NumChan;
rlm@13 419
rlm@13 420
rlm@13 421 printf("freq = %f, bpf = %d, channels = %d, signed? = %d\n",
rlm@13 422 frequency, bitsPerFrame, channels, isSigned);
rlm@13 423
rlm@13 424 jobject format = (*env)->
rlm@13 425 NewObject(
rlm@13 426 env,AudioFormatClass,AudioFormatConstructor,
rlm@13 427 frequency,
rlm@13 428 bitsPerFrame,
rlm@13 429 channels,
rlm@13 430 isSigned,
rlm@13 431 0);
rlm@13 432 return format;
rlm@13 433 }
rlm@13 434
rlm@13 435
rlm@13 436
rlm@0 437 //////////////////// Device Initilization / Management
rlm@0 438
rlm@0 439 static const ALCchar sendDevice[] = "Multiple Audio Send";
rlm@0 440
rlm@0 441 static ALCboolean send_open_playback(ALCdevice *device,
rlm@0 442 const ALCchar *deviceName)
rlm@0 443 {
rlm@0 444 send_data *data;
rlm@0 445 // stop any buffering for stdout, so that I can
rlm@0 446 // see the printf statements in my terminal immediatley
rlm@0 447 setbuf(stdout, NULL);
rlm@0 448
rlm@0 449 if(!deviceName)
rlm@0 450 deviceName = sendDevice;
rlm@0 451 else if(strcmp(deviceName, sendDevice) != 0)
rlm@0 452 return ALC_FALSE;
rlm@0 453 data = (send_data*)calloc(1, sizeof(*data));
rlm@0 454 device->szDeviceName = strdup(deviceName);
rlm@0 455 device->ExtraData = data;
rlm@0 456 return ALC_TRUE;
rlm@0 457 }
rlm@0 458
rlm@0 459 static void send_close_playback(ALCdevice *device)
rlm@0 460 {
rlm@0 461 send_data *data = (send_data*)device->ExtraData;
rlm@0 462 alcMakeContextCurrent(NULL);
rlm@0 463 ALuint i;
rlm@0 464 // Destroy all slave contexts. LWJGL will take care of
rlm@0 465 // its own context.
rlm@0 466 for (i = 1; i < data->numContexts; i++){
rlm@0 467 context_data *ctxData = data->contexts[i];
rlm@0 468 alcDestroyContext(ctxData->ctx);
rlm@0 469 free(ctxData->renderBuffer);
rlm@0 470 free(ctxData);
rlm@0 471 }
rlm@0 472 free(data);
rlm@0 473 device->ExtraData = NULL;
rlm@0 474 }
rlm@0 475
rlm@0 476 static ALCboolean send_reset_playback(ALCdevice *device)
rlm@0 477 {
rlm@13 478 SetDefaultWFXChannelOrder(device);
rlm@0 479 return ALC_TRUE;
rlm@0 480 }
rlm@0 481
rlm@0 482 static void send_stop_playback(ALCdevice *Device){
rlm@0 483 UNUSED(Device);
rlm@0 484 }
rlm@0 485
rlm@0 486 static const BackendFuncs send_funcs = {
rlm@0 487 send_open_playback,
rlm@0 488 send_close_playback,
rlm@0 489 send_reset_playback,
rlm@0 490 send_stop_playback,
rlm@0 491 NULL,
rlm@0 492 NULL, /* These would be filled with functions to */
rlm@0 493 NULL, /* handle capturing audio if we we into that */
rlm@0 494 NULL, /* sort of thing... */
rlm@0 495 NULL,
rlm@0 496 NULL
rlm@0 497 };
rlm@0 498
rlm@0 499 ALCboolean alc_send_init(BackendFuncs *func_list){
rlm@0 500 *func_list = send_funcs;
rlm@0 501 return ALC_TRUE;
rlm@0 502 }
rlm@0 503
rlm@0 504 void alc_send_deinit(void){}
rlm@0 505
rlm@0 506 void alc_send_probe(enum DevProbe type)
rlm@0 507 {
rlm@0 508 switch(type)
rlm@0 509 {
rlm@0 510 case DEVICE_PROBE:
rlm@0 511 AppendDeviceList(sendDevice);
rlm@0 512 break;
rlm@0 513 case ALL_DEVICE_PROBE:
rlm@0 514 AppendAllDeviceList(sendDevice);
rlm@0 515 break;
rlm@0 516 case CAPTURE_DEVICE_PROBE:
rlm@0 517 break;
rlm@0 518 }
rlm@0 519 }
rlm@0 520
rlm@0 521
rlm@0 522