Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
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   
Pages: [1]
  ignore  |  Print  
  ALC_INVALID_CONTEXT  (Read 3753 times)
0 Members and 1 Guest are viewing this topic.
Offline antoinelechacal

Junior Member





« Posted 2006-07-11 09:36:19 »

Hi all.
As I'm trying to port the lesson 8 from the openAL tutorial, and I'm getting the error code ALC_INVALID_CONTEXT from alGetError() just after calling alSource3f(...). If I Call alGetError() before alSource3f() I get ALC_INVALID_DEVICE.
I don't know how to solve that problem.
Another clue : when I call AudioSystem3D.openDevice("DirectSound3D"), I get a NullPointerException.

All of this is quite surprising given the lesson 1 works pretty good...

Thanks for your answers.

My name is nobody
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #1 - Posted 2006-07-11 11:27:14 »

Could you please post / attach complete source code?

Why are you using the Sound3D wrapper library rather than e.g. ALut? Have you tried just calling ALut.alutInit() to get your context?
Offline antoinelechacal

Junior Member





« Reply #2 - Posted 2006-07-11 12:14:48 »

I just used the sound 3D wrapper for testing, else I use alutInit().

I will post the source code as soon as I get my dev-machine back.

My name is nobody
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline antoinelechacal

Junior Member





« Reply #3 - Posted 2006-07-11 14:48:18 »

Here's the source code :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
ALut.alutInit();
al = ALFactory.getAL();
if (alc.alcGetError(device) != ALC.ALC_NO_ERROR)
     return AL.AL_FALSE;

ois = new OggInputStream(new File(path).toURL().openStream()); // deprecated

al.alGenBuffers(2, IntBuffer.wrap(buffers));
check();
al.alGenSources(1, IntBuffer.allocate(source));
check();
al.alSource3f(source, AL.AL_POSITION, 0.0f, 0.0f, 0.0f);
check();


The check method : 
1  
2  
3  
4  
5  
private void check() {
    int error = al.alGetError();
    if (error != AL.AL_NO_ERROR)
   throw new ALException("OpenAL error was raised.");
}


The latest call to check() causes an ALException with 40961 in error which is related to the ALC_INVALID_DEVICE or AL_INVALIDE_NAME constant...
Any idea?

Thanks guys

My name is nobody
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #4 - Posted 2006-07-11 17:03:58 »

A lot of stuff looks wrong with this code. I'm not sure where you're getting the device from; and the call to IntBuffer.allocate(source) looks wrong; for example. Could you please look at the source code for the JOAL versions of the devmaster tutorials (in the joal-demos source tree; check it out via CVS) and build from those examples, which are known to work?
Offline antoinelechacal

Junior Member





« Reply #5 - Posted 2006-07-12 09:15:47 »

Ok, I'll give it a try.

I'm just getting started with openAL, I need to get used to it  Embarrassed

My name is nobody
Offline antoinelechacal

Junior Member





« Reply #6 - Posted 2006-07-12 09:33:05 »

I just tried lesson 3 & lesson 5  source code, I have arguments problems, some AL methods seems OK while others don't. Does this indicate any version conflict? This would be quite surprinsing given I'm pretty sure I downloaded the latest version...

My name is nobody
Offline antoinelechacal

Junior Member





« Reply #7 - Posted 2006-07-12 12:02:49 »

