Main Menu

LWJGL 3

Started by Damian3395, January 17, 2015, 22:57:59

Previous topic - Next topic

Damian3395

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.

kappa

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.

Damian3395

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

SHC

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

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.

SHC

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

abcdef

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)

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

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

SHC

@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

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.

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

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