1
\$\begingroup\$

Whenever I research audio in LWJGL 3, they always use STB which can only load Ogg files. All of my audio files are in either WAV or MP3 format, and it would be annoying to have to convert all of them. Is there some other library or method I can use that would allow me to load these file formats?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

In LWJGL2 there was a loader class called org.lwjgl.util.WaveData, used for *.wav files, that is missing in LWJGL3. You can simply download the source of this class from the legacy LWJGL website and add it to your project. Replace org.lwjgl.LWJGLUtil.log() with System.out.println() in the source since LWJGLUtil does not exist in LWJGL3.

Also, if you are on JDK9 or later, you have to download three source files from the package com.sun.media.sound in JDK8 and put them into your project. The package needs to be renamed or you will get a loading error otherwise, since that package still exists in the current JDKs but is hidden.

Such classes are:

  • com.sun.media.sound.WaveFileReader.
  • com.sun.media.sound.WaveFileFormat.
  • com.sun.media.sound.SunFileReader.

Then you can write:

WaveData data = WaveData.create(url);
AL10.alBufferData(bufferHandle, data.format, data.data, data.samplerate);
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .