LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: OpenAl returns error when using alGenSources  (Read 4552 times)

Yuri6037

  • Talks Too Much
  • ***
  • Offline Offline
  • Posts: 104
  • Check out our website : http://www.sldt-team.net !
OpenAl returns error when using alGenSources
« 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, ...)

Code: [Select]
   /* 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;
    }
Logged

abcdef

  • Prolific Timewaster
  • ****
  • Offline Offline
  • Posts: 320
Re: OpenAl returns error when using alGenSources
« Reply #1 on: February 04, 2015, 20:34:46 »

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.

Code: [Select]
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";
        }
    }
Logged

Yuri6037

  • Talks Too Much
  • ***
  • Offline Offline
  • Posts: 104
  • Check out our website : http://www.sldt-team.net !
Re: OpenAl returns error when using alGenSources
« Reply #2 on: February 04, 2015, 21:33:49 »

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.
Logged

Yuri6037

  • Talks Too Much
  • ***
  • Offline Offline
  • Posts: 104
  • Check out our website : http://www.sldt-team.net !
Re: OpenAl returns error when using alGenSources
« Reply #3 on: February 05, 2015, 10:50:06 »

Thank you,

I got the result of OpenAL :
Code: [Select]
[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.
Logged

abcdef

  • Prolific Timewaster
  • ****
  • Offline Offline
  • Posts: 320
Re: OpenAl returns error when using alGenSources
« Reply #4 on: February 05, 2015, 10:53:23 »

Do you get the same error before you run

sound.source = alGenSources();

?
Logged

Yuri6037

  • Talks Too Much
  • ***
  • Offline Offline
  • Posts: 104
  • Check out our website : http://www.sldt-team.net !
Re: OpenAl returns error when using alGenSources
« Reply #5 on: February 05, 2015, 13:47:23 »

Yes indead, the enum error is happening right after alBufferData in my code !
Logged

Yuri6037

  • Talks Too Much
  • ***
  • Offline Offline
  • Posts: 104
  • Check out our website : http://www.sldt-team.net !
Re: OpenAl returns error when using alGenSources
« Reply #6 on: February 05, 2015, 13:59:55 »

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 !
Logged

Yuri6037

  • Talks Too Much
  • ***
  • Offline Offline
  • Posts: 104
  • Check out our website : http://www.sldt-team.net !
Re: OpenAl returns error when using alGenSources
« Reply #7 on: February 05, 2015, 17:37:28 »

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 :
Code: [Select]
    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 !!
Logged

abcdef

  • Prolific Timewaster
  • ****
  • Offline Offline
  • Posts: 320
Re: OpenAl returns error when using alGenSources
« Reply #8 on: February 05, 2015, 20:25:31 »

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

Yuri6037

  • Talks Too Much
  • ***
  • Offline Offline
  • Posts: 104
  • Check out our website : http://www.sldt-team.net !
Re: OpenAl returns error when using alGenSources
« Reply #9 on: February 06, 2015, 07:07:16 »

I can call it one time or in the render loop but that's changes nothing, no sounds come up...
Logged

Yuri6037

  • Talks Too Much
  • ***
  • Offline Offline
  • Posts: 104
  • Check out our website : http://www.sldt-team.net !
Re: OpenAl returns error when using alGenSources
« Reply #10 on: February 09, 2015, 14:48:40 »

Also ? Nobody can help me ?

Logged