# HG changeset patch # User Robert McIntyre # Date 1319873587 25200 # Node ID dae169178d113fd3f933dd48f0e768a0fc8c859f # Parent 87f818f58975c1de44c82e9026fd22f579b68988 investigate sound positioning problem diff -r 87f818f58975 -r dae169178d11 src/com/aurellem/capture/examples/AdvancedAudio.java --- a/src/com/aurellem/capture/examples/AdvancedAudio.java Fri Oct 28 22:24:10 2011 -0700 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java Sat Oct 29 00:33:07 2011 -0700 @@ -10,10 +10,6 @@ import com.jme3.audio.Listener; import com.jme3.cinematic.MotionPath; import com.jme3.cinematic.events.MotionTrack; -import com.jme3.input.KeyInput; -import com.jme3.input.controls.ActionListener; -import com.jme3.input.controls.KeyTrigger; -import com.jme3.input.controls.MouseButtonTrigger; import com.jme3.light.DirectionalLight; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; @@ -22,7 +18,6 @@ import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.scene.Node; -import com.jme3.scene.Spatial; import com.jme3.scene.shape.Box; import com.jme3.scene.shape.Sphere; import com.jme3.system.AppSettings; @@ -76,9 +71,11 @@ root.attachChild(ear); } + private Geometry bell; + private void createScene() { Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); - Geometry bell = new Geometry( "sound-emitter" , new Sphere(15,15,1)); + bell = new Geometry( "sound-emitter" , new Sphere(15,15,1)); mat.setColor("Color", ColorRGBA.Blue); bell.setMaterial(mat); rootNode.attachChild(bell); @@ -179,9 +176,9 @@ - private AudioNode audio_gun; - private AudioNode audio_nature; - private Geometry player; + private AudioNode music; + + private Listener auxListener = new Listener(); public File data1 = new File("/home/r/tmp/data1.wav"); public File data2 = new File("/home/r/tmp/data2.wav"); @@ -190,7 +187,7 @@ @Override public void simpleInitApp() { - //this.setTimer(new IsoTimer(60)); + this.setTimer(new IsoTimer(60)); if (this.audioRenderer instanceof MultiListener){ MultiListener rf = (MultiListener)this.audioRenderer; @@ -211,14 +208,14 @@ - initKeys(); + initAudio(); createScene(); motionControl.play(); - this.audioRenderer.playSource(audio_gun); + this.audioRenderer.playSource(music); @@ -227,39 +224,21 @@ /** We create two audio nodes. */ private void initAudio() { //audioRenderer.setEnvironment(Environment.Cavern); - /* gun shot sound is to be triggered by a mouse click. */ - audio_gun = new AudioNode(assetManager, "Sound/Environment/haydn.wav", false); - //audio_gun = new AudioNode(assetManager, "Sound/Effects/dream.wav", false, false); - audio_gun.setLooping(false); - audio_gun.setVolume(2); - audio_gun.setPositional(true); - - - /* nature sound - keeps playing in a loop. */ - audio_nature = new AudioNode(assetManager, "Sound/Environment/haydn.wav", false, false); - audio_nature.setLooping(true); - audio_nature.setPositional(true); - audio_nature.setLocalTranslation(Vector3f.ZERO.clone()); - audio_nature.setVolume(3); - audio_nature.updateGeometricState(); + + music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false); + music.setLooping(true); + music.setVolume(2); + music.setRefDistance(0.1f); + music.setMaxDistance(200); + music.setPositional(true); } /** Declaring the "Shoot" action, and * mapping it to a trigger (mouse click). */ - private void initKeys() { - inputManager.addMapping("Shoot", new MouseButtonTrigger(0)); - inputManager.addListener(actionListener, "Shoot"); - } + /** Defining the "Shoot" action: Play a gun sound. */ - private ActionListener actionListener = new ActionListener() { - @Override - public void onAction(String name, boolean keyPressed, float tpf) { - if (name.equals("Shoot") && !keyPressed) { - audioRenderer.playSource(audio_gun); // play once! - } - } - }; + /** Move the listener with the camera - for 3D audio. */ @Override @@ -271,7 +250,8 @@ auxListener.setLocation(loc); auxListener.setRotation(rot); - + music.setLocalTranslation(bell.getLocalTranslation()); + }