LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: LWJGL 3  (Read 3020 times)

Damian3395

  • Newbie
  • *
  • Offline Offline
  • Posts: 5
LWJGL 3
« on: January 17, 2015, 22:57:59 »

LWJGL 3 no longer supports WaveData in its utility folder, so how would I go about playing wav files in OpenAL, I have been looking around for tutorials in c++ to convert into java, but its hard to find one thats easy to understand for a new comer.
Logged

kappa

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1305
Re: LWJGL 3
« Reply #1 on: January 17, 2015, 23:36:16 »

LWJGL3 doesn't include the WaveData from LWJGL2 but it still works the same in LWJGL3, just grab it from the LWJGL2 source code and include it in your project.
Logged

Damian3395

  • Newbie
  • *
  • Offline Offline
  • Posts: 5
Re: LWJGL 3
« Reply #2 on: January 17, 2015, 23:54:09 »

Thanks for the advice, but I found a really nice project on GitHub that has helped me out a lot. This is what I was looking for, in case anyone else is looking for the same: https://github.com/worldsproject/Fluxware-Game-Engine/tree/master/src/sound
Logged

SHC

  • Regular nerd
  • **
  • Offline Offline
  • Posts: 93
Re: LWJGL 3
« Reply #3 on: January 18, 2015, 07:23:24 »

You can use JavaSound to read the samples into the OpenAL buffer. I think I have a decent enough implementation in my engine. You can see that in my WaveReader class.

Damian3395

  • Newbie
  • *
  • Offline Offline
  • Posts: 5
Re: LWJGL 3
« Reply #4 on: January 22, 2015, 03:09:03 »

I tried using both methods of OpenAL in the silenceEngine and the fluxware-game engine, but each time I tested the sound object, I keep get this same error:
AL lib: (EE) UpdateDeviceParams: Failed to set 44100hz, got 48000hz instead

I enjoyed learning from both methods, I am thinking about writing my own method of using openAL because I have been playing around with library and started to understand what each class file does. I think the hardest part is to figure out how to read a wav file and load it into a buffer for OpenAL to play.
Logged

SHC

  • Regular nerd
  • **
  • Offline Offline
  • Posts: 93
Re: LWJGL 3
« Reply #5 on: January 22, 2015, 04:20:20 »

I get that same error as well, but it simply works fine.

abcdef

  • Prolific Timewaster
  • ****
  • Offline Offline
  • Posts: 320
Re: LWJGL 3
« Reply #6 on: January 22, 2015, 07:08:55 »

For LWJGL3 this error would have been caused in the initiating process, the code snippet below is from the demo on github. If you created your own method then this is where you could try and code around the issue.

Supposedly you can ignore the ALC10.ALC_FREQUENCY attribute

You would then use (ALC10)

Code: [Select]
public static void alcGetInteger(long deviceHandle, int token, java.nio.IntBuffer dest)
token : ALC10.ALC_FREQUENCY

To get an array of the available frequencies (returned in the IntBuffer) which you can then pass as an argument when you create the buffer data

Code: [Select]
        IntBuffer attribs = ByteBuffer.allocateDirect(16 * (Integer.SIZE / Byte.SIZE)).order(ByteOrder.nativeOrder()).asIntBuffer();

        attribs.put(ALC10.ALC_FREQUENCY);
        attribs.put(44100);

        attribs.put(ALC10.ALC_REFRESH);
        attribs.put(60);

        attribs.put(ALC10.ALC_SYNC);
        attribs.put(ALC10.ALC_FALSE);

        attribs.put(0);
        attribs.flip();
Logged

SHC

  • Regular nerd
  • **
  • Offline Offline
  • Posts: 93
Re: LWJGL 3
« Reply #7 on: January 22, 2015, 08:54:14 »

@abcdef

To initialize the context, I'm calling the create method on ALContext class. This method calls the overloaded create method which is shown below. You can find this on Line #98 of ALContext.java

Code: [Select]
public static ALContext create(String deviceName, int frequency, int refresh, boolean sync) {
ALDevice device = ALDevice.create(deviceName);
IntBuffer attribs = BufferUtils.createIntBuffer(16);

attribs.put(ALC_FREQUENCY);
attribs.put(frequency);

attribs.put(ALC_REFRESH);
attribs.put(refresh);

attribs.put(ALC_SYNC);
attribs.put(sync ? ALC10.ALC_TRUE : ALC10.ALC_FALSE);

attribs.put(0);
attribs.flip();

long contextHandle = alcCreateContext(device.getPointer(), attribs);
return new ALContext(device, contextHandle);
}
And the create method that I call is the one you find on Line #84 of the same class, and looks like this.

Code: [Select]
public static ALContext create() {
return create(null, 44100, 60, false);
}
I'm just using the built-ins, which is just like the one you specified above, and it works too. The only problem is that error message, but I'm going to simply ignore that message, since I can hear the audio fine.

abcdef

  • Prolific Timewaster
  • ****
  • Offline Offline
  • Posts: 320
Re: LWJGL 3
« Reply #8 on: January 22, 2015, 12:28:03 »

@SHC

I don't think there is anything wrong with what you are doing  :)

I was just suggesting a way to remove the error if it was an issue. It was more of a suggestion to Damian3395 as he/she mentioned the error.
Logged