Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  I can't get source type  (Read 4493 times)
0 Members and 1 Guest are viewing this topic.
Offline artiom_fetishev

Junior Newbie

« Posted 2008-03-04 07:27:41 »


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.nio.ByteBuffer;


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;

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

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

        _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);

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


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

Junior Devvie

That's what she said

« Reply #1 - Posted 2008-03-05 06:25:22 »

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

Ultraq's Final MooCow
Bits and Pieces by Emanuel Rabina
Offline artiom_fetishev

Junior Newbie

« Reply #2 - Posted 2008-03-05 10:53:04 »

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!
Pages: [1]
  ignore  |  Print  

DesertCoockie (20 views)
2018-05-13 18:23:11

nelsongames (68 views)
2018-04-24 18:15:36

nelsongames (65 views)
2018-04-24 18:14:32

ivj94 (748 views)
2018-03-24 14:47:39

ivj94 (79 views)
2018-03-24 14:46:31

ivj94 (555 views)
2018-03-24 14:43:53

Solater (94 views)
2018-03-17 05:04:08

nelsongames (168 views)
2018-03-05 17:56:34

Gornova (338 views)
2018-03-02 22:15:33

buddyBro (998 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!