changeset 62:f5e52169f056

updated to work with new jme changes
author Robert McIntyre <rlm@mit.edu>
date Wed, 14 Dec 2011 17:43:52 -0700
parents 76581e11fb72
children df4a2d12ea13
files build.xml src/com/aurellem/capture/AurellemSystemDelegate.java src/com/aurellem/capture/FixSettings.java src/com/aurellem/capture/IsoTimer.java src/com/aurellem/capture/examples/Advanced.java
diffstat 5 files changed, 307 insertions(+), 264 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/build.xml	Sat Dec 03 23:49:14 2011 -0600
     1.2 +++ b/build.xml	Wed Dec 14 17:43:52 2011 -0700
     1.3 @@ -28,6 +28,8 @@
     1.4  
     1.5    <target name="prepare">
     1.6      <mkdir dir="${build}"/>
     1.7 +    <mkdir dir="${dist}"/> 
     1.8 +    <mkdir dir="${docs}"/>
     1.9    </target>
    1.10  
    1.11    <target name="compile" depends="prepare" >
    1.12 @@ -35,27 +37,30 @@
    1.13  	   classpathref="classpath"
    1.14  	   includeantruntime="false"/>
    1.15    </target>
    1.16 -
    1.17 -  <target name="dist" depends="compile,javadoc" >
    1.18 -    <mkdir dir="${dist}"/> 
    1.19 +  
    1.20 +  <target name="jar" depends="prepare,compile">
    1.21      <jar jarfile="${dist}/jmeCapture.jar">
    1.22  	 <fileset dir="${src}"/>
    1.23  	 <fileset dir="${build}"/>
    1.24      </jar>
    1.25    </target>
    1.26  
    1.27 +  <target name="javadoc" depends="prepare">
    1.28 +    <javadoc sourcepath="${src}"
    1.29 +	     classpathref="classpath"
    1.30 +	     destdir="${docs}"/>
    1.31 +  </target>
    1.32 +
    1.33 +  <target name="dist" depends="jar,javadoc" >
    1.34 +    
    1.35 +  </target>
    1.36 +
    1.37    <target name="clean"> 
    1.38      <delete dir="${build}"/> 
    1.39      <delete dir="${dist}"/> 
    1.40      <delete dir="${docs}"/>
    1.41    </target> 
    1.42  
    1.43 -  <target name="javadoc">
    1.44 -    <mkdir dir="${docs}"/>
    1.45 -    <javadoc sourcepath="${src}"
    1.46 -	     classpathref="classpath"
    1.47 -	     destdir="${docs}"/>
    1.48 -  </target>
    1.49  
    1.50  </project>
    1.51  
     2.1 --- a/src/com/aurellem/capture/AurellemSystemDelegate.java	Sat Dec 03 23:49:14 2011 -0600
     2.2 +++ b/src/com/aurellem/capture/AurellemSystemDelegate.java	Wed Dec 14 17:43:52 2011 -0700
     2.3 @@ -11,11 +11,14 @@
     2.4  	
     2.5  	public AudioRenderer newAudioRenderer(AppSettings settings) {
     2.6          initialize(settings);
     2.7 -        if (settings.getAudioRenderer() == SEND){
     2.8 +        if (settings.getAudioRenderer().equals(SEND)){
     2.9 +        	System.out.println("fuck me");
    2.10          	return new AudioSendRenderer();
    2.11          }
    2.12          else {
    2.13 -        	return super.newAudioRenderer(settings);        	
    2.14 -        }        
    2.15 -    }	
    2.16 +        	System.out.println("fuck you , I'm eating\n");
    2.17 +        	return super.newAudioRenderer(settings);
    2.18 +        }
    2.19 +        
    2.20 +	}	
    2.21  }
    2.22 \ No newline at end of file
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/com/aurellem/capture/FixSettings.java	Wed Dec 14 17:43:52 2011 -0700
     3.3 @@ -0,0 +1,31 @@
     3.4 +package com.aurellem.capture;
     3.5 +
     3.6 +import jme3test.helloworld.HelloLoop;
     3.7 +
     3.8 +import com.jme3.app.Application;
     3.9 +import com.jme3.system.AppSettings;
    3.10 +
    3.11 +
    3.12 +/**
    3.13 + * jMonkeyEngine will save the settings used in previous runs.
    3.14 + * This can be especially frustrating when it saves the "Send" 
    3.15 + * AudioRenderer setting from running the a program that is 
    3.16 + * capturing audio.  This resets your settings to fix the problem.
    3.17 + * 
    3.18 + * if you get 
    3.19 + *  "Unrecognizable audio renderer specified: Send"
    3.20 + * run this program.
    3.21 + * 
    3.22 + * @author Robert McIntyre
    3.23 + *
    3.24 + */
    3.25 +
    3.26 +public class FixSettings {
    3.27 +
    3.28 +	public static void main(String[] ignore){
    3.29 +		Application app = new HelloLoop();
    3.30 +		AppSettings basic = new AppSettings(true);
    3.31 +		app.setSettings(basic);
    3.32 +		app.start();
    3.33 +	}
    3.34 +}
     4.1 --- a/src/com/aurellem/capture/IsoTimer.java	Sat Dec 03 23:49:14 2011 -0600
     4.2 +++ b/src/com/aurellem/capture/IsoTimer.java	Wed Dec 14 17:43:52 2011 -0700
     4.3 @@ -36,32 +36,32 @@
     4.4  
     4.5  public class IsoTimer extends Timer {
     4.6  
     4.7 -    private float framerate;
     4.8 -    private int ticks;
     4.9 -	
    4.10 -    public IsoTimer(float framerate){
    4.11 -	this.framerate = framerate;
    4.12 -	this.ticks = 0;
    4.13 -    }
    4.14 -	
    4.15 -    public long getTime() {
    4.16 -	return (long) (this.ticks / this.framerate);
    4.17 -    }
    4.18 -	
    4.19 -    public long getResolution() {
    4.20 -	return 1000000000L;
    4.21 -    }
    4.22 -	
    4.23 -    public float getFrameRate() {
    4.24 -	return this.framerate;
    4.25 -    }
    4.26 -	
    4.27 -    public float getTimePerFrame() {
    4.28 -	return (float) (1.0f / this.framerate);
    4.29 -    }
    4.30 +	private long framerate;
    4.31 +	private int ticks;
    4.32  
    4.33 -    public void update() {this.ticks++;}
    4.34 -	
    4.35 -    public void reset() {this.ticks = 0;}
    4.36 +	public IsoTimer(float framerate){
    4.37 +		this.framerate = (long) framerate;
    4.38 +		this.ticks = 0;
    4.39 +	}
    4.40 +
    4.41 +	public long getTime() {
    4.42 +		return this.ticks;
    4.43 +	}
    4.44 +
    4.45 +	public long getResolution() {
    4.46 +		return (long) framerate;
    4.47 +	}
    4.48 +
    4.49 +	public float getFrameRate() {
    4.50 +		return this.framerate;
    4.51 +	}
    4.52 +
    4.53 +	public float getTimePerFrame() {
    4.54 +		return (float) (1.0f / this.framerate);
    4.55 +	}
    4.56 +
    4.57 +	public void update() {this.ticks++;}
    4.58 +
    4.59 +	public void reset() {this.ticks = 0;}
    4.60  
    4.61  }
     5.1 --- a/src/com/aurellem/capture/examples/Advanced.java	Sat Dec 03 23:49:14 2011 -0600
     5.2 +++ b/src/com/aurellem/capture/examples/Advanced.java	Wed Dec 14 17:43:52 2011 -0700
     5.3 @@ -1,7 +1,6 @@
     5.4  package com.aurellem.capture.examples;
     5.5  
     5.6  import java.io.File;
     5.7 -import java.io.FileNotFoundException;
     5.8  import java.io.IOException;
     5.9  import java.lang.reflect.Field;
    5.10  import java.nio.ByteBuffer;
    5.11 @@ -55,248 +54,253 @@
    5.12  
    5.13  public class Advanced extends SimpleApplication {
    5.14  
    5.15 -    /**
    5.16 -     * You will see three grey cubes, a blue sphere, and a path which
    5.17 -     * circles each cube.  The blue sphere is generating a constant
    5.18 -     * monotone sound as it moves along the track.  Each cube is
    5.19 -     * listening for sound; when a cube hears sound whose intensity is
    5.20 -     * greater than a certain threshold, it changes its color from
    5.21 -     * grey to green.
    5.22 -     * 
    5.23 -     *  Each cube is also saving whatever it hears to a file.  The
    5.24 -     *  scene from the perspective of the viewer is also saved to a
    5.25 -     *  video file.  When you listen to each of the sound files
    5.26 -     *  alongside the video, the sound will get louder when the sphere
    5.27 -     *  approaches the cube that generated that sound file.  This
    5.28 -     *  shows that each listener is hearing the world from its own
    5.29 -     *  perspective.
    5.30 -     * 
    5.31 -     */
    5.32 -    public static void main(String[] args) {
    5.33 -	Advanced app = new Advanced();
    5.34 -	AppSettings settings = new AppSettings(true);
    5.35 -	settings.setAudioRenderer(AurellemSystemDelegate.SEND);
    5.36 -	JmeSystem.setSystemDelegate(new AurellemSystemDelegate());
    5.37 -	app.setSettings(settings);
    5.38 -	app.setShowSettings(false);
    5.39 -	app.setPauseOnLostFocus(false);
    5.40 +	/**
    5.41 +	 * You will see three grey cubes, a blue sphere, and a path which
    5.42 +	 * circles each cube.  The blue sphere is generating a constant
    5.43 +	 * monotone sound as it moves along the track.  Each cube is
    5.44 +	 * listening for sound; when a cube hears sound whose intensity is
    5.45 +	 * greater than a certain threshold, it changes its color from
    5.46 +	 * grey to green.
    5.47 +	 * 
    5.48 +	 *  Each cube is also saving whatever it hears to a file.  The
    5.49 +	 *  scene from the perspective of the viewer is also saved to a
    5.50 +	 *  video file.  When you listen to each of the sound files
    5.51 +	 *  alongside the video, the sound will get louder when the sphere
    5.52 +	 *  approaches the cube that generated that sound file.  This
    5.53 +	 *  shows that each listener is hearing the world from its own
    5.54 +	 *  perspective.
    5.55 +	 * 
    5.56 +	 */
    5.57 +	public static void main(String[] args) {
    5.58 +		Advanced app = new Advanced();
    5.59 +		AppSettings settings = new AppSettings(true);
    5.60 +		settings.setAudioRenderer(AurellemSystemDelegate.SEND);
    5.61 +		JmeSystem.setSystemDelegate(new AurellemSystemDelegate());
    5.62 +		app.setSettings(settings);
    5.63 +		app.setShowSettings(false);
    5.64 +		app.setPauseOnLostFocus(false);
    5.65  		
    5.66 -	try {
    5.67 -	    Capture.captureVideo(app, File.createTempFile("advanced",".avi"));
    5.68 -	    Capture.captureAudio(app, File.createTempFile("advanced", ".wav"));
    5.69 -	}
    5.70 -	catch (IOException e) {e.printStackTrace();}
    5.71 -		
    5.72 -	app.start();
    5.73 -    }
    5.74 -
    5.75 -	
    5.76 -    private Geometry bell;
    5.77 -    private Geometry ear1;
    5.78 -    private Geometry ear2;
    5.79 -    private Geometry ear3;
    5.80 -    private AudioNode music;
    5.81 -    private MotionTrack motionControl;
    5.82 -		
    5.83 -    private Geometry makeEar(Node root, Vector3f position){
    5.84 -	Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    5.85 -	Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f));
    5.86 -	ear.setLocalTranslation(position);
    5.87 -	mat.setColor("Color", ColorRGBA.Green);
    5.88 -	ear.setMaterial(mat);
    5.89 -	root.attachChild(ear);
    5.90 -	return ear;
    5.91 -    } 
    5.92 -
    5.93 -    private Vector3f[] path = new Vector3f[]{
    5.94 -	// loop 1
    5.95 -	new Vector3f(0, 0, 0),
    5.96 -	new Vector3f(0, 0, -10),
    5.97 -	new Vector3f(-2, 0, -14),
    5.98 -	new Vector3f(-6, 0, -20),
    5.99 -	new Vector3f(0, 0, -26),
   5.100 -	new Vector3f(6, 0, -20),
   5.101 -	new Vector3f(0, 0, -14),
   5.102 -	new Vector3f(-6, 0, -20),
   5.103 -	new Vector3f(0, 0, -26),
   5.104 -	new Vector3f(6, 0, -20),
   5.105 -	// loop 2
   5.106 -	new Vector3f(5, 0, -5),
   5.107 -	new Vector3f(7, 0, 1.5f),
   5.108 -	new Vector3f(14, 0, 2),
   5.109 -	new Vector3f(20, 0, 6),
   5.110 -	new Vector3f(26, 0, 0),
   5.111 -	new Vector3f(20, 0, -6),
   5.112 -	new Vector3f(14, 0, 0),
   5.113 -	new Vector3f(20, 0, 6),
   5.114 -	new Vector3f(26, 0, 0),
   5.115 -	new Vector3f(20, 0, -6),
   5.116 -	new Vector3f(14, 0, 0),
   5.117 -	// loop 3
   5.118 -	new Vector3f(8, 0, 7.5f),
   5.119 -	new Vector3f(7, 0, 10.5f),
   5.120 -	new Vector3f(6, 0, 20),
   5.121 -	new Vector3f(0, 0, 26),
   5.122 -	new Vector3f(-6, 0, 20),
   5.123 -	new Vector3f(0, 0, 14),
   5.124 -	new Vector3f(6, 0, 20),
   5.125 -	new Vector3f(0, 0, 26),
   5.126 -	new Vector3f(-6, 0, 20),
   5.127 -	new Vector3f(0, 0, 14),
   5.128 -	// begin ellipse
   5.129 -	new Vector3f(16, 5, 20),
   5.130 -	new Vector3f(0, 0, 26),
   5.131 -	new Vector3f(-16, -10, 20),
   5.132 -	new Vector3f(0, 0, 14),
   5.133 -	new Vector3f(16, 20, 20),
   5.134 -	new Vector3f(0, 0, 26),
   5.135 -	new Vector3f(-10, -25, 10),
   5.136 -	new Vector3f(-10, 0, 0),
   5.137 -	// come at me!
   5.138 -	new Vector3f(-28.00242f, 48.005623f, -34.648228f),
   5.139 -	new Vector3f(0, 0 , -20),
   5.140 -    };
   5.141 -
   5.142 -    private void createScene() {
   5.143 -	Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   5.144 -	bell = new Geometry( "sound-emitter" , new Sphere(15,15,1));
   5.145 -	mat.setColor("Color", ColorRGBA.Blue);
   5.146 -	bell.setMaterial(mat);
   5.147 -	rootNode.attachChild(bell);
   5.148 -
   5.149 -	ear1 = makeEar(rootNode, new Vector3f(0, 0 ,-20));
   5.150 -	ear2 = makeEar(rootNode, new Vector3f(0, 0 ,20));
   5.151 -	ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0));
   5.152 -
   5.153 -	MotionPath track = new MotionPath();
   5.154 -
   5.155 -	for (Vector3f v : path){
   5.156 -	    track.addWayPoint(v);
   5.157 -	}
   5.158 -	track.setCurveTension(0.80f);
   5.159 -
   5.160 -	motionControl = new MotionTrack(bell,track);
   5.161 -		
   5.162 -	// for now, use reflection to change the timer... 
   5.163 -	// motionControl.setTimer(new IsoTimer(60));
   5.164 -	try {
   5.165 -	    Field timerField;
   5.166 -	    timerField = AbstractCinematicEvent.class.getDeclaredField("timer");
   5.167 -	    timerField.setAccessible(true);
   5.168 -	    try {timerField.set(motionControl, new IsoTimer(60));} 
   5.169 -	    catch (IllegalArgumentException e) {e.printStackTrace();} 
   5.170 -	    catch (IllegalAccessException e) {e.printStackTrace();}
   5.171 -	} 
   5.172 -	catch (SecurityException e) {e.printStackTrace();} 
   5.173 -	catch (NoSuchFieldException e) {e.printStackTrace();}
   5.174 -		
   5.175 -	motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation);
   5.176 -	motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
   5.177 -	motionControl.setInitialDuration(20f);
   5.178 -	motionControl.setSpeed(1f);
   5.179 -
   5.180 -	track.enableDebugShape(assetManager, rootNode);
   5.181 -	positionCamera();
   5.182 -    }
   5.183 -
   5.184 -
   5.185 -    private void positionCamera(){
   5.186 -	this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
   5.187 -	this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f));
   5.188 -    }
   5.189 -
   5.190 -    private void initAudio() {
   5.191 -	org.lwjgl.input.Mouse.setGrabbed(false);	
   5.192 -	music = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", false);
   5.193 -
   5.194 -	rootNode.attachChild(music);
   5.195 -	audioRenderer.playSource(music);
   5.196 -	music.setPositional(true);
   5.197 -	music.setVolume(1f);
   5.198 -	music.setReverbEnabled(false);
   5.199 -	music.setDirectional(false);
   5.200 -	music.setMaxDistance(200.0f);
   5.201 -	music.setRefDistance(1f);
   5.202 -	//music.setRolloffFactor(1f);
   5.203 -	music.setLooping(false);
   5.204 -	audioRenderer.pauseSource(music); 
   5.205 -    }
   5.206 -
   5.207 -    public class Dancer implements SoundProcessor {
   5.208 -	Geometry entity;
   5.209 -	float scale = 2;
   5.210 -	public Dancer(Geometry entity){
   5.211 -	    this.entity = entity;
   5.212 +		try {
   5.213 +			//Capture.captureVideo(app, File.createTempFile("advanced",".avi"));
   5.214 +			Capture.captureAudio(app, File.createTempFile("advanced", ".wav"));
   5.215 +		}
   5.216 +		catch (IOException e) {e.printStackTrace();}
   5.217 +		 
   5.218 +		app.start();
   5.219  	}
   5.220  
   5.221 -	/**
   5.222 -	 * this method is irrelevant since there is no state to cleanup.
   5.223 -	 */
   5.224 -	public void cleanup() {}
   5.225  
   5.226 +	private Geometry bell;
   5.227 +	private Geometry ear1;
   5.228 +	private Geometry ear2;
   5.229 +	private Geometry ear3;
   5.230 +	private AudioNode music;
   5.231 +	private MotionTrack motionControl;
   5.232 +	private IsoTimer motionTimer = new IsoTimer(60);
   5.233  
   5.234 -	/**
   5.235 -	 * Respond to sound!  This is the brain of an AI entity that 
   5.236 -	 * hears it's surroundings and reacts to them.
   5.237 -	 */
   5.238 -	public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) {
   5.239 -	    audioSamples.clear();
   5.240 -	    byte[] data = new byte[numSamples];
   5.241 -	    float[] out = new float[numSamples];
   5.242 -	    audioSamples.get(data);
   5.243 -	    FloatSampleTools.byte2floatInterleaved(data, 0, out, 0, 
   5.244 -						   numSamples/format.getFrameSize(), format);
   5.245 +	private Geometry makeEar(Node root, Vector3f position){
   5.246 +		Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   5.247 +		Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f));
   5.248 +		ear.setLocalTranslation(position);
   5.249 +		mat.setColor("Color", ColorRGBA.Green);
   5.250 +		ear.setMaterial(mat);
   5.251 +		root.attachChild(ear);
   5.252 +		return ear;
   5.253 +	} 
   5.254  
   5.255 -	    float max = Float.NEGATIVE_INFINITY;
   5.256 -	    for (float f : out){if (f > max) max = f;}
   5.257 -	    audioSamples.clear();
   5.258 +	private Vector3f[] path = new Vector3f[]{
   5.259 +			// loop 1
   5.260 +			new Vector3f(0, 0, 0),
   5.261 +			new Vector3f(0, 0, -10),
   5.262 +			new Vector3f(-2, 0, -14),
   5.263 +			new Vector3f(-6, 0, -20),
   5.264 +			new Vector3f(0, 0, -26),
   5.265 +			new Vector3f(6, 0, -20),
   5.266 +			new Vector3f(0, 0, -14),
   5.267 +			new Vector3f(-6, 0, -20),
   5.268 +			new Vector3f(0, 0, -26),
   5.269 +			new Vector3f(6, 0, -20),
   5.270 +			// loop 2
   5.271 +			new Vector3f(5, 0, -5),
   5.272 +			new Vector3f(7, 0, 1.5f),
   5.273 +			new Vector3f(14, 0, 2),
   5.274 +			new Vector3f(20, 0, 6),
   5.275 +			new Vector3f(26, 0, 0),
   5.276 +			new Vector3f(20, 0, -6),
   5.277 +			new Vector3f(14, 0, 0),
   5.278 +			new Vector3f(20, 0, 6),
   5.279 +			new Vector3f(26, 0, 0),
   5.280 +			new Vector3f(20, 0, -6),
   5.281 +			new Vector3f(14, 0, 0),
   5.282 +			// loop 3
   5.283 +			new Vector3f(8, 0, 7.5f),
   5.284 +			new Vector3f(7, 0, 10.5f),
   5.285 +			new Vector3f(6, 0, 20),
   5.286 +			new Vector3f(0, 0, 26),
   5.287 +			new Vector3f(-6, 0, 20),
   5.288 +			new Vector3f(0, 0, 14),
   5.289 +			new Vector3f(6, 0, 20),
   5.290 +			new Vector3f(0, 0, 26),
   5.291 +			new Vector3f(-6, 0, 20),
   5.292 +			new Vector3f(0, 0, 14),
   5.293 +			// begin ellipse
   5.294 +			new Vector3f(16, 5, 20),
   5.295 +			new Vector3f(0, 0, 26),
   5.296 +			new Vector3f(-16, -10, 20),
   5.297 +			new Vector3f(0, 0, 14),
   5.298 +			new Vector3f(16, 20, 20),
   5.299 +			new Vector3f(0, 0, 26),
   5.300 +			new Vector3f(-10, -25, 10),
   5.301 +			new Vector3f(-10, 0, 0),
   5.302 +			// come at me!
   5.303 +			new Vector3f(-28.00242f, 48.005623f, -34.648228f),
   5.304 +			new Vector3f(0, 0 , -20),
   5.305 +	};
   5.306  
   5.307 -	    if (max > 0.1){entity.getMaterial().setColor("Color", ColorRGBA.Green);}
   5.308 -	    else {entity.getMaterial().setColor("Color", ColorRGBA.Gray);}
   5.309 +	private void createScene() {
   5.310 +		Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
   5.311 +		bell = new Geometry( "sound-emitter" , new Sphere(15,15,1));
   5.312 +		mat.setColor("Color", ColorRGBA.Blue);
   5.313 +		bell.setMaterial(mat);
   5.314 +		rootNode.attachChild(bell);
   5.315 +
   5.316 +		ear1 = makeEar(rootNode, new Vector3f(0, 0 ,-20));
   5.317 +		ear2 = makeEar(rootNode, new Vector3f(0, 0 ,20));
   5.318 +		ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0));
   5.319 +
   5.320 +		MotionPath track = new MotionPath();
   5.321 +
   5.322 +		for (Vector3f v : path){
   5.323 +			track.addWayPoint(v);
   5.324 +		}
   5.325 +		track.setCurveTension(0.80f);
   5.326 +
   5.327 +		motionControl = new MotionTrack(bell,track);
   5.328 +		// for now, use reflection to change the timer... 
   5.329 +		// motionControl.setTimer(new IsoTimer(60));
   5.330 +		
   5.331 +		try {
   5.332 +			Field timerField;
   5.333 +			timerField = AbstractCinematicEvent.class.getDeclaredField("timer");
   5.334 +			timerField.setAccessible(true);
   5.335 +			try {timerField.set(motionControl, motionTimer);} 
   5.336 +			catch (IllegalArgumentException e) {e.printStackTrace();} 
   5.337 +			catch (IllegalAccessException e) {e.printStackTrace();}
   5.338 +		} 
   5.339 +		catch (SecurityException e) {e.printStackTrace();} 
   5.340 +		catch (NoSuchFieldException e) {e.printStackTrace();}
   5.341 +
   5.342 +
   5.343 +		motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation);
   5.344 +		motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
   5.345 +		motionControl.setInitialDuration(20f);
   5.346 +		motionControl.setSpeed(1f);
   5.347 +
   5.348 +		track.enableDebugShape(assetManager, rootNode);
   5.349 +		positionCamera();
   5.350  	}
   5.351 -    }
   5.352  
   5.353 -    private void prepareEar(Geometry ear, int n){
   5.354 -	if (this.audioRenderer instanceof MultiListener){
   5.355 -	    MultiListener rf = (MultiListener)this.audioRenderer;
   5.356  
   5.357 -	    Listener auxListener = new Listener();
   5.358 -	    auxListener.setLocation(ear.getLocalTranslation());
   5.359 +	private void positionCamera(){
   5.360 +		this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
   5.361 +		this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f));
   5.362 +	}
   5.363  
   5.364 -	    rf.addListener(auxListener);
   5.365 -	    WaveFileWriter aux = null;
   5.366 +	private void initAudio() {
   5.367 +		org.lwjgl.input.Mouse.setGrabbed(false);	
   5.368 +		music = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", false);
   5.369  
   5.370 -	    try {aux = new WaveFileWriter(new File("/home/r/tmp/ear"+n+".wav"));} 
   5.371 -	    catch (FileNotFoundException e) {e.printStackTrace();}
   5.372 +		rootNode.attachChild(music);
   5.373 +		audioRenderer.playSource(music);
   5.374 +		music.setPositional(true);
   5.375 +		music.setVolume(1f);
   5.376 +		music.setReverbEnabled(false);
   5.377 +		music.setDirectional(false);
   5.378 +		music.setMaxDistance(200.0f);
   5.379 +		music.setRefDistance(1f);
   5.380 +		//music.setRolloffFactor(1f);
   5.381 +		music.setLooping(false);
   5.382 +		audioRenderer.pauseSource(music); 
   5.383 +	}
   5.384  
   5.385 -	    rf.registerSoundProcessor(auxListener, 
   5.386 -				      new CompositeSoundProcessor(new Dancer(ear), aux));
   5.387 -	}   
   5.388 -    }
   5.389 +	public class Dancer implements SoundProcessor {
   5.390 +		Geometry entity;
   5.391 +		float scale = 2;
   5.392 +		public Dancer(Geometry entity){
   5.393 +			this.entity = entity;
   5.394 +		}
   5.395  
   5.396 +		/**
   5.397 +		 * this method is irrelevant since there is no state to cleanup.
   5.398 +		 */
   5.399 +		public void cleanup() {}
   5.400  
   5.401 -    public void simpleInitApp() {
   5.402 -	this.setTimer(new IsoTimer(60));
   5.403 -	initAudio();
   5.404 -		
   5.405 -	createScene();
   5.406  
   5.407 -	prepareEar(ear1, 1);
   5.408 -	prepareEar(ear2, 1);
   5.409 -	prepareEar(ear3, 1);
   5.410 +		/**
   5.411 +		 * Respond to sound!  This is the brain of an AI entity that 
   5.412 +		 * hears its surroundings and reacts to them.
   5.413 +		 */
   5.414 +		public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) {
   5.415 +			audioSamples.clear();
   5.416 +			byte[] data = new byte[numSamples];
   5.417 +			float[] out = new float[numSamples];
   5.418 +			audioSamples.get(data);
   5.419 +			FloatSampleTools.byte2floatInterleaved(data, 0, out, 0, 
   5.420 +					numSamples/format.getFrameSize(), format);
   5.421  
   5.422 -	motionControl.play();
   5.423 -    }
   5.424 +			float max = Float.NEGATIVE_INFINITY;
   5.425 +			for (float f : out){if (f > max) max = f;}
   5.426 +			audioSamples.clear();
   5.427  
   5.428 -    public void simpleUpdate(float tpf) {
   5.429 -	if (music.getStatus() != AudioNode.Status.Playing){
   5.430 -	    music.play();
   5.431 +			if (max > 0.1){entity.getMaterial().setColor("Color", ColorRGBA.Green);}
   5.432 +			else {entity.getMaterial().setColor("Color", ColorRGBA.Gray);}
   5.433 +		}
   5.434  	}
   5.435 -	Vector3f loc = cam.getLocation();
   5.436 -	Quaternion rot = cam.getRotation();
   5.437 -	listener.setLocation(loc);
   5.438 -	listener.setRotation(rot);
   5.439 -	music.setLocalTranslation(bell.getLocalTranslation());
   5.440 -    }
   5.441 +
   5.442 +	private void prepareEar(Geometry ear, int n){
   5.443 +		if (this.audioRenderer instanceof MultiListener){
   5.444 +			MultiListener rf = (MultiListener)this.audioRenderer;
   5.445 +
   5.446 +			Listener auxListener = new Listener();
   5.447 +			auxListener.setLocation(ear.getLocalTranslation());
   5.448 +
   5.449 +			rf.addListener(auxListener);
   5.450 +			WaveFileWriter aux = null;
   5.451 +
   5.452 +			try {aux = new WaveFileWriter(File.createTempFile("advanced-audio-" + n, ".wav"));} 
   5.453 +			catch (IOException e) {e.printStackTrace();}
   5.454 +
   5.455 +			rf.registerSoundProcessor(auxListener, 
   5.456 +					new CompositeSoundProcessor(new Dancer(ear), aux));
   5.457 +					
   5.458 +		}   
   5.459 +	}
   5.460 +
   5.461 +
   5.462 +	public void simpleInitApp() {
   5.463 +		this.setTimer(new IsoTimer(60));
   5.464 +		initAudio();
   5.465 +
   5.466 +		createScene();
   5.467 +
   5.468 +		prepareEar(ear1, 1);
   5.469 +		prepareEar(ear2, 1);
   5.470 +		prepareEar(ear3, 1);
   5.471 +
   5.472 +		motionControl.play();
   5.473 +
   5.474 +	}
   5.475 +
   5.476 +	public void simpleUpdate(float tpf) {
   5.477 +		motionTimer.update();
   5.478 +		if (music.getStatus() != AudioNode.Status.Playing){
   5.479 +			music.play();
   5.480 +		}
   5.481 +		Vector3f loc = cam.getLocation();
   5.482 +		Quaternion rot = cam.getRotation();
   5.483 +		listener.setLocation(loc);
   5.484 +		listener.setRotation(rot);
   5.485 +		music.setLocalTranslation(bell.getLocalTranslation());
   5.486 +	}
   5.487  
   5.488  }