I’ve read a previous post where someone had problems with 3D audio (http://jmonkeyengine.org/groups/sound/forum/topic/hello-audio-without-3d-effect/). I’m trying it now with the latest nightly release, on two separate computers, and I’m not having a lot of luck. Even if I don’t get a full 3D effect, I assume I should at least be hearing a difference between left and right ear… (I’m on Windows 7, 64 bit.)
I’ve written a reusable test caseA small, self-contained application class that shows the effects of a problem. It should use only default assets so that it can be posted in the forum in code tags and run as-is by the developers., below, where the sound should spin round the camera. Have I made any mistakes?
Cheers,
Peter.
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.audio.AudioNode;
import com.jme3.audio.Environment;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import org.lwjgl.openal.AL10;
import org.lwjgl.openal.AL11;
public class Main extends SimpleApplication {
// Cube geometry
Geometry geom;
// Point on the circle to spin the cube
int radius = 20;
int numPoints = 10000;
int point = 0;
float alpha;
// Audio node
private AudioNode cubeAudio;
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
// Create spinning cube
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
rootNode.attachChild(geom);
// Set up audio
audioRenderer.setEnvironment(Environment.Dungeon);
AL10.alDistanceModel(AL11.AL_EXPONENT_DISTANCE);
cubeAudio = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", false);
cubeAudio.setPositional(true);
cubeAudio.setLooping(true);
cubeAudio.setReverbEnabled(true);
cubeAudio.setRefDistance(100000000);
cubeAudio.setMaxDistance(100000000);
cubeAudio.play();
alpha = (float)Math.PI*2/numPoints;
}
@Override
public void simpleUpdate(float tpf) {
// Move the cube to a new location
float theta = alpha * point;
float x = (float) Math.cos( theta ) * radius;
float z = (float) Math.sin( theta ) * radius;
geom.setLocalTranslation(x, 0, z);
point = point + 1;
if (point > numPoints) point = 0;
// Update sound source location
cubeAudio.setLocalTranslation(x, 0, z);
cubeAudio.updateGeometricState();
// Update listener location
listener.setLocation(cam.getLocation());
listener.setRotation(cam.getRotation());
}
@Override
public void simpleRender(RenderManager rm) { }
}