Mercurial > audio-send
comparison Alc/backends/send.c @ 13:92b416b4e027
fixed all problems for 16 bit mono output
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 31 Oct 2011 07:44:02 -0700 |
parents | 37f25cb34196 |
children | 63312ec4a2bf |
comparison
equal
deleted
inserted
replaced
12:9558b856ebdf | 13:92b416b4e027 |
---|---|
186 data->maxContexts = newMaxContexts; | 186 data->maxContexts = newMaxContexts; |
187 } | 187 } |
188 // create context_data and add it to the main array | 188 // create context_data and add it to the main array |
189 context_data *ctxData; | 189 context_data *ctxData; |
190 ctxData = (context_data*)calloc(1, sizeof(*ctxData)); | 190 ctxData = (context_data*)calloc(1, sizeof(*ctxData)); |
191 ctxData->renderBuffer = malloc(data->size); | 191 ctxData->renderBuffer = |
192 malloc(BytesFromDevFmt(Device->FmtType) * | |
193 Device->NumChan * Device->UpdateSize); | |
192 ctxData->ctx = context; | 194 ctxData->ctx = context; |
193 | 195 |
194 data->contexts[data->numContexts] = ctxData; | 196 data->contexts[data->numContexts] = ctxData; |
195 data->numContexts++; | 197 data->numContexts++; |
196 } | 198 } |
300 ALvoid *buffer_address = | 302 ALvoid *buffer_address = |
301 ((ALbyte *)(((char*)(*env)->GetDirectBufferAddress(env, buffer)) + position)); | 303 ((ALbyte *)(((char*)(*env)->GetDirectBufferAddress(env, buffer)) + position)); |
302 ALCdevice *recorder = (ALCdevice*) ((intptr_t)device); | 304 ALCdevice *recorder = (ALCdevice*) ((intptr_t)device); |
303 send_data *data = (send_data*)recorder->ExtraData; | 305 send_data *data = (send_data*)recorder->ExtraData; |
304 if ((ALuint)n > data->numContexts){return;} | 306 if ((ALuint)n > data->numContexts){return;} |
305 if ((uint) samples > data->size){ | 307 //if ((uint) samples > data->size){ |
306 samples = (int) data->size; | 308 // samples = (int) data->size; |
307 } | 309 //} |
308 memcpy(buffer_address, data->contexts[n]->renderBuffer, samples*sizeof(ALfloat)); | 310 printf("Want %d samples for listener %d\n", samples, n); |
311 printf("Device's format type is %d bytes per sample,\n", | |
312 BytesFromDevFmt(recorder->FmtType)); | |
313 printf("and it has %d channels, making for %d requested bytes\n", | |
314 recorder->NumChan, | |
315 BytesFromDevFmt(recorder->FmtType) * recorder->NumChan * samples); | |
316 | |
317 memcpy(buffer_address, data->contexts[n]->renderBuffer, | |
318 BytesFromDevFmt(recorder->FmtType) * recorder->NumChan * samples); | |
319 //samples*sizeof(ALfloat)); | |
309 } | 320 } |
310 | 321 |
311 /* | 322 /* |
312 * Class: com_aurellem_send_AudioSend | 323 * Class: com_aurellem_send_AudioSend |
313 * Method: naddListener | 324 * Method: naddListener |
374 | 385 |
375 ALCdevice *Device = (ALCdevice*) ((intptr_t)device); | 386 ALCdevice *Device = (ALCdevice*) ((intptr_t)device); |
376 init(Device); | 387 init(Device); |
377 | 388 |
378 } | 389 } |
390 | |
391 | |
392 /* | |
393 * Class: com_aurellem_send_AudioSend | |
394 * Method: ngetAudioFormat | |
395 * Signature: (J)Ljavax/sound/sampled/AudioFormat; | |
396 */ | |
397 JNIEXPORT jobject JNICALL Java_com_aurellem_send_AudioSend_ngetAudioFormat | |
398 (JNIEnv *env, jclass clazz, jlong device){ | |
399 UNUSED(clazz); | |
400 jclass AudioFormatClass = | |
401 (*env)->FindClass(env, "javax/sound/sampled/AudioFormat"); | |
402 jmethodID AudioFormatConstructor = | |
403 (*env)->GetMethodID(env, AudioFormatClass, "<init>", "(FIIZZ)V"); | |
404 | |
405 ALCdevice *Device = (ALCdevice*) ((intptr_t)device); | |
406 | |
407 //float frequency | |
408 | |
409 int isSigned; | |
410 switch (Device->FmtType) | |
411 { | |
412 case DevFmtUByte: | |
413 case DevFmtUShort: isSigned = 0; break; | |
414 default : isSigned = 1; | |
415 } | |
416 float frequency = Device->Frequency; | |
417 int bitsPerFrame = (8 * BytesFromDevFmt(Device->FmtType)); | |
418 int channels = Device->NumChan; | |
419 | |
420 | |
421 printf("freq = %f, bpf = %d, channels = %d, signed? = %d\n", | |
422 frequency, bitsPerFrame, channels, isSigned); | |
423 | |
424 jobject format = (*env)-> | |
425 NewObject( | |
426 env,AudioFormatClass,AudioFormatConstructor, | |
427 frequency, | |
428 bitsPerFrame, | |
429 channels, | |
430 isSigned, | |
431 0); | |
432 return format; | |
433 } | |
434 | |
379 | 435 |
380 | 436 |
381 //////////////////// Device Initilization / Management | 437 //////////////////// Device Initilization / Management |
382 | 438 |
383 static const ALCchar sendDevice[] = "Multiple Audio Send"; | 439 static const ALCchar sendDevice[] = "Multiple Audio Send"; |
417 device->ExtraData = NULL; | 473 device->ExtraData = NULL; |
418 } | 474 } |
419 | 475 |
420 static ALCboolean send_reset_playback(ALCdevice *device) | 476 static ALCboolean send_reset_playback(ALCdevice *device) |
421 { | 477 { |
422 send_data *data = (send_data*)device->ExtraData; | 478 //send_data *data = (send_data*)device->ExtraData; |
423 ALuint channels=0, bits=0; | 479 //ALuint channels=0, bits=0; |
424 device->FmtType = DevFmtShort; | 480 //device->FmtType = DevFmtShort; |
425 bits = BytesFromDevFmt(device->FmtType) * 8; | 481 //bits = BytesFromDevFmt(device->FmtType) * 8; |
426 channels = ChannelsFromDevFmt(device->FmtChans); | 482 //channels = ChannelsFromDevFmt(device->FmtChans); |
427 data->size = device->UpdateSize * channels * bits / 8; | 483 //data->size = device->UpdateSize * channels * bits / 8; |
428 | 484 SetDefaultWFXChannelOrder(device); |
429 return ALC_TRUE; | 485 return ALC_TRUE; |
430 } | 486 } |
431 | 487 |
432 static void send_stop_playback(ALCdevice *Device){ | 488 static void send_stop_playback(ALCdevice *Device){ |
433 UNUSED(Device); | 489 UNUSED(Device); |