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;
}