That works now, thanks to your help Ken, as you said, I was missusing IntBuffer.
I'm facing another problem now... Playing an ogg file takes 100% of my CPU.
I just ported the code from Game Dev (lesson Cool, is there any way to improve the use of the CPU?

Thanks again.

My name is nobody
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #8 - Posted 2006-07-12 15:08:34 »

I think there are several people on these forums who use Ogg Vorbis files in their games but I don't have any experience with them myself. I'd suggest you post maybe on the performance forum asking the general question about whether people do the decompression up front (at say the beginning of a level) or on the fly.
Offline Ultraq

Junior Member




That's what she said


« Reply #9 - Posted 2006-07-13 04:13:11 »

I'm facing another problem now... Playing an ogg file takes 100% of my CPU.
I just ported the code from Game Dev (lesson Cool, is there any way to improve the use of the CPU?

With my understanding of what lesson 8 is about (I haven't read all the source, nor completely comprehend it), it doesn't look like it should be using all of the CPU cycles.  It simply just decodes a little bit, puts it onto a 2-sized buffer queue, and then waits until there is more space in the buffer to add the next decoded piece.

Maybe your implementation doesn't wait when the buffer is full?  I can imagine 100% CPU usage if you've decided to use a sort of polling loop/thread which keeps trying to add decoded data to the buffer when there isn't enough space.  Getting this thread to wait (or the loop to yield and/or back-off for a set period of time) could reduce CPU usage.

Ultraq's Final MooCow
Bits and Pieces by Emanuel Rabina
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline antoinelechacal

Junior Member





« Reply #10 - Posted 2006-07-13 09:22:22 »

On a different machine, it "just" take 50% of the CPU...
Getting this thread to wait (or the loop to yield and/or back-off for a set period of time) could reduce CPU usage.

How would do that in the given code?

Thanks

My name is nobody
Offline Ultraq

Junior Member




That's what she said


« Reply #11 - Posted 2006-07-14 01:20:42 »

I'm guessing the 50% thing is because it's a dual-core processor.  Because your program isn't multi-threaded, it'll just shunt all instructions to 1 core of the processor.

Anyway, regarding wait/notify/backing-off:

Backing-Off/Polling:
By no means the most efficient way of checking if the buffer has space to add more data to it, but the easiest to understand.  This is effectively a polling mechanism that checks if there's space in the buffer to add more data.  If there isn't any space, it goes to sleep for a while, before checking again.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
// Method to add more data to the buffer
public void addData() {

    while (thereIsMoreToDecode) {
        if (buffer.isFull()) {
            Thread.sleep(500); // Sleep for 500ms
       }
        else {
            // Add more data to the buffer
       }
    }
}

public static void main(String[] args) {

    // Start a new add-data-to-buffer thread
   new Thread(new Runnable() {
        public void run() {
            addData();
        }
    }).start();

    // Do other stuff, like reading from the buffer
}


Thread wait/notify:
This is a tougher concept to understand: synchronization, locks, etc... but just as easy to implement.  If you don't already know about them (which I'll assume) I'd probably recommend a primer in Java threads before trying this out.
In this case, the method that puts data on to the buffer is going to wait until there is more room before adding more data.  What wait() means, is that the method goes to sleep until another thread tells it to wake-up (which happens when the notify() method is called) on the event that there is more room.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
private int bufferSize = 2;
private int bufferUsed = 0;

// Putting data onto the buffer method
public synchronized void addData() {

    while (thereIsMoreToDecode) {

        // Decode OGG data ...

        //  Then put it onto the buffer if there's room
       if (bufferUsed < bufferSize) {
            // Queue the new data onto the buffer
           bufferUsed++;
            notify();
        }
        // Otherwise wait until there's room
       else {
            wait();
        }
    }
}

// Taking data off the buffer method
public synchronized void takeData() {

    while (thereIsMoreToRead) {

        // Only read if there is data in the buffer
       if (bufferUsed > 0) {
            // Read the data from the buffer
           bufferUsed--;
            notify();
        }
        // Otherwise, sleep until there is more
       else {
            wait();'
        }
    }
}

// Method to start the decoding and reading threads
public static void main(String[] args) {

    // Create and start a new add-data-to-buffer thread
    new Thread(new Runnable() {
        public void run() {
            addData();
        }
    }).start();

    // Create and start a take-data-from-buffer thread
    new Thread(new Runnable() {
        public void run() {
           takeData();
        }
    }).start();
}


This is all just examples and pseudo-code, but if you can wrap your head around what the wait() and nofity() methods do, as well as fill-in the gaps for actually putting data onto the buffers where I've just left comments, then you should be fine.  The example that I've written above for wait/notify is similar to the one given to this chapter on multi-threading in Java (w/ a producers-consumers example) here:
http://java.sun.com/docs/books/tutorial/essential/threads/multithreaded.html

Ultraq's Final MooCow
Bits and Pieces by Emanuel Rabina
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.

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

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

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

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

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

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

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

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

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

CJLetsGame (215 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!