Running sound in a multithreaded environment

Hey everybody. The game I am currently working on (Gravity Arena (more creative name pending)) uses a multi-threading system to take advantage of computers with lots of cores.



Currently I am trying to add some sounds to the game and I’m getting



Exception in thread “Thread-6” java.lang.IllegalStateException: No audio renderer available, make sure call is being performed on render thread.



When I try to run a sound inside one of my game entities, I get this problem.



What can I do about it? Can I somehow access the render thread and get it to do these sorts of things?

SimpleApplication.enqueue(Callable)

@zzuegg said:
SimpleApplication.enqueue(Callable)


I am a little confused. Should I make my entity classes implement callable or...?

Basically I have this method that gets called every frame. A thruster will check if it is on, and if it is, then it will make sure the sound is playing for that action.

I don't understand how I can do anything with that enqueue thing.

If I do something like enqueue(Executor.callable(this.getThread))

And then run the code like normal... Will that work?

I don't seem to be able to access the static method callable in Executor...

[java]

public classSomeClass{

private Callable playSound(){

//do something

return Boolean.True;

}



public void theOtherThread(){

SimpleApplication.enqueue(this.playSound());

}



}

[/java]

@zzuegg said:
[java]
public classSomeClass{
private Callable playSound(){
//do something
return Boolean.True;
}

public void theOtherThread(){
SimpleApplication.enqueue(this.playSound());
}

}
[/java]


You cant do this:
[java]private Callable playSound(){
//do something
return Boolean.True;
}[/java]
If one were to make a method to return a callable, one would need to return a callable.
@yuxemporos said:
You cant do this:
[java]private Callable playSound(){
//do something
return Boolean.True;
}[/java]
If one were to make a method to return a callable, one would need to return a callable.


sorry i meant:

[java]
Callable<Boolean> playSound = new Callable<Boolean>() {

public Boolean call() throws Exception {
throw new UnsupportedOperationException("Not supported yet.");
}
};
this.app.enqueue(playSound);
[/java]
1 Like

Ah, that looks like an easier thing than what I ended up doing hehehe.



[java]public class soundCheck implements Callable {



Thruster t;



public soundCheck(Thruster thruster) {

t = thruster;

System.out.println("Starting soundCheck thrusting is "+t.firing);

}



public Object call() throws Exception {

System.out.println("The sound should be " + thrustSound.getStatus()+" The Thruster should be firing? "+t.firing);

if (t.firing) {

System.out.println("The sound should be " + thrustSound.getStatus());

if (thrustSound.getStatus() == Status.Stopped || thrustSound.getStatus() == Status.Paused) {

thrustSound.play();

System.out.println("There should be a sound playing");

}

} else {

if (thrustSound.getStatus() == Status.Playing) {

thrustSound.stop();

}

}

return thrustSound.getStatus();

}

}[/java]