changeset 33:c4bfbf5d090e

starting to get something that can percieve sound
author Robert McIntyre <rlm@mit.edu>
date Sun, 30 Oct 2011 13:57:16 -0700
parents b67ffa8aa0b9
children 13d354e1184b
files build.xml src/com/aurellem/capture/audio/WaveFileWriter.java src/com/aurellem/capture/examples/AdvancedAudio.java
diffstat 3 files changed, 62 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/build.xml	Sun Oct 30 10:17:09 2011 -0700
     1.2 +++ b/build.xml	Sun Oct 30 13:57:16 2011 -0700
     1.3 @@ -20,7 +20,7 @@
     1.4      <pathelement path="${lib}/xuggle-xuggler.jar"/>
     1.5      <pathelement path="${lib}/xuggle-xuggler-test.jar"/>
     1.6      <pathelement path="${lib}/tritonus_aos-0.3.6.jar"/>
     1.7 -    <pathelement path="${lib}/tritonus_share.jar"/>
     1.8 +    <pathelement path="${lib}/tritonus_share-0.3.6.jar"/>
     1.9    </path>
    1.10  
    1.11    <target name="prepare">
     2.1 --- a/src/com/aurellem/capture/audio/WaveFileWriter.java	Sun Oct 30 10:17:09 2011 -0700
     2.2 +++ b/src/com/aurellem/capture/audio/WaveFileWriter.java	Sun Oct 30 13:57:16 2011 -0700
     2.3 @@ -32,7 +32,7 @@
     2.4  	}
     2.5  		
     2.6  	public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) {
     2.7 -	
     2.8 +		audioSamples.clear();
     2.9  		if (!initialized){
    2.10  			init(format);
    2.11  			initialized = true;
     3.1 --- a/src/com/aurellem/capture/examples/AdvancedAudio.java	Sun Oct 30 10:17:09 2011 -0700
     3.2 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java	Sun Oct 30 13:57:16 2011 -0700
     3.3 @@ -1,13 +1,20 @@
     3.4  package com.aurellem.capture.examples;
     3.5  
     3.6  import java.io.File;
     3.7 +import java.io.FileNotFoundException;
     3.8 +import java.io.IOException;
     3.9  import java.nio.ByteBuffer;
    3.10  
    3.11  import javax.sound.sampled.AudioFormat;
    3.12  
    3.13 +import org.tritonus.share.sampled.FloatSampleTools;
    3.14 +
    3.15 +import com.aurellem.capture.Capture;
    3.16  import com.aurellem.capture.IsoTimer;
    3.17 +import com.aurellem.capture.audio.CompositeSoundProcessor;
    3.18  import com.aurellem.capture.audio.MultiListener;
    3.19  import com.aurellem.capture.audio.SoundProcessor;
    3.20 +import com.aurellem.capture.audio.WaveFileWriter;
    3.21  import com.jme3.app.SimpleApplication;
    3.22  import com.jme3.audio.AudioNode;
    3.23  import com.jme3.audio.Listener;
    3.24 @@ -59,6 +66,8 @@
    3.25  			app.setShowSettings(false);
    3.26  			app.setPauseOnLostFocus(false);
    3.27  			org.lwjgl.input.Mouse.setGrabbed(false);
    3.28 +			try {Capture.captureVideo(app, new File("/home/r/tmp/out.avi"));}
    3.29 +			catch (IOException e) {e.printStackTrace();}
    3.30  			app.start();
    3.31  	  }
    3.32  	 
    3.33 @@ -162,10 +171,11 @@
    3.34  
    3.35  		 
    3.36  		 motionControl = new MotionTrack(bell,track);
    3.37 +		 motionControl.setTimer(new IsoTimer(60));
    3.38  	     motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation);
    3.39  	     motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
    3.40 -	     motionControl.setInitialDuration(10f);
    3.41 -	     motionControl.setSpeed(0.1f);
    3.42 +	     motionControl.setInitialDuration(20f);
    3.43 +	     motionControl.setSpeed(1f);
    3.44  		 
    3.45  		 
    3.46  		 track.enableDebugShape(assetManager, rootNode);
    3.47 @@ -195,12 +205,12 @@
    3.48  	
    3.49      rootNode.attachChild(music);
    3.50      audioRenderer.playSource(music);
    3.51 +    music.setPositional(true);
    3.52 +    //music.setVolume(1f);
    3.53      
    3.54 -    music.setVolume(1f);
    3.55 -    music.setPositional(true);
    3.56 -    music.setMaxDistance(200.0f);
    3.57 -    music.setRefDistance(0.1f);
    3.58 -    music.setRolloffFactor(5f);
    3.59 +    //music.setMaxDistance(200.0f);
    3.60 +    //music.setRefDistance(0.1f);
    3.61 +    //music.setRolloffFactor(5f);
    3.62      audioRenderer.pauseSource(music); 
    3.63      
    3.64    }
    3.65 @@ -222,9 +232,10 @@
    3.66  	  Spatial entity;
    3.67  
    3.68  	  float scale = 2;
    3.69 -	  
    3.70 -	  public Dancer(Spatial entity){
    3.71 +	  String debug;
    3.72 +	  public Dancer(Spatial entity, String debug){
    3.73  		  this.entity = entity;
    3.74 +		  this.debug = debug;
    3.75  	  }
    3.76  
    3.77  	  /**
    3.78 @@ -238,10 +249,24 @@
    3.79  	   * hears it's surroundings and reacts to them.
    3.80  	   */
    3.81  	  public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) {
    3.82 -		  //System.out.println("I'm DANCING <3");
    3.83 -		  entity.scale(this.scale);
    3.84 -		  if (this.scale == 2f){this.scale = 0.5f;}
    3.85 -		  else {this.scale = 2;}
    3.86 +		  audioSamples.clear();
    3.87 +		  byte[] data = new byte[numSamples];
    3.88 +		  float[] out = new float[numSamples];
    3.89 +		  audioSamples.get(data);
    3.90 +		  FloatSampleTools.byte2floatInterleaved(data, 0, out, 0, 
    3.91 +				  numSamples/format.getFrameSize(), format);
    3.92 +		  
    3.93 +		  float max = Float.NEGATIVE_INFINITY;
    3.94 +		  for (float f : out){if (f > max) max = f;}
    3.95 +		  
    3.96 +		  System.out.println(debug);
    3.97 +		  System.out.println(max);
    3.98 +		  
    3.99 +		  
   3.100 +		  
   3.101 +		  //entity.scale(this.scale);
   3.102 +		  //if (this.scale == 2f){this.scale = 0.5f;}
   3.103 +		  //else {this.scale = 2;}
   3.104  	  }
   3.105  
   3.106  
   3.107 @@ -260,10 +285,21 @@
   3.108  		
   3.109  		
   3.110  		rf.addListener(auxListener);
   3.111 +		WaveFileWriter writer = null;
   3.112 +		WaveFileWriter writer2 = null;
   3.113 +		auxListener.setLocation(ear1.getLocalTranslation());
   3.114 +		listener.setLocation(ear1.getLocalTranslation());
   3.115 +		try {writer = new WaveFileWriter(new File("/home/r/tmp/out.wav"));} 
   3.116 +		catch (FileNotFoundException e) {e.printStackTrace();}
   3.117  		
   3.118 -		//rf.registerSoundProcessor(new WaveFileWriter(data1));
   3.119 -		rf.registerSoundProcessor(auxListener, new Dancer(ear1));
   3.120 +		try {writer2 = new WaveFileWriter(new File("/home/r/tmp/outmain.wav"));} 
   3.121 +		catch (FileNotFoundException e) {e.printStackTrace();}
   3.122 +				
   3.123 +		rf.registerSoundProcessor(auxListener, 
   3.124 +				new CompositeSoundProcessor(new Dancer(ear1, "aux"), writer));
   3.125  		
   3.126 +		rf.registerSoundProcessor(
   3.127 +				new CompositeSoundProcessor(new Dancer(ear1, "main"), writer2));
   3.128  	}   
   3.129  
   3.130      motionControl.play();
   3.131 @@ -285,7 +321,7 @@
   3.132  		  if (name.equals("Shoot") && !keyPressed) {
   3.133  			  System.out.println("I'm playing! <3");
   3.134  			  System.out.println(bell.getLocalTranslation().subtract(cam.getLocation()).length());	
   3.135 -			  
   3.136 +			  bell.getMaterial().setColor("Color", ColorRGBA.randomColor());
   3.137  			  audioRenderer.playSource(music);
   3.138  			  System.out.println(music.getRefDistance());
   3.139  			 
   3.140 @@ -297,6 +333,8 @@
   3.141    
   3.142    
   3.143    private Vector3f prevBellPos = Vector3f.ZERO;
   3.144 +  
   3.145 +  
   3.146    public void simpleUpdate(float tpf) {
   3.147  	//Vector3f loc = cam.getLocation();
   3.148  	//Quaternion rot = cam.getRotation();
   3.149 @@ -304,14 +342,14 @@
   3.150      //listener.setRotation(rot);
   3.151      
   3.152      
   3.153 -    listener.setLocation(cam.getLocation());
   3.154 -    listener.setRotation(cam.getRotation());
   3.155 +    //listener.setLocation(cam.getLocation());
   3.156 +    //listener.setRotation(cam.getRotation());
   3.157      //auxListener.setLocation(loc);
   3.158      //auxListener.setRotation(rot);
   3.159 -    //if (music.getStatus() == AudioNode.Status.Stopped){
   3.160 -
   3.161 -    	//music.playInstance();
   3.162 -    //}
   3.163 +    if (music.getStatus() != AudioNode.Status.Playing){
   3.164 +    	audioRenderer.playSource(music);
   3.165 +    	bell.getMaterial().setColor("Color", ColorRGBA.randomColor());
   3.166 +    }
   3.167      //audioRenderer.updateSourceParam(music, AudioParam.Direction);
   3.168      
   3.169      Vector3f bellVelocity = bell.getLocalTranslation().subtract(prevBellPos).mult(1.0f/tpf);