# HG changeset patch # User Robert McIntyre # Date 1320072242 25200 # Node ID 92b416b4e027291e1ee2923830dc00c144ffb735 # Parent 9558b856ebdf61f4904c5a6fa6e361a06d8d2fa4 fixed all problems for 16 bit mono output diff -r 9558b856ebdf -r 92b416b4e027 Alc/backends/send.c --- a/Alc/backends/send.c Mon Oct 31 03:33:37 2011 -0700 +++ b/Alc/backends/send.c Mon Oct 31 07:44:02 2011 -0700 @@ -188,7 +188,9 @@ // create context_data and add it to the main array context_data *ctxData; ctxData = (context_data*)calloc(1, sizeof(*ctxData)); - ctxData->renderBuffer = malloc(data->size); + ctxData->renderBuffer = + malloc(BytesFromDevFmt(Device->FmtType) * + Device->NumChan * Device->UpdateSize); ctxData->ctx = context; data->contexts[data->numContexts] = ctxData; @@ -302,10 +304,19 @@ ALCdevice *recorder = (ALCdevice*) ((intptr_t)device); send_data *data = (send_data*)recorder->ExtraData; if ((ALuint)n > data->numContexts){return;} - if ((uint) samples > data->size){ - samples = (int) data->size; - } - memcpy(buffer_address, data->contexts[n]->renderBuffer, samples*sizeof(ALfloat)); + //if ((uint) samples > data->size){ + // samples = (int) data->size; + //} + printf("Want %d samples for listener %d\n", samples, n); + printf("Device's format type is %d bytes per sample,\n", + BytesFromDevFmt(recorder->FmtType)); + printf("and it has %d channels, making for %d requested bytes\n", + recorder->NumChan, + BytesFromDevFmt(recorder->FmtType) * recorder->NumChan * samples); + + memcpy(buffer_address, data->contexts[n]->renderBuffer, + BytesFromDevFmt(recorder->FmtType) * recorder->NumChan * samples); + //samples*sizeof(ALfloat)); } /* @@ -378,6 +389,51 @@ } +/* + * Class: com_aurellem_send_AudioSend + * Method: ngetAudioFormat + * Signature: (J)Ljavax/sound/sampled/AudioFormat; + */ +JNIEXPORT jobject JNICALL Java_com_aurellem_send_AudioSend_ngetAudioFormat +(JNIEnv *env, jclass clazz, jlong device){ + UNUSED(clazz); + jclass AudioFormatClass = + (*env)->FindClass(env, "javax/sound/sampled/AudioFormat"); + jmethodID AudioFormatConstructor = + (*env)->GetMethodID(env, AudioFormatClass, "", "(FIIZZ)V"); + + ALCdevice *Device = (ALCdevice*) ((intptr_t)device); + + //float frequency + + int isSigned; + switch (Device->FmtType) + { + case DevFmtUByte: + case DevFmtUShort: isSigned = 0; break; + default : isSigned = 1; + } + float frequency = Device->Frequency; + int bitsPerFrame = (8 * BytesFromDevFmt(Device->FmtType)); + int channels = Device->NumChan; + + + printf("freq = %f, bpf = %d, channels = %d, signed? = %d\n", + frequency, bitsPerFrame, channels, isSigned); + + jobject format = (*env)-> + NewObject( + env,AudioFormatClass,AudioFormatConstructor, + frequency, + bitsPerFrame, + channels, + isSigned, + 0); + return format; +} + + + //////////////////// Device Initilization / Management static const ALCchar sendDevice[] = "Multiple Audio Send"; @@ -419,13 +475,13 @@ static ALCboolean send_reset_playback(ALCdevice *device) { - send_data *data = (send_data*)device->ExtraData; - ALuint channels=0, bits=0; - device->FmtType = DevFmtShort; - bits = BytesFromDevFmt(device->FmtType) * 8; - channels = ChannelsFromDevFmt(device->FmtChans); - data->size = device->UpdateSize * channels * bits / 8; - + //send_data *data = (send_data*)device->ExtraData; + //ALuint channels=0, bits=0; + //device->FmtType = DevFmtShort; + //bits = BytesFromDevFmt(device->FmtType) * 8; + //channels = ChannelsFromDevFmt(device->FmtChans); + //data->size = device->UpdateSize * channels * bits / 8; + SetDefaultWFXChannelOrder(device); return ALC_TRUE; } diff -r 9558b856ebdf -r 92b416b4e027 java/src/com/aurellem/send/AudioSend.java --- a/java/src/com/aurellem/send/AudioSend.java Mon Oct 31 03:33:37 2011 -0700 +++ b/java/src/com/aurellem/send/AudioSend.java Mon Oct 31 07:44:02 2011 -0700 @@ -2,6 +2,8 @@ import java.nio.ByteBuffer; +import javax.sound.sampled.AudioFormat; + public class AudioSend { private final long deviceID; @@ -75,4 +77,15 @@ nsetNthListenerf(pname, v1, this.deviceID, contextNum);} public static native void nsetNthListenerf(int pname, float v1, long device, int contextNum); + + /** + * Retrieve the AudioFormat which the device is using. This format is itself derived + * from the OpenAL config file under the "format" variable. + */ + public AudioFormat getAudioFormat(){ + return ngetAudioFormat(this.deviceID);} + public static native AudioFormat ngetAudioFormat(long device); + + + }