Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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 3321 times)
0 Members and 1 Guest are viewing this topic.
Offline artiom_fetishev

Junior Newbie





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

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;


       
        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);
        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);
            }
        }
    }
}
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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (30 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (59 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!