LWJGL Forum

Programming => OpenAL => Topic started by: ksabo_lwjgl on May 20, 2007, 04:56:30

Title: native c code is int casting a byte array
Post by: ksabo_lwjgl on May 20, 2007, 04:56:30
/*
* Class:     org_lwjgl_openal_ALC11
* Method:    nalcCaptureSamples
* Signature: (JLjava/nio/ByteBuffer;I)V
*/
static void JNICALL Java_org_lwjgl_openal_ALC11_nalcCaptureSamples(JNIEnv *env, jclass clazz, jlong device, jobject buffer, jint position, jint samples) {
ALuint *buffer_address = ((ALuint *)(*env)->GetDirectBufferAddress(env, buffer)) + position;
alcCaptureSamples((ALCdevice*) ((intptr_t)device), buffer_address, samples);
}


it's suppose to be a byte array so I'm getting JVM crashes when my buffer reaches 25%.

I also noticed that all the AL11 things dont check for errors after calls like most of the al10 and alc10 methods do. Not sure if this was intentional or not. just wanted to mention it.

thanks,
karl
Title: Re: native c code is int casting a byte array
Post by: Matzon on May 20, 2007, 05:36:38
I'll investigate this asap
Title: Re: native c code is int casting a byte array
Post by: Matzon on May 20, 2007, 06:09:31
I am not sure there are any errors in the code actually - the native code deals with address locations and stuff like that.
From my point of view, you're passing a too high sample count and the alcCaptureSamples methods is probably overwriting your buffer argument.

For this to be safe, the device probably has to store the arguments passed to alcCaptureOpenDevice and ensure that the size of samples is correct.
Note that the ALCCaptureTest works flawlessly.

As for error checking, thats in ALC code and casued by the fact that its hand coded and the other stuff is generated. I will add some error checks.
Title: Re: native c code is int casting a byte array
Post by: ksabo_lwjgl on May 20, 2007, 16:12:20
hmm ok thanks Matzon. Ill check out the example and play around some more.  I was just testing and no matter how big i made my bytebuffer when i set it's position to around 25% it's capacity i would get a JVM crash.

-karl
Title: Re: native c code is int casting a byte array
Post by: ksabo_lwjgl on May 20, 2007, 16:20:36
actually now that i think about it that is the exact problem

((ALuint *)(*env)->GetDirectBufferAddress(env, buffer)) + position;

you int cast the pointer and then add the position. So now every position offset is multiplied by 4.  The reason your example works fine is you never set the position to something other than 0.

-karl
Title: Re: native c code is int casting a byte array
Post by: ksabo_lwjgl on May 20, 2007, 17:18:34
capture samples should look like alBufferData:

static void JNICALL Java_org_lwjgl_openal_AL10_nalBufferData(JNIEnv *env, jclass clazz, jint buffer, jint format, jobject data, jint data_position, jint size, jint freq) {
ALvoid *data_address = ((ALvoid *)(((char *)(*env)->GetDirectBufferAddress(env, data)) + data_position));
alBufferData(buffer, format, data_address, size, freq);
}
Title: Re: native c code is int casting a byte array
Post by: Matzon on May 20, 2007, 17:49:04
sry - fixed in trunk