3D Audio not working?

I’ve read a previous post where someone had problems with 3D audio (http://hub.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 case, below, where the sound should spin round the camera. Have I made any mistakes?



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();




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);



// Set up audio



cubeAudio = new AudioNode(assetManager, “Sound/Effects/Beep.ogg”, false);







alpha = (float)Math.PI*2/numPoints;



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);


// Update listener location





public void simpleRender(RenderManager rm) { }


This look suspicious:



With that, you’d have to have one ear miles away from the other to hear any difference. Try setting the ref distance really small as a test.

And make sure that your sound is mono.

Also… this:


Is probably not a great idea.

1 Like


Reducing refDistance and maxDistance to sensible values makes the effect work, albeit subtle. (My thinking was that by setting them to high values, only direction rather than distance would have an effect.)

If anyone knows any tricks to boost the illusion - to give a seriously strong effect similar to http://gprime.net/flash.php/soundimmersion - I’d be delighted to hear :slight_smile:

Leave max distance really really high. But make ref distance sensible.

I use positioned audio for random sounds in Mythruna and you can definitely hear and locate the exact spot they sound like they are coming from.

Max distance sets the distance where the sound stops getting quieter. It you set it too small then your sound will be heard from everywhere.

@pspeed said:Also... this:

Is probably not a great idea.

According to the AL10 documentation, the only legal arguments are the constants provided for in AL10.

In any event, you shouldn't be needing to call GL or AL functionality directly when using jME!

Thanks, I’ve removed that - it came from the JME doppler example.


BTW, I checked out Mythruna’s code and apparently I just leave ref distance and max distance at the default values and get a pretty good positional audio.

…I do turn off reverb though as it can confuse the sound I hear. At least when I was testing it.