changeset 17:dae169178d11

investigate sound positioning problem
author Robert McIntyre <rlm@mit.edu>
date Sat, 29 Oct 2011 00:33:07 -0700
parents 87f818f58975
children 2543c95a0fd2
files src/com/aurellem/capture/examples/AdvancedAudio.java
diffstat 1 files changed, 20 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/src/com/aurellem/capture/examples/AdvancedAudio.java	Fri Oct 28 22:24:10 2011 -0700
     1.2 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java	Sat Oct 29 00:33:07 2011 -0700
     1.3 @@ -10,10 +10,6 @@
     1.4  import com.jme3.audio.Listener;
     1.5  import com.jme3.cinematic.MotionPath;
     1.6  import com.jme3.cinematic.events.MotionTrack;
     1.7 -import com.jme3.input.KeyInput;
     1.8 -import com.jme3.input.controls.ActionListener;
     1.9 -import com.jme3.input.controls.KeyTrigger;
    1.10 -import com.jme3.input.controls.MouseButtonTrigger;
    1.11  import com.jme3.light.DirectionalLight;
    1.12  import com.jme3.material.Material;
    1.13  import com.jme3.math.ColorRGBA;
    1.14 @@ -22,7 +18,6 @@
    1.15  import com.jme3.math.Vector3f;
    1.16  import com.jme3.scene.Geometry;
    1.17  import com.jme3.scene.Node;
    1.18 -import com.jme3.scene.Spatial;
    1.19  import com.jme3.scene.shape.Box;
    1.20  import com.jme3.scene.shape.Sphere;
    1.21  import com.jme3.system.AppSettings;
    1.22 @@ -76,9 +71,11 @@
    1.23  		 root.attachChild(ear);
    1.24  	 } 
    1.25  	 
    1.26 +	 private Geometry bell;
    1.27 +	 
    1.28  	 private void createScene() {
    1.29  		 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    1.30 -		 Geometry bell = new Geometry( "sound-emitter" , new Sphere(15,15,1));
    1.31 +		 bell = new Geometry( "sound-emitter" , new Sphere(15,15,1));
    1.32  		 mat.setColor("Color", ColorRGBA.Blue);
    1.33  		 bell.setMaterial(mat);
    1.34  		 rootNode.attachChild(bell);
    1.35 @@ -179,9 +176,9 @@
    1.36  	
    1.37  	
    1.38  
    1.39 -  private AudioNode audio_gun;
    1.40 -  private AudioNode audio_nature;
    1.41 -  private Geometry player;
    1.42 +  private AudioNode music;
    1.43 +  
    1.44 +  
    1.45    private Listener auxListener = new Listener(); 
    1.46    public File data1 = new File("/home/r/tmp/data1.wav");
    1.47    public File data2 = new File("/home/r/tmp/data2.wav");
    1.48 @@ -190,7 +187,7 @@
    1.49    
    1.50    @Override
    1.51    public void simpleInitApp() {
    1.52 -	//this.setTimer(new IsoTimer(60));
    1.53 +	this.setTimer(new IsoTimer(60));
    1.54  	
    1.55  	if (this.audioRenderer instanceof MultiListener){
    1.56  		MultiListener rf = (MultiListener)this.audioRenderer;
    1.57 @@ -211,14 +208,14 @@
    1.58      
    1.59          
    1.60      
    1.61 -    initKeys();
    1.62 +    
    1.63      initAudio();
    1.64  	createScene();
    1.65  	 
    1.66  
    1.67      motionControl.play();
    1.68  	
    1.69 -	this.audioRenderer.playSource(audio_gun);
    1.70 +	this.audioRenderer.playSource(music);
    1.71  
    1.72  	
    1.73  
    1.74 @@ -227,39 +224,21 @@
    1.75    /** We create two audio nodes. */ 
    1.76    private void initAudio() {
    1.77  	//audioRenderer.setEnvironment(Environment.Cavern);
    1.78 -    /* gun shot sound is to be triggered by a mouse click. */
    1.79 -	audio_gun = new AudioNode(assetManager, "Sound/Environment/haydn.wav", false);
    1.80 -	//audio_gun = new AudioNode(assetManager, "Sound/Effects/dream.wav", false, false);
    1.81 -    audio_gun.setLooping(false);
    1.82 -    audio_gun.setVolume(2);
    1.83 -    audio_gun.setPositional(true);
    1.84 -
    1.85 -
    1.86 -    /* nature sound - keeps playing in a loop. */
    1.87 -    audio_nature = new AudioNode(assetManager, "Sound/Environment/haydn.wav", false, false);
    1.88 -    audio_nature.setLooping(true);
    1.89 -    audio_nature.setPositional(true);
    1.90 -    audio_nature.setLocalTranslation(Vector3f.ZERO.clone());
    1.91 -    audio_nature.setVolume(3);
    1.92 -    audio_nature.updateGeometricState();
    1.93 +    
    1.94 +	music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false);
    1.95 +    music.setLooping(true);
    1.96 +    music.setVolume(2);
    1.97 +    music.setRefDistance(0.1f);	
    1.98 +    music.setMaxDistance(200);
    1.99 +    music.setPositional(true);
   1.100    }
   1.101  
   1.102    /** Declaring the "Shoot" action, and
   1.103     *  mapping it to a trigger (mouse click). */
   1.104 -  private void initKeys() {
   1.105 -    inputManager.addMapping("Shoot", new MouseButtonTrigger(0));
   1.106 -    inputManager.addListener(actionListener, "Shoot");
   1.107 -  }
   1.108 +  
   1.109  
   1.110    /** Defining the "Shoot" action: Play a gun sound. */
   1.111 -  private ActionListener actionListener = new ActionListener() {
   1.112 -    @Override
   1.113 -    public void onAction(String name, boolean keyPressed, float tpf) {
   1.114 -      if (name.equals("Shoot") && !keyPressed) {
   1.115 -        audioRenderer.playSource(audio_gun); // play once!
   1.116 -      }
   1.117 -    }
   1.118 -  };
   1.119 +  
   1.120  
   1.121    /** Move the listener with the camera - for 3D audio. */
   1.122    @Override
   1.123 @@ -271,7 +250,8 @@
   1.124      auxListener.setLocation(loc);
   1.125      auxListener.setRotation(rot);
   1.126      
   1.127 -    	
   1.128 +    music.setLocalTranslation(bell.getLocalTranslation());
   1.129 +    
   1.130      	
   1.131    }
   1.132