I can't get source type

Hi,

When I try to get source type I always get the error with the next code 40962. There’re 3 constants which corresponds this error number: ALC_INVALID_CONTEXT, AL_ILLEGAL_ENUM and AL_INVALID_ENUM. To which constant does this error code corresponds and why this error has appeared?

I use the SingleStaticSource class from JOAL tutorials. Here the full listing:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;

import net.java.games.joal.AL;
import net.java.games.joal.ALFactory;
import net.java.games.joal.util.ALut;
import net.java.games.joal.OpenALException;

public class SingleStaticSource {

static AL _al;

// Buffers hold sound data.
static int[] _buffer = new int[1];

// Sources are points emitting sound.
static int[] _source = new int[1];

// Position of the source sound.
static float[] _sourcePos = { 0.0f, 0.0f, 0.0f };

// Velocity of the source sound.
static float[] _sourceVel = { 0.0f, 0.0f, 0.0f };

// Position of the listener.
static float[] _listenerPos = { 0.0f, 0.0f, 0.0f };

// Velocity of the listener.
static float[] _listenerVel = { 0.0f, 0.0f, 0.0f };

// Orientation of the listener. (first 3 elems are "at", second 3 are "up")
static float[] _listenerOri = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f };

static int loadALData() {

    // variables to load into

    int[] format = new int[1];
    int[] size = new int[1];
    ByteBuffer[] data = new ByteBuffer[1];
    int[] freq = new int[1];
    int[] loop = new int[1];

    // Load wav data into a buffer.
    _al.alGenBuffers(1, _buffer);
    if (_al.alGetError() != AL.AL_NO_ERROR)
        return AL.AL_FALSE;

    ALut.alutLoadWAVFile(
        "wavdata/FancyPants.wav",
        format,
        data,
        size,
        freq,
        loop);
    _al.alBufferData(_buffer[0], format[0], data[0], size[0], freq[0]);
    ALut.alutUnloadWAV(format[0], data[0], size[0], freq[0]);

    // Bind buffer with a source.
    _al.alGenSources(1, _source);

    if (_al.alGetError() != AL.AL_NO_ERROR)
        return AL.AL_FALSE;


    
    [b]int sourceType = _al.alGetSourcei(_source[0], AL.AL_SOURCE_TYPE);
    int error = _al.alGetError();
    if (error != AL.AL_NO_ERROR) {
        System.out.println("error getting source type. Error id = " + error);
    } else {
        System.out.println("source type is " + sourceType);
    }[/b]        

    _al.alSourcei(_source[0], AL.AL_BUFFER, _buffer[0]);
    _al.alSourcef(_source[0], AL.AL_PITCH, 1.0f);
    _al.alSourcef(_source[0], AL.AL_GAIN, 1.0f);
    _al.alSourcefv(_source[0], AL.AL_POSITION, _sourcePos);
    _al.alSourcefv(_source[0], AL.AL_VELOCITY, _sourceVel);
    _al.alSourcei(_source[0], AL.AL_LOOPING, loop[0]);

    // Do another error check and return.
    if (_al.alGetError() == AL.AL_NO_ERROR)
        return AL.AL_TRUE;

    return AL.AL_FALSE;
}

static void setListenerValues() {
    _al.alListenerfv(AL.AL_POSITION, _listenerPos);
    _al.alListenerfv(AL.AL_VELOCITY, _listenerVel);
    _al.alListenerfv(AL.AL_ORIENTATION, _listenerOri);
}

static void killAllData() {
    _al.alDeleteBuffers(1, _buffer);
    _al.alDeleteSources(1, _source);
    ALut.alutExit();
}

public static void main(String[] args) {
    // Initialize OpenAL and clear the error bit.
    try {
    _al = ALFactory.getAL();
        ALut.alutInit();
        _al.alGetError();
    } catch (OpenALException e) {
        e.printStackTrace();
        return;
    }
    // Load the wav data.
    if (loadALData() == AL.AL_FALSE)
        System.exit(1);

    setListenerValues();

    char[] c = new char[1];
    while (c[0] != 'q') {
        try {
            BufferedReader buf =
                new BufferedReader(new InputStreamReader(System.in));
            System.out.println(
                "Press a key and hit ENTER: \n"
                    + "'p' to play, 's' to stop, " +
                      "'h' to pause and 'q' to quit");
            buf.read(c);
            switch (c[0]) {
                case 'p' :
                    // Pressing 'p' will begin playing the sample.
                    _al.alSourcePlay(_source[0]);
                    break;
                case 's' :
                    // Pressing 's' will stop the sample from playing.
                    _al.alSourceStop(_source[0]);
                    break;
                case 'h' :
                    // Pressing 'n' will pause (hold) the sample.
                    _al.alSourcePause(_source[0]);
                    break;
                case 'q' :
                    killAllData();
                    break;
            }
            System.out.println("buffer[0] = " + _source[0]);
            System.out.println("source[0] = " + _buffer[0]);
            
        } catch (IOException e) {
            System.exit(1);
        }
    }
}

}

I’m curious if the first of the bold lines actually compiles: alGetSourcei() has a void return type, and so that line shouldn’t even work. Maybe you’re using an older version of JOAL built against OpenAL 1.0?
Anyway, the error you’re getting must be AL_INVALID_ENUM because of the 3 constants you’ve listed, it’s the only one documented for the alGetSourcei() method.

I’ve just tried using AL_SOURCE_TYPE as the enum parameter, and was able to get the source type from that method without error. Maybe using AL_SOURCE_TYPE in alGetSourcei() is an OpenAL 1.1 thing (AL_SOURCE_TYPE isn’t listed as one of the valid parameters for that method, but I just think that’s the documentation lagging behind the API) ?
I’m using JOAL 1.1.2 (a nightly build from early November).

you were right!
I used the old JOAL API version with OpenAL SDK 1.1. I’ve updated JOAL to 1.1.2 version and everything works! Thanks a lot!