diff src/com/aurellem/capture/examples/AdvancedAudio.java @ 18:2543c95a0fd2

fixed sound problem
author Robert McIntyre <rlm@mit.edu>
date Sat, 29 Oct 2011 14:39:19 -0700
parents dae169178d11
children 4de7988407ef
line wrap: on
line diff
     1.1 --- a/src/com/aurellem/capture/examples/AdvancedAudio.java	Sat Oct 29 00:33:07 2011 -0700
     1.2 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java	Sat Oct 29 14:39:19 2011 -0700
     1.3 @@ -7,9 +7,12 @@
     1.4  import com.aurellem.capture.audio.WaveFileWriter;
     1.5  import com.jme3.app.SimpleApplication;
     1.6  import com.jme3.audio.AudioNode;
     1.7 +import com.jme3.audio.AudioParam;
     1.8  import com.jme3.audio.Listener;
     1.9  import com.jme3.cinematic.MotionPath;
    1.10  import com.jme3.cinematic.events.MotionTrack;
    1.11 +import com.jme3.input.controls.ActionListener;
    1.12 +import com.jme3.input.controls.MouseButtonTrigger;
    1.13  import com.jme3.light.DirectionalLight;
    1.14  import com.jme3.material.Material;
    1.15  import com.jme3.math.ColorRGBA;
    1.16 @@ -55,9 +58,6 @@
    1.17  			org.lwjgl.input.Mouse.setGrabbed(false);
    1.18  			app.start();
    1.19  	  }
    1.20 -
    1.21 -	
    1.22 -	
    1.23  	 
    1.24  	 private MotionTrack motionControl;
    1.25  	
    1.26 @@ -146,6 +146,8 @@
    1.27  		 
    1.28  		 // come at me bro!
    1.29  		 path.addWayPoint(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
    1.30 +		//path.addWayPoint(new Vector3f(0, 0 , -20));
    1.31 +		 
    1.32  		 path.setCurveTension(0.80f);
    1.33  
    1.34  		 
    1.35 @@ -156,7 +158,7 @@
    1.36  	     motionControl.setSpeed(0.1f);
    1.37  		 
    1.38  		 
    1.39 -		 //path.enableDebugShape(assetManager, rootNode);
    1.40 +		 path.enableDebugShape(assetManager, rootNode);
    1.41  
    1.42  
    1.43  		 positionCamera();
    1.44 @@ -166,10 +168,8 @@
    1.45  
    1.46  	 
    1.47  	 private void positionCamera(){
    1.48 -		this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
    1.49 +		//this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
    1.50  		this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f));
    1.51 -		
    1.52 -
    1.53  	 }
    1.54  	 
    1.55  	 
    1.56 @@ -185,7 +185,7 @@
    1.57    public File data3 = new File("/home/r/tmp/data3.wav");
    1.58     
    1.59    
    1.60 -  @Override
    1.61 +  
    1.62    public void simpleInitApp() {
    1.63  	this.setTimer(new IsoTimer(60));
    1.64  	
    1.65 @@ -210,12 +210,13 @@
    1.66      
    1.67      
    1.68      initAudio();
    1.69 +    initKeys();
    1.70  	createScene();
    1.71  	 
    1.72  
    1.73      motionControl.play();
    1.74  	
    1.75 -	this.audioRenderer.playSource(music);
    1.76 +	//this.audioRenderer.playSource(music);
    1.77  
    1.78  	
    1.79  
    1.80 @@ -226,11 +227,25 @@
    1.81  	//audioRenderer.setEnvironment(Environment.Cavern);
    1.82      
    1.83  	music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false);
    1.84 -    music.setLooping(true);
    1.85 -    music.setVolume(2);
    1.86 -    music.setRefDistance(0.1f);	
    1.87 -    music.setMaxDistance(200);
    1.88 +	
    1.89 +	//music.setLooping(true);
    1.90 +    
    1.91 +   
    1.92 +	
    1.93 +    
    1.94 +    
    1.95 +    rootNode.attachChild(music);
    1.96 +    audioRenderer.playSource(music);
    1.97 +    
    1.98 +    music.setVolume(1f);
    1.99      music.setPositional(true);
   1.100 +    music.setMaxDistance(200.0f);
   1.101 +    music.setRefDistance(0.1f);
   1.102 +    music.setRolloffFactor(5f);
   1.103 +    audioRenderer.pauseSource(music);
   1.104 +    
   1.105 +    
   1.106 +    
   1.107    }
   1.108  
   1.109    /** Declaring the "Shoot" action, and
   1.110 @@ -239,19 +254,49 @@
   1.111  
   1.112    /** Defining the "Shoot" action: Play a gun sound. */
   1.113    
   1.114 +  private void initKeys() {
   1.115 +	  inputManager.addMapping("Shoot", new MouseButtonTrigger(0));
   1.116 +	  inputManager.addListener(actionListener, "Shoot");
   1.117 +  }
   1.118 +
   1.119 +  /** Defining the "Shoot" action: Play a gun sound. */
   1.120 +  private ActionListener actionListener = new ActionListener() {
   1.121 +	  @Override
   1.122 +	  public void onAction(String name, boolean keyPressed, float tpf) {
   1.123 +		  if (name.equals("Shoot") && !keyPressed) {
   1.124 +			  System.out.println("I'm playing! <3");
   1.125 +			  System.out.println(bell.getLocalTranslation().subtract(cam.getLocation()).length());	
   1.126 +			  
   1.127 +			  audioRenderer.playSource(music);
   1.128 +			  System.out.println(music.getRefDistance());
   1.129 +			 
   1.130 +		  }
   1.131 +	  }
   1.132 +  };
   1.133  
   1.134    /** Move the listener with the camera - for 3D audio. */
   1.135    @Override
   1.136    public void simpleUpdate(float tpf) {
   1.137 -	Vector3f loc = cam.getLocation();
   1.138 -	Quaternion rot = cam.getRotation();
   1.139 -    listener.setLocation(loc);
   1.140 -    listener.setRotation(rot);
   1.141 -    auxListener.setLocation(loc);
   1.142 -    auxListener.setRotation(rot);
   1.143 +	//Vector3f loc = cam.getLocation();
   1.144 +	//Quaternion rot = cam.getRotation();
   1.145 +    //listener.setLocation(loc);
   1.146 +    //listener.setRotation(rot);
   1.147 +    
   1.148 +    
   1.149 +    listener.setLocation(cam.getLocation());
   1.150 +    listener.setRotation(cam.getRotation());
   1.151 +    //auxListener.setLocation(loc);
   1.152 +    //auxListener.setRotation(rot);
   1.153 +    //if (music.getStatus() == AudioNode.Status.Stopped){
   1.154 +
   1.155 +    	//music.playInstance();
   1.156 +    //}
   1.157 +    //audioRenderer.updateSourceParam(music, AudioParam.Direction);
   1.158      
   1.159      music.setLocalTranslation(bell.getLocalTranslation());
   1.160      
   1.161 +    //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_MIN_GAIN, 0f);
   1.162 +    //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_ROLLOFF_FACTOR, 5f);
   1.163      	
   1.164    }
   1.165