[Beginner] Wav files are not playing

Started by TotalSpelNerd, February 03, 2015, 15:47:00

Previous topic - Next topic

TotalSpelNerd

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)

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

abcdef

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.


TotalSpelNerd

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.

abcdef

Have you tried the example from the wiki?

TotalSpelNerd

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?

abcdef

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

TotalSpelNerd

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.

abcdef

What values do you have for

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

before you make the call?

TotalSpelNerd

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:
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?

abcdef

Does it work if you set the format properly then?

TotalSpelNerd

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

Thanks for your assistance.