# HG changeset patch # User Robert McIntyre # Date 1323909832 25200 # Node ID f5e52169f056c9bba5153c45cc63772e110c6982 # Parent 76581e11fb729f687ec2cb71b73eade6dfd3ae96 updated to work with new jme changes diff -r 76581e11fb72 -r f5e52169f056 build.xml --- a/build.xml Sat Dec 03 23:49:14 2011 -0600 +++ b/build.xml Wed Dec 14 17:43:52 2011 -0700 @@ -28,6 +28,8 @@ + + @@ -35,27 +37,30 @@ classpathref="classpath" includeantruntime="false"/> - - - + + + + + + + + + + - - - - diff -r 76581e11fb72 -r f5e52169f056 src/com/aurellem/capture/AurellemSystemDelegate.java --- a/src/com/aurellem/capture/AurellemSystemDelegate.java Sat Dec 03 23:49:14 2011 -0600 +++ b/src/com/aurellem/capture/AurellemSystemDelegate.java Wed Dec 14 17:43:52 2011 -0700 @@ -11,11 +11,14 @@ public AudioRenderer newAudioRenderer(AppSettings settings) { initialize(settings); - if (settings.getAudioRenderer() == SEND){ + if (settings.getAudioRenderer().equals(SEND)){ + System.out.println("fuck me"); return new AudioSendRenderer(); } else { - return super.newAudioRenderer(settings); - } - } + System.out.println("fuck you , I'm eating\n"); + return super.newAudioRenderer(settings); + } + + } } \ No newline at end of file diff -r 76581e11fb72 -r f5e52169f056 src/com/aurellem/capture/FixSettings.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/aurellem/capture/FixSettings.java Wed Dec 14 17:43:52 2011 -0700 @@ -0,0 +1,31 @@ +package com.aurellem.capture; + +import jme3test.helloworld.HelloLoop; + +import com.jme3.app.Application; +import com.jme3.system.AppSettings; + + +/** + * jMonkeyEngine will save the settings used in previous runs. + * This can be especially frustrating when it saves the "Send" + * AudioRenderer setting from running the a program that is + * capturing audio. This resets your settings to fix the problem. + * + * if you get + * "Unrecognizable audio renderer specified: Send" + * run this program. + * + * @author Robert McIntyre + * + */ + +public class FixSettings { + + public static void main(String[] ignore){ + Application app = new HelloLoop(); + AppSettings basic = new AppSettings(true); + app.setSettings(basic); + app.start(); + } +} diff -r 76581e11fb72 -r f5e52169f056 src/com/aurellem/capture/IsoTimer.java --- a/src/com/aurellem/capture/IsoTimer.java Sat Dec 03 23:49:14 2011 -0600 +++ b/src/com/aurellem/capture/IsoTimer.java Wed Dec 14 17:43:52 2011 -0700 @@ -36,32 +36,32 @@ public class IsoTimer extends Timer { - private float framerate; - private int ticks; - - public IsoTimer(float framerate){ - this.framerate = framerate; - this.ticks = 0; - } - - public long getTime() { - return (long) (this.ticks / this.framerate); - } - - public long getResolution() { - return 1000000000L; - } - - public float getFrameRate() { - return this.framerate; - } - - public float getTimePerFrame() { - return (float) (1.0f / this.framerate); - } + private long framerate; + private int ticks; - public void update() {this.ticks++;} - - public void reset() {this.ticks = 0;} + public IsoTimer(float framerate){ + this.framerate = (long) framerate; + this.ticks = 0; + } + + public long getTime() { + return this.ticks; + } + + public long getResolution() { + return (long) framerate; + } + + public float getFrameRate() { + return this.framerate; + } + + public float getTimePerFrame() { + return (float) (1.0f / this.framerate); + } + + public void update() {this.ticks++;} + + public void reset() {this.ticks = 0;} } diff -r 76581e11fb72 -r f5e52169f056 src/com/aurellem/capture/examples/Advanced.java --- a/src/com/aurellem/capture/examples/Advanced.java Sat Dec 03 23:49:14 2011 -0600 +++ b/src/com/aurellem/capture/examples/Advanced.java Wed Dec 14 17:43:52 2011 -0700 @@ -1,7 +1,6 @@ package com.aurellem.capture.examples; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Field; import java.nio.ByteBuffer; @@ -55,248 +54,253 @@ public class Advanced extends SimpleApplication { - /** - * You will see three grey cubes, a blue sphere, and a path which - * circles each cube. The blue sphere is generating a constant - * monotone sound as it moves along the track. Each cube is - * listening for sound; when a cube hears sound whose intensity is - * greater than a certain threshold, it changes its color from - * grey to green. - * - * Each cube is also saving whatever it hears to a file. The - * scene from the perspective of the viewer is also saved to a - * video file. When you listen to each of the sound files - * alongside the video, the sound will get louder when the sphere - * approaches the cube that generated that sound file. This - * shows that each listener is hearing the world from its own - * perspective. - * - */ - public static void main(String[] args) { - Advanced app = new Advanced(); - AppSettings settings = new AppSettings(true); - settings.setAudioRenderer(AurellemSystemDelegate.SEND); - JmeSystem.setSystemDelegate(new AurellemSystemDelegate()); - app.setSettings(settings); - app.setShowSettings(false); - app.setPauseOnLostFocus(false); + /** + * You will see three grey cubes, a blue sphere, and a path which + * circles each cube. The blue sphere is generating a constant + * monotone sound as it moves along the track. Each cube is + * listening for sound; when a cube hears sound whose intensity is + * greater than a certain threshold, it changes its color from + * grey to green. + * + * Each cube is also saving whatever it hears to a file. The + * scene from the perspective of the viewer is also saved to a + * video file. When you listen to each of the sound files + * alongside the video, the sound will get louder when the sphere + * approaches the cube that generated that sound file. This + * shows that each listener is hearing the world from its own + * perspective. + * + */ + public static void main(String[] args) { + Advanced app = new Advanced(); + AppSettings settings = new AppSettings(true); + settings.setAudioRenderer(AurellemSystemDelegate.SEND); + JmeSystem.setSystemDelegate(new AurellemSystemDelegate()); + app.setSettings(settings); + app.setShowSettings(false); + app.setPauseOnLostFocus(false); - try { - Capture.captureVideo(app, File.createTempFile("advanced",".avi")); - Capture.captureAudio(app, File.createTempFile("advanced", ".wav")); - } - catch (IOException e) {e.printStackTrace();} - - app.start(); - } - - - private Geometry bell; - private Geometry ear1; - private Geometry ear2; - private Geometry ear3; - private AudioNode music; - private MotionTrack motionControl; - - private Geometry makeEar(Node root, Vector3f position){ - Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); - Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f)); - ear.setLocalTranslation(position); - mat.setColor("Color", ColorRGBA.Green); - ear.setMaterial(mat); - root.attachChild(ear); - return ear; - } - - private Vector3f[] path = new Vector3f[]{ - // loop 1 - new Vector3f(0, 0, 0), - new Vector3f(0, 0, -10), - new Vector3f(-2, 0, -14), - new Vector3f(-6, 0, -20), - new Vector3f(0, 0, -26), - new Vector3f(6, 0, -20), - new Vector3f(0, 0, -14), - new Vector3f(-6, 0, -20), - new Vector3f(0, 0, -26), - new Vector3f(6, 0, -20), - // loop 2 - new Vector3f(5, 0, -5), - new Vector3f(7, 0, 1.5f), - new Vector3f(14, 0, 2), - new Vector3f(20, 0, 6), - new Vector3f(26, 0, 0), - new Vector3f(20, 0, -6), - new Vector3f(14, 0, 0), - new Vector3f(20, 0, 6), - new Vector3f(26, 0, 0), - new Vector3f(20, 0, -6), - new Vector3f(14, 0, 0), - // loop 3 - new Vector3f(8, 0, 7.5f), - new Vector3f(7, 0, 10.5f), - new Vector3f(6, 0, 20), - new Vector3f(0, 0, 26), - new Vector3f(-6, 0, 20), - new Vector3f(0, 0, 14), - new Vector3f(6, 0, 20), - new Vector3f(0, 0, 26), - new Vector3f(-6, 0, 20), - new Vector3f(0, 0, 14), - // begin ellipse - new Vector3f(16, 5, 20), - new Vector3f(0, 0, 26), - new Vector3f(-16, -10, 20), - new Vector3f(0, 0, 14), - new Vector3f(16, 20, 20), - new Vector3f(0, 0, 26), - new Vector3f(-10, -25, 10), - new Vector3f(-10, 0, 0), - // come at me! - new Vector3f(-28.00242f, 48.005623f, -34.648228f), - new Vector3f(0, 0 , -20), - }; - - private void createScene() { - Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); - bell = new Geometry( "sound-emitter" , new Sphere(15,15,1)); - mat.setColor("Color", ColorRGBA.Blue); - bell.setMaterial(mat); - rootNode.attachChild(bell); - - ear1 = makeEar(rootNode, new Vector3f(0, 0 ,-20)); - ear2 = makeEar(rootNode, new Vector3f(0, 0 ,20)); - ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0)); - - MotionPath track = new MotionPath(); - - for (Vector3f v : path){ - track.addWayPoint(v); - } - track.setCurveTension(0.80f); - - motionControl = new MotionTrack(bell,track); - - // for now, use reflection to change the timer... - // motionControl.setTimer(new IsoTimer(60)); - try { - Field timerField; - timerField = AbstractCinematicEvent.class.getDeclaredField("timer"); - timerField.setAccessible(true); - try {timerField.set(motionControl, new IsoTimer(60));} - catch (IllegalArgumentException e) {e.printStackTrace();} - catch (IllegalAccessException e) {e.printStackTrace();} - } - catch (SecurityException e) {e.printStackTrace();} - catch (NoSuchFieldException e) {e.printStackTrace();} - - motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation); - motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y)); - motionControl.setInitialDuration(20f); - motionControl.setSpeed(1f); - - track.enableDebugShape(assetManager, rootNode); - positionCamera(); - } - - - private void positionCamera(){ - this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); - this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f)); - } - - private void initAudio() { - org.lwjgl.input.Mouse.setGrabbed(false); - music = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", false); - - rootNode.attachChild(music); - audioRenderer.playSource(music); - music.setPositional(true); - music.setVolume(1f); - music.setReverbEnabled(false); - music.setDirectional(false); - music.setMaxDistance(200.0f); - music.setRefDistance(1f); - //music.setRolloffFactor(1f); - music.setLooping(false); - audioRenderer.pauseSource(music); - } - - public class Dancer implements SoundProcessor { - Geometry entity; - float scale = 2; - public Dancer(Geometry entity){ - this.entity = entity; + try { + //Capture.captureVideo(app, File.createTempFile("advanced",".avi")); + Capture.captureAudio(app, File.createTempFile("advanced", ".wav")); + } + catch (IOException e) {e.printStackTrace();} + + app.start(); } - /** - * this method is irrelevant since there is no state to cleanup. - */ - public void cleanup() {} + private Geometry bell; + private Geometry ear1; + private Geometry ear2; + private Geometry ear3; + private AudioNode music; + private MotionTrack motionControl; + private IsoTimer motionTimer = new IsoTimer(60); - /** - * Respond to sound! This is the brain of an AI entity that - * hears it's surroundings and reacts to them. - */ - public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) { - audioSamples.clear(); - byte[] data = new byte[numSamples]; - float[] out = new float[numSamples]; - audioSamples.get(data); - FloatSampleTools.byte2floatInterleaved(data, 0, out, 0, - numSamples/format.getFrameSize(), format); + private Geometry makeEar(Node root, Vector3f position){ + Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); + Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f)); + ear.setLocalTranslation(position); + mat.setColor("Color", ColorRGBA.Green); + ear.setMaterial(mat); + root.attachChild(ear); + return ear; + } - float max = Float.NEGATIVE_INFINITY; - for (float f : out){if (f > max) max = f;} - audioSamples.clear(); + private Vector3f[] path = new Vector3f[]{ + // loop 1 + new Vector3f(0, 0, 0), + new Vector3f(0, 0, -10), + new Vector3f(-2, 0, -14), + new Vector3f(-6, 0, -20), + new Vector3f(0, 0, -26), + new Vector3f(6, 0, -20), + new Vector3f(0, 0, -14), + new Vector3f(-6, 0, -20), + new Vector3f(0, 0, -26), + new Vector3f(6, 0, -20), + // loop 2 + new Vector3f(5, 0, -5), + new Vector3f(7, 0, 1.5f), + new Vector3f(14, 0, 2), + new Vector3f(20, 0, 6), + new Vector3f(26, 0, 0), + new Vector3f(20, 0, -6), + new Vector3f(14, 0, 0), + new Vector3f(20, 0, 6), + new Vector3f(26, 0, 0), + new Vector3f(20, 0, -6), + new Vector3f(14, 0, 0), + // loop 3 + new Vector3f(8, 0, 7.5f), + new Vector3f(7, 0, 10.5f), + new Vector3f(6, 0, 20), + new Vector3f(0, 0, 26), + new Vector3f(-6, 0, 20), + new Vector3f(0, 0, 14), + new Vector3f(6, 0, 20), + new Vector3f(0, 0, 26), + new Vector3f(-6, 0, 20), + new Vector3f(0, 0, 14), + // begin ellipse + new Vector3f(16, 5, 20), + new Vector3f(0, 0, 26), + new Vector3f(-16, -10, 20), + new Vector3f(0, 0, 14), + new Vector3f(16, 20, 20), + new Vector3f(0, 0, 26), + new Vector3f(-10, -25, 10), + new Vector3f(-10, 0, 0), + // come at me! + new Vector3f(-28.00242f, 48.005623f, -34.648228f), + new Vector3f(0, 0 , -20), + }; - if (max > 0.1){entity.getMaterial().setColor("Color", ColorRGBA.Green);} - else {entity.getMaterial().setColor("Color", ColorRGBA.Gray);} + private void createScene() { + Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); + bell = new Geometry( "sound-emitter" , new Sphere(15,15,1)); + mat.setColor("Color", ColorRGBA.Blue); + bell.setMaterial(mat); + rootNode.attachChild(bell); + + ear1 = makeEar(rootNode, new Vector3f(0, 0 ,-20)); + ear2 = makeEar(rootNode, new Vector3f(0, 0 ,20)); + ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0)); + + MotionPath track = new MotionPath(); + + for (Vector3f v : path){ + track.addWayPoint(v); + } + track.setCurveTension(0.80f); + + motionControl = new MotionTrack(bell,track); + // for now, use reflection to change the timer... + // motionControl.setTimer(new IsoTimer(60)); + + try { + Field timerField; + timerField = AbstractCinematicEvent.class.getDeclaredField("timer"); + timerField.setAccessible(true); + try {timerField.set(motionControl, motionTimer);} + catch (IllegalArgumentException e) {e.printStackTrace();} + catch (IllegalAccessException e) {e.printStackTrace();} + } + catch (SecurityException e) {e.printStackTrace();} + catch (NoSuchFieldException e) {e.printStackTrace();} + + + motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation); + motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y)); + motionControl.setInitialDuration(20f); + motionControl.setSpeed(1f); + + track.enableDebugShape(assetManager, rootNode); + positionCamera(); } - } - private void prepareEar(Geometry ear, int n){ - if (this.audioRenderer instanceof MultiListener){ - MultiListener rf = (MultiListener)this.audioRenderer; - Listener auxListener = new Listener(); - auxListener.setLocation(ear.getLocalTranslation()); + private void positionCamera(){ + this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); + this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f)); + } - rf.addListener(auxListener); - WaveFileWriter aux = null; + private void initAudio() { + org.lwjgl.input.Mouse.setGrabbed(false); + music = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", false); - try {aux = new WaveFileWriter(new File("/home/r/tmp/ear"+n+".wav"));} - catch (FileNotFoundException e) {e.printStackTrace();} + rootNode.attachChild(music); + audioRenderer.playSource(music); + music.setPositional(true); + music.setVolume(1f); + music.setReverbEnabled(false); + music.setDirectional(false); + music.setMaxDistance(200.0f); + music.setRefDistance(1f); + //music.setRolloffFactor(1f); + music.setLooping(false); + audioRenderer.pauseSource(music); + } - rf.registerSoundProcessor(auxListener, - new CompositeSoundProcessor(new Dancer(ear), aux)); - } - } + public class Dancer implements SoundProcessor { + Geometry entity; + float scale = 2; + public Dancer(Geometry entity){ + this.entity = entity; + } + /** + * this method is irrelevant since there is no state to cleanup. + */ + public void cleanup() {} - public void simpleInitApp() { - this.setTimer(new IsoTimer(60)); - initAudio(); - - createScene(); - prepareEar(ear1, 1); - prepareEar(ear2, 1); - prepareEar(ear3, 1); + /** + * Respond to sound! This is the brain of an AI entity that + * hears its surroundings and reacts to them. + */ + public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) { + audioSamples.clear(); + byte[] data = new byte[numSamples]; + float[] out = new float[numSamples]; + audioSamples.get(data); + FloatSampleTools.byte2floatInterleaved(data, 0, out, 0, + numSamples/format.getFrameSize(), format); - motionControl.play(); - } + float max = Float.NEGATIVE_INFINITY; + for (float f : out){if (f > max) max = f;} + audioSamples.clear(); - public void simpleUpdate(float tpf) { - if (music.getStatus() != AudioNode.Status.Playing){ - music.play(); + if (max > 0.1){entity.getMaterial().setColor("Color", ColorRGBA.Green);} + else {entity.getMaterial().setColor("Color", ColorRGBA.Gray);} + } } - Vector3f loc = cam.getLocation(); - Quaternion rot = cam.getRotation(); - listener.setLocation(loc); - listener.setRotation(rot); - music.setLocalTranslation(bell.getLocalTranslation()); - } + + private void prepareEar(Geometry ear, int n){ + if (this.audioRenderer instanceof MultiListener){ + MultiListener rf = (MultiListener)this.audioRenderer; + + Listener auxListener = new Listener(); + auxListener.setLocation(ear.getLocalTranslation()); + + rf.addListener(auxListener); + WaveFileWriter aux = null; + + try {aux = new WaveFileWriter(File.createTempFile("advanced-audio-" + n, ".wav"));} + catch (IOException e) {e.printStackTrace();} + + rf.registerSoundProcessor(auxListener, + new CompositeSoundProcessor(new Dancer(ear), aux)); + + } + } + + + public void simpleInitApp() { + this.setTimer(new IsoTimer(60)); + initAudio(); + + createScene(); + + prepareEar(ear1, 1); + prepareEar(ear2, 1); + prepareEar(ear3, 1); + + motionControl.play(); + + } + + public void simpleUpdate(float tpf) { + motionTimer.update(); + if (music.getStatus() != AudioNode.Status.Playing){ + music.play(); + } + Vector3f loc = cam.getLocation(); + Quaternion rot = cam.getRotation(); + listener.setLocation(loc); + listener.setRotation(rot); + music.setLocalTranslation(bell.getLocalTranslation()); + } }