diff src/com/aurellem/capture/examples/AdvancedAudio.java @ 19:4de7988407ef

added CompositeSoundProcessor for combining SoundProcessors
author Robert McIntyre <rlm@mit.edu>
date Sat, 29 Oct 2011 15:16:06 -0700
parents 2543c95a0fd2
children bc6fbfbbadd9
line wrap: on
line diff
     1.1 --- a/src/com/aurellem/capture/examples/AdvancedAudio.java	Sat Oct 29 14:39:19 2011 -0700
     1.2 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java	Sat Oct 29 15:16:06 2011 -0700
     1.3 @@ -7,7 +7,6 @@
     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 @@ -73,6 +72,58 @@
    1.12  	 
    1.13  	 private Geometry bell;
    1.14  	 
    1.15 +	 
    1.16 +	 private Vector3f[] path = new Vector3f[]{
    1.17 +			 // loop 1
    1.18 +			 new Vector3f(0, 0, 0),
    1.19 +			 new Vector3f(0, 0, -10),
    1.20 +			 new Vector3f(-2, 0, -14),
    1.21 +			 new Vector3f(-6, 0, -20),
    1.22 +			 new Vector3f(0, 0, -26),
    1.23 +			 new Vector3f(6, 0, -20),
    1.24 +			 new Vector3f(0, 0, -14),
    1.25 +			 new Vector3f(-6, 0, -20),
    1.26 +			 new Vector3f(0, 0, -26),
    1.27 +			 new Vector3f(6, 0, -20),
    1.28 +			 // loop 2
    1.29 +			 new Vector3f(5, 0, -5),
    1.30 +			 new Vector3f(7, 0, 1.5f),
    1.31 +			 new Vector3f(14, 0, 2),
    1.32 +			 new Vector3f(20, 0, 6),
    1.33 +			 new Vector3f(26, 0, 0),
    1.34 +			 new Vector3f(20, 0, -6),
    1.35 +			 new Vector3f(14, 0, 0),
    1.36 +			 new Vector3f(20, 0, 6),
    1.37 +			 new Vector3f(26, 0, 0),
    1.38 +			 new Vector3f(20, 0, -6),
    1.39 +			 new Vector3f(14, 0, 0),
    1.40 +			 // loop 3
    1.41 +			 new Vector3f(8, 0, 7.5f),
    1.42 +			 new Vector3f(7, 0, 10.5f),
    1.43 +			 new Vector3f(6, 0, 20),
    1.44 +			 new Vector3f(0, 0, 26),
    1.45 +			 new Vector3f(-6, 0, 20),
    1.46 +			 new Vector3f(0, 0, 14),
    1.47 +			 new Vector3f(6, 0, 20),
    1.48 +			 new Vector3f(0, 0, 26),
    1.49 +			 new Vector3f(-6, 0, 20),
    1.50 +			 new Vector3f(0, 0, 14),
    1.51 +			 // begin ellipse
    1.52 +			 new Vector3f(16, 5, 20),
    1.53 +			 new Vector3f(0, 0, 26),
    1.54 +			 new Vector3f(-16, -10, 20),
    1.55 +			 new Vector3f(0, 0, 14),
    1.56 +			 new Vector3f(16, 20, 20),
    1.57 +			 new Vector3f(0, 0, 26),
    1.58 +			 new Vector3f(-10, -25, 10),
    1.59 +			 new Vector3f(-10, 0, 0),
    1.60 +			 // come at me bro!
    1.61 +			 new Vector3f(-28.00242f, 48.005623f, -34.648228f),
    1.62 +			 new Vector3f(0, 0 , -20),
    1.63 +	 };
    1.64 +	 
    1.65 +	 
    1.66 +	 
    1.67  	 private void createScene() {
    1.68  		 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    1.69  		 bell = new Geometry( "sound-emitter" , new Sphere(15,15,1));
    1.70 @@ -90,75 +141,24 @@
    1.71  		 makeEar(rootNode, new Vector3f(20, 0 ,0));
    1.72  		 makeEar(rootNode, new Vector3f(-20, 0 ,0));
    1.73  
    1.74 -		 MotionPath path = new MotionPath();
    1.75 +		 MotionPath track = new MotionPath();
    1.76  		 
    1.77 -		 // loop 1
    1.78 -		 path.addWayPoint(new Vector3f(0, 0, 0));
    1.79 -		 path.addWayPoint(new Vector3f(0, 0, -10));
    1.80 -		 path.addWayPoint(new Vector3f(-2, 0, -14));
    1.81 -		 path.addWayPoint(new Vector3f(-6, 0, -20));
    1.82 -		 path.addWayPoint(new Vector3f(0, 0, -26));
    1.83 -		 path.addWayPoint(new Vector3f(6, 0, -20));
    1.84 -		 path.addWayPoint(new Vector3f(0, 0, -14));
    1.85 -		 path.addWayPoint(new Vector3f(-6, 0, -20));
    1.86 -		 path.addWayPoint(new Vector3f(0, 0, -26));
    1.87 -		 path.addWayPoint(new Vector3f(6, 0, -20));
    1.88 -		 	 
    1.89 -		 
    1.90 -		 // loop 2
    1.91 -		 path.addWayPoint(new Vector3f(5, 0, -5));
    1.92 -		 path.addWayPoint(new Vector3f(7, 0, 1.5f));
    1.93 -		 path.addWayPoint(new Vector3f(14, 0, 2));
    1.94 -		 path.addWayPoint(new Vector3f(20, 0, 6));
    1.95 -		 path.addWayPoint(new Vector3f(26, 0, 0));
    1.96 -		 path.addWayPoint(new Vector3f(20, 0, -6));
    1.97 -		 path.addWayPoint(new Vector3f(14, 0, 0));
    1.98 -		 path.addWayPoint(new Vector3f(20, 0, 6));
    1.99 -		 path.addWayPoint(new Vector3f(26, 0, 0));
   1.100 -		 path.addWayPoint(new Vector3f(20, 0, -6));
   1.101 -		 path.addWayPoint(new Vector3f(14, 0, 0));
   1.102 -		 
   1.103 -		 
   1.104 -		 
   1.105 -		 // loop 3
   1.106 -		 path.addWayPoint(new Vector3f(8, 0, 7.5f));
   1.107 -		 path.addWayPoint(new Vector3f(7, 0, 10.5f));
   1.108 -		 path.addWayPoint(new Vector3f(6, 0, 20));
   1.109 -		 path.addWayPoint(new Vector3f(0, 0, 26));
   1.110 -		 path.addWayPoint(new Vector3f(-6, 0, 20));
   1.111 -		 path.addWayPoint(new Vector3f(0, 0, 14));
   1.112 -		 path.addWayPoint(new Vector3f(6, 0, 20));
   1.113 -		 path.addWayPoint(new Vector3f(0, 0, 26));
   1.114 -		 path.addWayPoint(new Vector3f(-6, 0, 20));
   1.115 -		 path.addWayPoint(new Vector3f(0, 0, 14));
   1.116 -		 
   1.117 -		 
   1.118 -		 // begin elipse
   1.119 -
   1.120 -		 path.addWayPoint(new Vector3f(16, 5, 20));
   1.121 -		 path.addWayPoint(new Vector3f(0, 0, 26));
   1.122 -		 path.addWayPoint(new Vector3f(-16, -10, 20));
   1.123 -		 path.addWayPoint(new Vector3f(0, 0, 14));
   1.124 -		 path.addWayPoint(new Vector3f(16, 20, 20));
   1.125 -		 path.addWayPoint(new Vector3f(0, 0, 26));
   1.126 -		 path.addWayPoint(new Vector3f(-10, -25, 10));
   1.127 -		 path.addWayPoint(new Vector3f(-10, 0, 0));
   1.128 -		 
   1.129 -		 // come at me bro!
   1.130 -		 path.addWayPoint(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
   1.131 -		//path.addWayPoint(new Vector3f(0, 0 , -20));
   1.132 -		 
   1.133 -		 path.setCurveTension(0.80f);
   1.134 +		for (Vector3f v : path){
   1.135 +			track.addWayPoint(v);
   1.136 +		}
   1.137 +	
   1.138 +		  
   1.139 +		 track.setCurveTension(0.80f);
   1.140  
   1.141  		 
   1.142 -		 motionControl = new MotionTrack(bell,path);
   1.143 +		 motionControl = new MotionTrack(bell,track);
   1.144  	     motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation);
   1.145  	     motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
   1.146  	     motionControl.setInitialDuration(10f);
   1.147  	     motionControl.setSpeed(0.1f);
   1.148  		 
   1.149  		 
   1.150 -		 path.enableDebugShape(assetManager, rootNode);
   1.151 +		 track.enableDebugShape(assetManager, rootNode);
   1.152  
   1.153  
   1.154  		 positionCamera();
   1.155 @@ -168,22 +168,43 @@
   1.156  
   1.157  	 
   1.158  	 private void positionCamera(){
   1.159 -		//this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
   1.160 +		this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
   1.161 +		// cam.setLocation(new Vector3f(0,0,-20));
   1.162  		this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f));
   1.163  	 }
   1.164 -	 
   1.165 -	 
   1.166 -	
   1.167 -	
   1.168  
   1.169    private AudioNode music;
   1.170    
   1.171    
   1.172 +
   1.173 +   
   1.174 +  
   1.175 +  private void initAudio() {
   1.176 +
   1.177 +	music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false);
   1.178 +	
   1.179 +    rootNode.attachChild(music);
   1.180 +    audioRenderer.playSource(music);
   1.181 +    
   1.182 +    music.setVolume(1f);
   1.183 +    music.setPositional(true);
   1.184 +    music.setMaxDistance(200.0f);
   1.185 +    music.setRefDistance(0.1f);
   1.186 +    music.setRolloffFactor(5f);
   1.187 +    audioRenderer.pauseSource(music); 
   1.188 +    
   1.189 +  }
   1.190 +
   1.191 +  
   1.192 +  
   1.193 +  
   1.194    private Listener auxListener = new Listener(); 
   1.195    public File data1 = new File("/home/r/tmp/data1.wav");
   1.196    public File data2 = new File("/home/r/tmp/data2.wav");
   1.197    public File data3 = new File("/home/r/tmp/data3.wav");
   1.198 -   
   1.199 +  public File data4 = new File("/home/r/tmp/data4.wav");
   1.200 +  public File data5 = new File("/home/r/tmp/data5.wav");
   1.201 +  public File data6 = new File("/home/r/tmp/data6.wav");
   1.202    
   1.203    
   1.204    public void simpleInitApp() {
   1.205 @@ -202,57 +223,16 @@
   1.206  		rf.registerSoundProcessor(new WaveFileWriter(data1));
   1.207  		rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2));
   1.208  		rf.registerSoundProcessor(listener3, new WaveFileWriter(data3));
   1.209 -	}
   1.210 -    
   1.211 -    
   1.212 -    
   1.213 -        
   1.214 -    
   1.215 -    
   1.216 +	}   
   1.217      initAudio();
   1.218      initKeys();
   1.219  	createScene();
   1.220 -	 
   1.221 -
   1.222      motionControl.play();
   1.223 -	
   1.224 -	//this.audioRenderer.playSource(music);
   1.225 -
   1.226 -	
   1.227 -
   1.228    }
   1.229  
   1.230 -  /** We create two audio nodes. */ 
   1.231 -  private void initAudio() {
   1.232 -	//audioRenderer.setEnvironment(Environment.Cavern);
   1.233 -    
   1.234 -	music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false);
   1.235 -	
   1.236 -	//music.setLooping(true);
   1.237 -    
   1.238 -   
   1.239 -	
   1.240 -    
   1.241 -    
   1.242 -    rootNode.attachChild(music);
   1.243 -    audioRenderer.playSource(music);
   1.244 -    
   1.245 -    music.setVolume(1f);
   1.246 -    music.setPositional(true);
   1.247 -    music.setMaxDistance(200.0f);
   1.248 -    music.setRefDistance(0.1f);
   1.249 -    music.setRolloffFactor(5f);
   1.250 -    audioRenderer.pauseSource(music);
   1.251 -    
   1.252 -    
   1.253 -    
   1.254 -  }
   1.255 + 
   1.256  
   1.257 -  /** Declaring the "Shoot" action, and
   1.258 -   *  mapping it to a trigger (mouse click). */
   1.259 -  
   1.260  
   1.261 -  /** Defining the "Shoot" action: Play a gun sound. */
   1.262    
   1.263    private void initKeys() {
   1.264  	  inputManager.addMapping("Shoot", new MouseButtonTrigger(0));
   1.265 @@ -275,7 +255,9 @@
   1.266    };
   1.267  
   1.268    /** Move the listener with the camera - for 3D audio. */
   1.269 -  @Override
   1.270 +  
   1.271 +  
   1.272 +  private Vector3f prevBellPos = Vector3f.ZERO;
   1.273    public void simpleUpdate(float tpf) {
   1.274  	//Vector3f loc = cam.getLocation();
   1.275  	//Quaternion rot = cam.getRotation();
   1.276 @@ -293,7 +275,11 @@
   1.277      //}
   1.278      //audioRenderer.updateSourceParam(music, AudioParam.Direction);
   1.279      
   1.280 +    Vector3f bellVelocity = bell.getLocalTranslation().subtract(prevBellPos).mult(1.0f/tpf);
   1.281 +    prevBellPos = bell.getLocalTranslation();
   1.282 +    
   1.283      music.setLocalTranslation(bell.getLocalTranslation());
   1.284 +    music.setVelocity(bellVelocity);
   1.285      
   1.286      //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_MIN_GAIN, 0f);
   1.287      //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_ROLLOFF_FACTOR, 5f);