LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: [Beginner] Wav files are not playing  (Read 2677 times)

TotalSpelNerd

  • Newbie
  • *
  • Offline Offline
  • Posts: 11
[Beginner] Wav files are not playing
« on: February 03, 2015, 15:47:00 »

I just started working with sounds for a bit and can't wrap my head around why my code isn't working at all. Doesn't matter if I load the sound from resource folders or directly from a file from my computer. It can find the file (WaveData != null). I'm doing all the al code inside the main thread so it couldn't possibly be that either.

This is my current audio code (simplified)

Code: [Select]
public void createAudio(){
buffer = alGenBuffers();
WaveData data = WaveData.create(Audio.class.getResourceAsStream("/sounds/sound2.wav"));
alBufferData(buffer, data.format, data.data, data.samplerate); // Here I'm getting an invalid enum error, AL10.alGetError()==AL10.AL_INVALID_ENUM
data.dispose();
source = alGenSources();
alSourcei(source, AL_BUFFER, buffer);
}

public void play(){
alSourcePlay(source);
}

I tried looking for an answer on what invalid enum really is, but couldn't really find anything.

If anyone could explain the problem here, that would be nice :D

Edit: volume to the max doesn't work btw.

Thanks in advance
Logged

abcdef

  • Prolific Timewaster
  • ****
  • Offline Offline
  • Posts: 320
Re: [Beginner] Wav files are not playing
« Reply #1 on: February 03, 2015, 16:24:53 »

The issue is play() by itself won't play things continuously. If you have a render loop then call play() in that render loop, you should hear sound then.

Logged

TotalSpelNerd

  • Newbie
  • *
  • Offline Offline
  • Posts: 11
Re: [Beginner] Wav files are not playing
« Reply #2 on: February 03, 2015, 17:20:19 »

Yeah I know it doesn't call itself, that is not the problem. I call the play function when pressing the space button (still inside the main Thread and tried println to confirm that the key press is being called). Even tried moving the call into the render method, didn't work either, didn't think it would. It still seems to be a problem with alBufferData where I get a AL_INVALID_ENUM error or is that normal.
Logged

abcdef

  • Prolific Timewaster
  • ****
  • Offline Offline
  • Posts: 320
Re: [Beginner] Wav files are not playing
« Reply #3 on: February 03, 2015, 21:04:18 »

Have you tried the example from the wiki?
Logged

TotalSpelNerd

  • Newbie
  • *
  • Offline Offline
  • Posts: 11
Re: [Beginner] Wav files are not playing
« Reply #4 on: February 04, 2015, 17:09:29 »

Yeah I did try it, with my own files of course. Still didn't work.

After watching Oskar Veerhoeks tutorial on OpenAL (Episode 22) I downloaded the file he used for his coding and guess what. It worked, why did his wav file work but not mine? How can I check if the wav file I'm using works for LWJGL? How can I make it work for LWJGL?
Logged

abcdef

  • Prolific Timewaster
  • ****
  • Offline Offline
  • Posts: 320
Re: [Beginner] Wav files are not playing
« Reply #5 on: February 04, 2015, 19:23:50 »

you should be able to try it in VLC or windows media player to check it is valid
Logged

TotalSpelNerd

  • Newbie
  • *
  • Offline Offline
  • Posts: 11
Re: [Beginner] Wav files are not playing
« Reply #6 on: February 05, 2015, 06:26:50 »

But I can run the files in VLC and Windows Media Player, but I always get an invalid enum error when creating the other files. Is the files a used before too big or too small to use? First file I tried was 2.04kB with 24 bitrate, second one was 178kB with 2304 bitrate and the one that worked was 32kB with 705 bitrate.
Logged

abcdef

  • Prolific Timewaster
  • ****
  • Offline Offline
  • Posts: 320
Re: [Beginner] Wav files are not playing
« Reply #7 on: February 05, 2015, 09:54:44 »

What values do you have for

buffer
data.format
data.data (capacity / limit/position)
data.samplerate

before you make the call?
Logged

TotalSpelNerd

  • Newbie
  • *
  • Offline Offline
  • Posts: 11
Re: [Beginner] Wav files are not playing
« Reply #8 on: February 05, 2015, 15:57:34 »

This is the values that I'm getting from one sound file that didn't work:
Buffer=1 : data.format=0 : data.data=java.nio.DirectByteBuffer[pos=0 lim=182586 cap=182586] : data.samplerate=48000
This is the values that I'm getting from one sound file that did work:
Buffer=1 : data.format=4353 : data.data=java.nio.DirectByteBuffer[pos=0 lim=31744 cap=31744] : data.samplerate=44100

Only ran one audio file then launched the application again with the other file hence buffer=1 in both cases. From what I can see in this test data.format seems to be wrong, unless I'm totally mistaken.

Edit: Apparently the sound I'm trying to play is a Stereo sound with 24 bits which is not supported with the WaveData.class, only 8 and 16.

This is the code that is executed inside WaveFile:
Code: [Select]
if (audioformat.getSampleSizeInBits() == 8) {
channels = AL10.AL_FORMAT_STEREO8;
} else if (audioformat.getSampleSizeInBits() == 16) {
channels = AL10.AL_FORMAT_STEREO16;
} else {
System.out.println(audioformat.getSampleSizeInBits()); // This is where my code goes, which gives me a format=0
assert false : "Illegal sample size";
}

Is there a way to support this or is that a lost cause?
Logged

abcdef

  • Prolific Timewaster
  • ****
  • Offline Offline
  • Posts: 320
Re: [Beginner] Wav files are not playing
« Reply #9 on: February 05, 2015, 20:24:07 »

Does it work if you set the format properly then?
Logged

TotalSpelNerd

  • Newbie
  • *
  • Offline Offline
  • Posts: 11
Re: [Beginner] Wav files are not playing
« Reply #10 on: February 06, 2015, 06:07:24 »

Yeah, it does but I had to convert my 24 bit file into a 16 bit to make it work.

Thanks for your assistance.
Logged