Programming => OpenAL => Topic started by: Damian3395 on January 17, 2015, 22:57:59

Title: LWJGL 3
Post by: Damian3395 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.
Title: Re: LWJGL 3
Post by: kappa 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.
Title: Re: LWJGL 3
Post by: Damian3395 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
Title: Re: LWJGL 3
Post by: SHC 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. (https://github.com/sriharshachilakapati/SilenceEngine/blob/master/src/main/java/com/shc/silenceengine/audio/formats/WaveReader.java)
Title: Re: LWJGL 3
Post by: Damian3395 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.
Title: Re: LWJGL 3
Post by: SHC on January 22, 2015, 04:20:20
I get that same error as well, but it simply works fine.
Title: Re: LWJGL 3
Post by: abcdef 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)

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();




Title: Re: LWJGL 3
Post by: SHC on January 22, 2015, 08:54:14

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 (https://github.com/LWJGL/lwjgl3/blob/master/src/core/org/lwjgl/openal/ALContext.java#L98) 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(sync ? ALC10.ALC_TRUE : ALC10.ALC_FALSE);


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 (https://github.com/LWJGL/lwjgl3/blob/master/src/core/org/lwjgl/openal/ALContext.java#L84) 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.
Title: Re: LWJGL 3
Post by: abcdef on January 22, 2015, 12:28:03

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.