So I am on an Intel Mac using LWJGL release 1.1.2, and I am creating a FMOD sound stream to play an MP3 file. I want to get the left/right level data from the channel that the stream is playing from using FSound.FSOUND_GetCurrentLevels().
So I make a stream object following the FMOD example on the website:
*load MP3 file into bytebuffer called data*
stream = FSound.FSOUND_Stream_Open(data, FSound.FSOUND_LOADMEMORY);
And I start playing this stream on channel 0. The loading and playing of the stream works because a half second or so of the song plays before the program crashes.
I have a global FloatBuffer called l_r that I create using FloatBuffer.allocate(2) (One float for each side, left and right).
Here is the code for testing GetCurrentLevels():
System.out.println("here we go...");
// Get the current levels for channel 0, place values in FloatBuffer l_r
FSound.FSOUND_GetCurrentLevels(0, l_r);
System.out.println("success!?");
The output:
here we go...
Invalid memory access of location 00000004 eip=127055a3
I tried putting the code in a try/catch to get a stack trace, but no dice. Any ideas? Thanks.
Sounds like a native code issue - either in fmod or in the binding. Nothing you can try/catch.
I'll take a peek at the code tonight...
Ok, thanks. Just for further reference I am using the jar and native files for FMOD that came with the lwjgl 1.1.2 optional release.
I modified org.lwjgl.test.fmod3.StreamPlayerMemory, and replaced the sleep line with:
FloatBuffer lr = BufferUtils.createFloatBuffer(2);
try {
while(length > 0) {
FSound.FSOUND_GetCurrentLevels(0, lr);
System.out.println("l: " + lr.get(0) + ", r: " + lr.get(1));
Thread.sleep(1000);
length -= 1000;
}
} catch (InterruptedException inte) {
}
and it seems to work fine.
Thanks for the help! I was creating my FloatBuffer by calling java.nio.FloatBuffer.allocate(), but when I used lwjgl.BufferUtils.createFloatBuffer() it works. Can someone explain the difference between the two and why the second works?
you need to allocate direct buffers using allocateDirect.