LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: Trouble with FSound.FSOUND_GetCurrentLevels()  (Read 12753 times)

bvpeck

  • Newbie
  • *
  • Offline Offline
  • Posts: 3
Trouble with FSound.FSOUND_GetCurrentLevels()
« on: September 05, 2007, 04:02:46 »

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:
Code: [Select]
*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():
Code: [Select]
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:
Code: [Select]
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.
Logged

Matzon

  • Demigod
  • *****
  • Offline Offline
  • Posts: 2242
Re: Trouble with FSound.FSOUND_GetCurrentLevels()
« Reply #1 on: September 05, 2007, 06:54:06 »

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...

bvpeck

  • Newbie
  • *
  • Offline Offline
  • Posts: 3
Re: Trouble with FSound.FSOUND_GetCurrentLevels()
« Reply #2 on: September 05, 2007, 13:56:13 »

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.
Logged

Matzon

  • Demigod
  • *****
  • Offline Offline
  • Posts: 2242
Re: Trouble with FSound.FSOUND_GetCurrentLevels()
« Reply #3 on: September 05, 2007, 18:10:22 »

I modified org.lwjgl.test.fmod3.StreamPlayerMemory, and replaced the sleep line with:

Code: [Select]
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.

bvpeck

  • Newbie
  • *
  • Offline Offline
  • Posts: 3
Re: Trouble with FSound.FSOUND_GetCurrentLevels()
« Reply #4 on: September 05, 2007, 19:29:21 »

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?
Logged

Matzon

  • Demigod
  • *****
  • Offline Offline
  • Posts: 2242
Re: Trouble with FSound.FSOUND_GetCurrentLevels()
« Reply #5 on: September 05, 2007, 19:38:30 »

you need to allocate direct buffers using allocateDirect.