Mercurial > audio-send
diff 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 |
line wrap: on
line diff
1.1 --- a/Alc/backends/send.c Mon Oct 31 03:33:37 2011 -0700 1.2 +++ b/Alc/backends/send.c Mon Oct 31 07:44:02 2011 -0700 1.3 @@ -188,7 +188,9 @@ 1.4 // create context_data and add it to the main array 1.5 context_data *ctxData; 1.6 ctxData = (context_data*)calloc(1, sizeof(*ctxData)); 1.7 - ctxData->renderBuffer = malloc(data->size); 1.8 + ctxData->renderBuffer = 1.9 + malloc(BytesFromDevFmt(Device->FmtType) * 1.10 + Device->NumChan * Device->UpdateSize); 1.11 ctxData->ctx = context; 1.12 1.13 data->contexts[data->numContexts] = ctxData; 1.14 @@ -302,10 +304,19 @@ 1.15 ALCdevice *recorder = (ALCdevice*) ((intptr_t)device); 1.16 send_data *data = (send_data*)recorder->ExtraData; 1.17 if ((ALuint)n > data->numContexts){return;} 1.18 - if ((uint) samples > data->size){ 1.19 - samples = (int) data->size; 1.20 - } 1.21 - memcpy(buffer_address, data->contexts[n]->renderBuffer, samples*sizeof(ALfloat)); 1.22 + //if ((uint) samples > data->size){ 1.23 + // samples = (int) data->size; 1.24 + //} 1.25 + printf("Want %d samples for listener %d\n", samples, n); 1.26 + printf("Device's format type is %d bytes per sample,\n", 1.27 + BytesFromDevFmt(recorder->FmtType)); 1.28 + printf("and it has %d channels, making for %d requested bytes\n", 1.29 + recorder->NumChan, 1.30 + BytesFromDevFmt(recorder->FmtType) * recorder->NumChan * samples); 1.31 + 1.32 + memcpy(buffer_address, data->contexts[n]->renderBuffer, 1.33 + BytesFromDevFmt(recorder->FmtType) * recorder->NumChan * samples); 1.34 + //samples*sizeof(ALfloat)); 1.35 } 1.36 1.37 /* 1.38 @@ -378,6 +389,51 @@ 1.39 } 1.40 1.41 1.42 +/* 1.43 + * Class: com_aurellem_send_AudioSend 1.44 + * Method: ngetAudioFormat 1.45 + * Signature: (J)Ljavax/sound/sampled/AudioFormat; 1.46 + */ 1.47 +JNIEXPORT jobject JNICALL Java_com_aurellem_send_AudioSend_ngetAudioFormat 1.48 +(JNIEnv *env, jclass clazz, jlong device){ 1.49 + UNUSED(clazz); 1.50 + jclass AudioFormatClass = 1.51 + (*env)->FindClass(env, "javax/sound/sampled/AudioFormat"); 1.52 + jmethodID AudioFormatConstructor = 1.53 + (*env)->GetMethodID(env, AudioFormatClass, "<init>", "(FIIZZ)V"); 1.54 + 1.55 + ALCdevice *Device = (ALCdevice*) ((intptr_t)device); 1.56 + 1.57 + //float frequency 1.58 + 1.59 + int isSigned; 1.60 + switch (Device->FmtType) 1.61 + { 1.62 + case DevFmtUByte: 1.63 + case DevFmtUShort: isSigned = 0; break; 1.64 + default : isSigned = 1; 1.65 + } 1.66 + float frequency = Device->Frequency; 1.67 + int bitsPerFrame = (8 * BytesFromDevFmt(Device->FmtType)); 1.68 + int channels = Device->NumChan; 1.69 + 1.70 + 1.71 + printf("freq = %f, bpf = %d, channels = %d, signed? = %d\n", 1.72 + frequency, bitsPerFrame, channels, isSigned); 1.73 + 1.74 + jobject format = (*env)-> 1.75 + NewObject( 1.76 + env,AudioFormatClass,AudioFormatConstructor, 1.77 + frequency, 1.78 + bitsPerFrame, 1.79 + channels, 1.80 + isSigned, 1.81 + 0); 1.82 + return format; 1.83 +} 1.84 + 1.85 + 1.86 + 1.87 //////////////////// Device Initilization / Management 1.88 1.89 static const ALCchar sendDevice[] = "Multiple Audio Send"; 1.90 @@ -419,13 +475,13 @@ 1.91 1.92 static ALCboolean send_reset_playback(ALCdevice *device) 1.93 { 1.94 - send_data *data = (send_data*)device->ExtraData; 1.95 - ALuint channels=0, bits=0; 1.96 - device->FmtType = DevFmtShort; 1.97 - bits = BytesFromDevFmt(device->FmtType) * 8; 1.98 - channels = ChannelsFromDevFmt(device->FmtChans); 1.99 - data->size = device->UpdateSize * channels * bits / 8; 1.100 - 1.101 + //send_data *data = (send_data*)device->ExtraData; 1.102 + //ALuint channels=0, bits=0; 1.103 + //device->FmtType = DevFmtShort; 1.104 + //bits = BytesFromDevFmt(device->FmtType) * 8; 1.105 + //channels = ChannelsFromDevFmt(device->FmtChans); 1.106 + //data->size = device->UpdateSize * channels * bits / 8; 1.107 + SetDefaultWFXChannelOrder(device); 1.108 return ALC_TRUE; 1.109 } 1.110