LWJGL Forum
Programming => OpenAL => Topic started by: Yuri6037 on February 04, 2015, 20:25:04
-
Hello all,
So i made this time my own sound file loading system ! Indead, i removed entirely the use of the lwjgl-util library. I gave me a defi to load a wave/ogg/whatever you want without using the WaveData class, and i made it, but now alGetError returns not AL_NO_ERROR when calling it right after alGenSources.
So it's a huge function i made that takes in parameter a Sound (class from my engine witch stores all informations about this sound (the file, listener, source, ...)
/* Loads the given sound and returns false when this failes or true if it succeeded ! */
protected boolean loadSound(Sound sound){
sound.buffer = alGenBuffers();
if (alGetError() != AL_NO_ERROR) {
return false;
}
/* Read and decode the sound file */
if (!SoundFormatHelper.instance.canSoundFileBeRead(sound.soundPath)){
return false;
}
BufferedInputStream stream;
try {
stream = new BufferedInputStream(new FileInputStream(sound.soundPath));
} catch (FileNotFoundException e) {
return false;
}
ISoundDecoder decoder = SoundFormatHelper.instance.getSoundDecoderForFormat(FileUtilities.getFileExtension(sound.soundPath));
decoder.initialize(stream);
ByteBuffer data = decoder.getData();
if (data == null){
GameApplication.engineLogger.severe(decoder.getName() + " has failed decoding file " + sound.soundPath.toString());
return false;
}
alBufferData(sound.buffer, decoder.getFormat(), decoder.getData(), decoder.getSampleRate());
decoder.clearBuffers();
try {
stream.close();
} catch (IOException e) {
System.out.println("Merde 3");
return false;
}
/* End */
/* Source generation */
sound.source = alGenSources();
if (alGetError() != AL_NO_ERROR) {
//Everytime i run the function it goes always here !!!
return false;
}
alSourcei(sound.source, AL_BUFFER, sound.buffer);
alSourcef(sound.source, AL_PITCH, 1.0f);
alSourcef(sound.source, AL_GAIN, 1.0f);
alSource(sound.source, AL_POSITION, sound.sourcePos);
alSource(sound.source, AL_VELOCITY, sound.sourceVel);
alSourcei(sound.source, AL_LOOPING, AL_FALSE);
if (alGetError() != AL_NO_ERROR) {
return false;
}
alListener(AL_POSITION, sound.listenerPos);
alListener(AL_VELOCITY, sound.listenerVel);
alListener(AL_ORIENTATION, sound.listenerOri);
return alGetError() == AL_NO_ERROR;
}
-
You have told us there is an error but not what it is. If you find an error, work out what it is. Below is a code snippet to help you out.
public String getALErrorString(int err)
{
switch (err)
{
case AL10.AL_NO_ERROR:
return "AL_NO_ERROR";
case AL10.AL_INVALID_NAME:
return "AL_INVALID_NAME";
case AL10.AL_INVALID_ENUM:
return "AL_INVALID_ENUM";
case AL10.AL_INVALID_VALUE:
return "AL_INVALID_VALUE";
case AL10.AL_INVALID_OPERATION:
return "AL_INVALID_OPERATION";
case AL10.AL_OUT_OF_MEMORY:
return "AL_OUT_OF_MEMORY";
default:
return "No such error code";
}
}
-
Oh sorry, I didn't know there was a way to know with error it was... Yes Indead, I'm a newbie at OpenAL, I never used it in c.
-
Thank you,
I got the result of OpenAL :
[05/02/2015 11:47:19 - SLDT's GameEngine] [INFO] : Worked file .\resources\sounds\menu\main.wav, result is : 'menu.main.wav'
[05/02/2015 11:47:19 - SLDT's GameEngine] [WARNING] : Failed to load sound, menu.main.wav : ERROR_INVALID_ENUM
ERROR_INVALID_ENUM is same as AL_INVALID_ENUM.
-
Do you get the same error before you run
sound.source = alGenSources();
?
-
Yes indead, the enum error is happening right after alBufferData in my code !
-
I think i found the problem !
My WaveSoundDecoder is always returning 0 at the getFormat, i just seen that OpenAL need to know if it's a stereo or mono sound ! Now i'll edit my code to give these informations !
-
Ok, now wave file load successfully, however there's no sound witch are played when i use an alSourcePlay...
Here is the code for the play function :
protected void playSound(Sound sound) {
alSourcePlay(sound.source);
EnumSoundLoadError err = getALErrorAsErrorEnum(alGetError());
if (err != EnumSoundLoadError.ERROR_NULL){
GameApplication.engineLogger.warning("Unable to play sound : " + err.name());
}
}
And yes the alGetError doesn't return any error !!
-
I feel like this post is very similar to the other post that is going on in this sub forum :)
How often do you call the play function?
-
I can call it one time or in the render loop but that's changes nothing, no sounds come up...
-
Also ? Nobody can help me ?