Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Java Sound & OpenAL / Re: I can't get source type on: 2008-03-05 11: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!
2  Java Game APIs & Engines / Java Sound & OpenAL / I can't get source type on: 2008-03-04 08: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);
            }
        }
    }
}
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (38 views)
2014-04-15 18:08:23

BurntPizza (34 views)
2014-04-15 03:46:01

UprightPath (50 views)
2014-04-14 17:39:50

UprightPath (32 views)
2014-04-14 17:35:47

Porlus (49 views)
2014-04-14 15:48:38

tom_mai78101 (71 views)
2014-04-10 04:04:31

BurntPizza (130 views)
2014-04-08 23:06:04

tom_mai78101 (230 views)
2014-04-05 13:34:39

trollwarrior1 (193 views)
2014-04-04 12:06:45

CJLetsGame (200 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!