Positional sound, I need basic help!

Hello everyone,



I would like to put a single sound source, and make it fade in or out relatively to the position where I find myself (the camera). It sounds so simple, but I'm not going any further with it.



At the moment I have placed my sound source, it is linked to a tracker who stops the sound when i'm to far away. Actually I don't want to stop the sound, I just want to blend it away.



Where should I look for some help, I didn't find on the forum, in the Javadoc and with the examples?





Thanks in advance…

Trying to be more precise, I've written the following code in the simpleInitGame() function :

// Initialize sound

/** Set the 'ears' for the sound API /

audio = AudioSystem.getSystem();

audio.getEar().trackOrientation(cam);

audio.getEar().trackPosition(cam);



/
* Create program sound */

laserSound = audio.createAudioTrack(MainFrame.class.getClassLoader()

.getResource("loops_1_1.ogg"), false);

laserSound.setType(TrackType.POSITIONAL);

laserSound.setRelative(true);

laserSound.setLooping(true);

laserSound.setReferenceDistance(1f);

laserSound.setVolumeChangeRate(1f);

laserSound.setCurrVelocity(new Vector3f(0.1f,0.1f,0.1f));

laserSound.setWorldPosition(0,0,0);

laserSound.setMaxAudibleDistance(1f);

laserSound.setMaxVolume(1f);

laserSound.setMinVolume(0.1f);

laserSound.play();



Actually… i've tried out all possibilites I could.

In the simpleUpdate() method i've just written: audio.update();





Hope it helps (and sorry to ask so stupid questions :slight_smile: ).

hi, although this post is quite old here's a solution


package jmetest.mytests;

import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;

import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jmex.audio.AudioSystem;
import com.jmex.audio.AudioTrack;
import com.jmex.audio.RangedAudioTracker;
import com.jmex.audio.AudioTrack.TrackType;

public class TestPositionalAudio extends SimpleGame {

/**
* @param args
*/
public static void main(String[] args) {
new TestPositionalAudio().start();

}

private AudioSystem audio;
private AudioTrack laserSound;

//setup a Map with RangedAudioTrackers and a boolean if they're active
private HashMap<RangedAudioTracker, Boolean> m_sfxTrackers = new HashMap<RangedAudioTracker, Boolean>();
private Iterator<RangedAudioTracker> m_sfxTrackerIterator;
//and a single RangedAudioTracker for reuse in the update()
private RangedAudioTracker m_updTracker;

@Override
protected void simpleInitGame() {
//change the inputhandler speeds to enable more precize movement
input.getFromAttachedHandlers(0).setActionSpeed(0.5f);
input.getFromAttachedHandlers(1).setActionSpeed(20f);

// Initialize sound
/** Set the 'ears' for the sound API */
audio = AudioSystem.getSystem();
audio.getEar().trackOrientation(cam);
audio.getEar().trackPosition(cam);

/** Create program sound */
URL bla = TestPositionalAudio.class.getClassLoader().getResource(
"jmetest/data/sound/CHAR_CRE_1.ogg");
laserSound = audio.createAudioTrack(bla, false);
laserSound.setType(TrackType.POSITIONAL);
laserSound.setRelative(false);
laserSound.setLooping(true);
laserSound.setReferenceDistance(1f);
laserSound.setVolumeChangeRate(0.2f);
laserSound.setWorldPosition(0, 0, 0);
laserSound.setMaxAudibleDistance(1);
laserSound.setMaxVolume(1f);
laserSound.setMinVolume(0f);
// laserSound.play();

//setup a rangedAudioTracker with fadeTime 5 sec and start/stoprange 12/15
RangedAudioTracker newsTracker = new RangedAudioTracker(laserSound, 12f,
15f);
newsTracker.setPosition(new Vector3f(0f, 0f, 0f));
//fadeTime in seconds after start/stop
newsTracker.setFadeTime(5);
newsTracker.setTrackIn3D(true);
//add it to the trackerMap
m_sfxTrackers.put(newsTracker, true);

//setup a box as indicator of the soundsource
Box box = new Box("box", Vector3f.ZERO,1,1,1);
rootNode.attachChild(box);

//setup a sphere as indicator of the rangedAudioTracker's stoprange
Sphere sphere = new Sphere("s",Vector3f.ZERO,20,20,15);
rootNode.attachChild(sphere);

rootNode.updateGeometricState(0, true);

}

@Override
protected void simpleUpdate() {
super.simpleUpdate();
updateAudioSystem();
}

private void updateAudioSystem() {
audio.update();

m_sfxTrackerIterator = m_sfxTrackers.keySet().iterator();

while (m_sfxTrackerIterator.hasNext()) {
m_updTracker = m_sfxTrackerIterator.next();
if (m_sfxTrackers.get(m_updTracker)) {
m_updTracker.checkTrackAudible(cam.getLocation());
}
}
m_updTracker = null;
}

}



When I try execute this exemple, thow the follow error:

java.lang.NullPointerException

at TestPositionalAudio.simpleInitGame(TestPositionalAudio.java:48)

at com.jme.app.BaseSimpleGame.initGame(BaseSimpleGame.java:545)

at com.jme.app.BaseGame.start(BaseGame.java:74)

at TestPositionalAudio.main(TestPositionalAudio.java:21)



I’m braziliam, so, if I talk something wrong don’t call