Mercurial > jmeCapture
changeset 41:58386a64d019
renamed stuff
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 03 Nov 2011 16:55:43 -0700 |
parents | 56dc950feaed |
children | b1bc965a38d2 |
files | src/com/aurellem/capture/examples/Advanced.java src/com/aurellem/capture/examples/AdvancedAudio.java src/com/aurellem/capture/examples/AdvancedVideo.java |
diffstat | 3 files changed, 277 insertions(+), 464 deletions(-) [+] |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/com/aurellem/capture/examples/Advanced.java Thu Nov 03 16:55:43 2011 -0700 1.3 @@ -0,0 +1,277 @@ 1.4 +package com.aurellem.capture.examples; 1.5 + 1.6 +import java.io.File; 1.7 +import java.io.FileNotFoundException; 1.8 +import java.io.IOException; 1.9 +import java.nio.ByteBuffer; 1.10 +import java.util.logging.Level; 1.11 +import java.util.logging.Logger; 1.12 + 1.13 +import javax.sound.sampled.AudioFormat; 1.14 + 1.15 +import org.tritonus.share.sampled.FloatSampleTools; 1.16 + 1.17 +import com.aurellem.capture.Capture; 1.18 +import com.aurellem.capture.IsoTimer; 1.19 +import com.aurellem.capture.audio.CompositeSoundProcessor; 1.20 +import com.aurellem.capture.audio.MultiListener; 1.21 +import com.aurellem.capture.audio.SoundProcessor; 1.22 +import com.aurellem.capture.audio.WaveFileWriter; 1.23 +import com.jme3.app.SimpleApplication; 1.24 +import com.jme3.audio.AudioNode; 1.25 +import com.jme3.audio.Listener; 1.26 +import com.jme3.cinematic.MotionPath; 1.27 +import com.jme3.cinematic.events.MotionTrack; 1.28 +import com.jme3.material.Material; 1.29 +import com.jme3.math.ColorRGBA; 1.30 +import com.jme3.math.FastMath; 1.31 +import com.jme3.math.Quaternion; 1.32 +import com.jme3.math.Vector3f; 1.33 +import com.jme3.scene.Geometry; 1.34 +import com.jme3.scene.Node; 1.35 +import com.jme3.scene.shape.Box; 1.36 +import com.jme3.scene.shape.Sphere; 1.37 +import com.jme3.system.AppSettings; 1.38 + 1.39 + 1.40 +/** 1.41 + * 1.42 + * Demonstrates advanced use of the audio capture and recording features. 1.43 + * Multiple perspectives of the same scene are simultaneously rendered to 1.44 + * different sound files. 1.45 + * 1.46 + * A key limitation of the way multiple listeners are implemented is that 1.47 + * only 3D positioning effects are realized for listeners other than the 1.48 + * main LWJGL listener. This means that audio effects such as environment 1.49 + * settings will *not* be heard on any auxiliary listeners, though sound 1.50 + * attenuation will work correctly. 1.51 + * 1.52 + * Multiple listeners as realized here might be used to make AI entities 1.53 + * that can each hear the world from their own perspective. 1.54 + * 1.55 + * @author Robert McIntyre 1.56 + * 1.57 + */ 1.58 + 1.59 +public class Advanced extends SimpleApplication { 1.60 + 1.61 + 1.62 + private Geometry bell; 1.63 + private Geometry ear1; 1.64 + private Geometry ear2; 1.65 + private Geometry ear3; 1.66 + private AudioNode music; 1.67 + private MotionTrack motionControl; 1.68 + 1.69 + public static void main(String[] args) { 1.70 + Logger.getLogger("com.jme3").setLevel(Level.OFF); 1.71 + Advanced app = new Advanced(); 1.72 + AppSettings settings = new AppSettings(true); 1.73 + settings.setAudioRenderer("Send"); 1.74 + app.setSettings(settings); 1.75 + app.setShowSettings(false); 1.76 + app.setPauseOnLostFocus(false); 1.77 + 1.78 + try { 1.79 + Capture.captureVideo(app, File.createTempFile("advanced",".avi")); 1.80 + Capture.captureAudio(app, File.createTempFile("advanced", ".wav")); 1.81 + } 1.82 + catch (IOException e) {e.printStackTrace();} 1.83 + app.start(); 1.84 + } 1.85 + 1.86 + private Geometry makeEar(Node root, Vector3f position){ 1.87 + Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 1.88 + Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f)); 1.89 + ear.setLocalTranslation(position); 1.90 + mat.setColor("Color", ColorRGBA.Green); 1.91 + ear.setMaterial(mat); 1.92 + root.attachChild(ear); 1.93 + return ear; 1.94 + } 1.95 + 1.96 + private Vector3f[] path = new Vector3f[]{ 1.97 + // loop 1 1.98 + new Vector3f(0, 0, 0), 1.99 + new Vector3f(0, 0, -10), 1.100 + new Vector3f(-2, 0, -14), 1.101 + new Vector3f(-6, 0, -20), 1.102 + new Vector3f(0, 0, -26), 1.103 + new Vector3f(6, 0, -20), 1.104 + new Vector3f(0, 0, -14), 1.105 + new Vector3f(-6, 0, -20), 1.106 + new Vector3f(0, 0, -26), 1.107 + new Vector3f(6, 0, -20), 1.108 + // loop 2 1.109 + new Vector3f(5, 0, -5), 1.110 + new Vector3f(7, 0, 1.5f), 1.111 + new Vector3f(14, 0, 2), 1.112 + new Vector3f(20, 0, 6), 1.113 + new Vector3f(26, 0, 0), 1.114 + new Vector3f(20, 0, -6), 1.115 + new Vector3f(14, 0, 0), 1.116 + new Vector3f(20, 0, 6), 1.117 + new Vector3f(26, 0, 0), 1.118 + new Vector3f(20, 0, -6), 1.119 + new Vector3f(14, 0, 0), 1.120 + // loop 3 1.121 + new Vector3f(8, 0, 7.5f), 1.122 + new Vector3f(7, 0, 10.5f), 1.123 + new Vector3f(6, 0, 20), 1.124 + new Vector3f(0, 0, 26), 1.125 + new Vector3f(-6, 0, 20), 1.126 + new Vector3f(0, 0, 14), 1.127 + new Vector3f(6, 0, 20), 1.128 + new Vector3f(0, 0, 26), 1.129 + new Vector3f(-6, 0, 20), 1.130 + new Vector3f(0, 0, 14), 1.131 + // begin ellipse 1.132 + new Vector3f(16, 5, 20), 1.133 + new Vector3f(0, 0, 26), 1.134 + new Vector3f(-16, -10, 20), 1.135 + new Vector3f(0, 0, 14), 1.136 + new Vector3f(16, 20, 20), 1.137 + new Vector3f(0, 0, 26), 1.138 + new Vector3f(-10, -25, 10), 1.139 + new Vector3f(-10, 0, 0), 1.140 + // come at me! 1.141 + new Vector3f(-28.00242f, 48.005623f, -34.648228f), 1.142 + new Vector3f(0, 0 , -20), 1.143 + }; 1.144 + 1.145 + private void createScene() { 1.146 + Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 1.147 + bell = new Geometry( "sound-emitter" , new Sphere(15,15,1)); 1.148 + mat.setColor("Color", ColorRGBA.Blue); 1.149 + bell.setMaterial(mat); 1.150 + rootNode.attachChild(bell); 1.151 + 1.152 + ear1 = makeEar(rootNode, new Vector3f(0, 0 ,-20)); 1.153 + ear2 = makeEar(rootNode, new Vector3f(0, 0 ,20)); 1.154 + ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0)); 1.155 + 1.156 + MotionPath track = new MotionPath(); 1.157 + 1.158 + for (Vector3f v : path){ 1.159 + track.addWayPoint(v); 1.160 + } 1.161 + track.setCurveTension(0.80f); 1.162 + 1.163 + motionControl = new MotionTrack(bell,track); 1.164 + motionControl.setTimer(new IsoTimer(60)); 1.165 + motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation); 1.166 + motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y)); 1.167 + motionControl.setInitialDuration(20f); 1.168 + motionControl.setSpeed(1f); 1.169 + 1.170 + track.enableDebugShape(assetManager, rootNode); 1.171 + positionCamera(); 1.172 + } 1.173 + 1.174 + 1.175 + private void positionCamera(){ 1.176 + this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); 1.177 + this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f)); 1.178 + } 1.179 + 1.180 + private void initAudio() { 1.181 + org.lwjgl.input.Mouse.setGrabbed(false); 1.182 + music = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", false); 1.183 + 1.184 + rootNode.attachChild(music); 1.185 + audioRenderer.playSource(music); 1.186 + music.setPositional(true); 1.187 + music.setVolume(1f); 1.188 + music.setReverbEnabled(false); 1.189 + music.setDirectional(false); 1.190 + music.setMaxDistance(200.0f); 1.191 + music.setRefDistance(1f); 1.192 + music.setRolloffFactor(1f); 1.193 + music.setLooping(false); 1.194 + audioRenderer.pauseSource(music); 1.195 + } 1.196 + 1.197 + 1.198 + 1.199 + 1.200 + 1.201 + 1.202 + public class Dancer implements SoundProcessor { 1.203 + Geometry entity; 1.204 + float scale = 2; 1.205 + public Dancer(Geometry entity){ 1.206 + this.entity = entity; 1.207 + } 1.208 + 1.209 + /** 1.210 + * this method is irrelevant since there is no state to cleanup. 1.211 + */ 1.212 + public void cleanup() {} 1.213 + 1.214 + 1.215 + /** 1.216 + * Respond to sound! This is the brain of an AI entity that 1.217 + * hears it's surroundings and reacts to them. 1.218 + */ 1.219 + public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) { 1.220 + audioSamples.clear(); 1.221 + byte[] data = new byte[numSamples]; 1.222 + float[] out = new float[numSamples]; 1.223 + audioSamples.get(data); 1.224 + FloatSampleTools.byte2floatInterleaved(data, 0, out, 0, 1.225 + numSamples/format.getFrameSize(), format); 1.226 + 1.227 + float max = Float.NEGATIVE_INFINITY; 1.228 + for (float f : out){if (f > max) max = f;} 1.229 + audioSamples.clear(); 1.230 + 1.231 + if (max > 0.1){entity.getMaterial().setColor("Color", ColorRGBA.Green);} 1.232 + else {entity.getMaterial().setColor("Color", ColorRGBA.Gray);} 1.233 + } 1.234 + } 1.235 + 1.236 + private void prepareEar(Geometry ear, int n){ 1.237 + if (this.audioRenderer instanceof MultiListener){ 1.238 + MultiListener rf = (MultiListener)this.audioRenderer; 1.239 + 1.240 + Listener auxListener = new Listener(); 1.241 + auxListener.setLocation(ear.getLocalTranslation()); 1.242 + 1.243 + rf.addListener(auxListener); 1.244 + WaveFileWriter aux = null; 1.245 + 1.246 + try {aux = new WaveFileWriter(new File("/home/r/tmp/ear"+n+".wav"));} 1.247 + catch (FileNotFoundException e) {e.printStackTrace();} 1.248 + 1.249 + rf.registerSoundProcessor(auxListener, 1.250 + new CompositeSoundProcessor(new Dancer(ear), aux)); 1.251 + 1.252 + } 1.253 + } 1.254 + 1.255 + 1.256 + public void simpleInitApp() { 1.257 + this.setTimer(new IsoTimer(60)); 1.258 + initAudio(); 1.259 + 1.260 + createScene(); 1.261 + 1.262 + prepareEar(ear1, 1); 1.263 + prepareEar(ear2, 1); 1.264 + prepareEar(ear3, 1); 1.265 + 1.266 + motionControl.play(); 1.267 + } 1.268 + 1.269 + public void simpleUpdate(float tpf) { 1.270 + if (music.getStatus() != AudioNode.Status.Playing){ 1.271 + music.play(); 1.272 + } 1.273 + Vector3f loc = cam.getLocation(); 1.274 + Quaternion rot = cam.getRotation(); 1.275 + listener.setLocation(loc); 1.276 + listener.setRotation(rot); 1.277 + music.setLocalTranslation(bell.getLocalTranslation()); 1.278 + } 1.279 + 1.280 +}
2.1 --- a/src/com/aurellem/capture/examples/AdvancedAudio.java Thu Nov 03 16:39:32 2011 -0700 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,389 +0,0 @@ 2.4 -package com.aurellem.capture.examples; 2.5 - 2.6 -import java.io.File; 2.7 -import java.io.FileNotFoundException; 2.8 -import java.io.IOException; 2.9 -import java.nio.ByteBuffer; 2.10 -import java.util.logging.Level; 2.11 -import java.util.logging.Logger; 2.12 - 2.13 -import javax.sound.sampled.AudioFormat; 2.14 - 2.15 -import org.tritonus.share.sampled.FloatSampleTools; 2.16 - 2.17 -import com.aurellem.capture.Capture; 2.18 -import com.aurellem.capture.IsoTimer; 2.19 -import com.aurellem.capture.audio.CompositeSoundProcessor; 2.20 -import com.aurellem.capture.audio.MultiListener; 2.21 -import com.aurellem.capture.audio.SoundProcessor; 2.22 -import com.aurellem.capture.audio.WaveFileWriter; 2.23 -import com.jme3.app.SimpleApplication; 2.24 -import com.jme3.audio.AudioNode; 2.25 -import com.jme3.audio.Listener; 2.26 -import com.jme3.audio.ListenerParam; 2.27 -import com.jme3.cinematic.MotionPath; 2.28 -import com.jme3.cinematic.events.MotionTrack; 2.29 -import com.jme3.input.controls.ActionListener; 2.30 -import com.jme3.input.controls.MouseButtonTrigger; 2.31 -import com.jme3.light.DirectionalLight; 2.32 -import com.jme3.material.Material; 2.33 -import com.jme3.math.ColorRGBA; 2.34 -import com.jme3.math.FastMath; 2.35 -import com.jme3.math.Quaternion; 2.36 -import com.jme3.math.Vector3f; 2.37 -import com.jme3.scene.Geometry; 2.38 -import com.jme3.scene.Node; 2.39 -import com.jme3.scene.shape.Box; 2.40 -import com.jme3.scene.shape.Sphere; 2.41 -import com.jme3.system.AppSettings; 2.42 - 2.43 - 2.44 -/** 2.45 - * 2.46 - * Demonstrates advanced use of the audio capture and recording features. 2.47 - * Multiple perspectives of the same scene are simultaneously rendered to 2.48 - * different sound files. 2.49 - * 2.50 - * A key limitation of the way multiple listeners are implemented is that 2.51 - * only 3D positioning effects are realized for listeners other than the 2.52 - * main LWJGL listener. This means that audio effects such as environment 2.53 - * settings will *not* be heard on any auxiliary listeners, though sound 2.54 - * attenuation will work correctly. 2.55 - * 2.56 - * Multiple listeners as realized here might be used to make AI entities 2.57 - * that can each hear the world from their own perspective. 2.58 - * 2.59 - * @author Robert McIntyre 2.60 - * 2.61 - */ 2.62 - 2.63 -public class AdvancedAudio extends SimpleApplication { 2.64 - 2.65 - public static void main(String[] args) { 2.66 - Logger.getLogger("com.jme3").setLevel(Level.OFF); 2.67 - AdvancedAudio app = new AdvancedAudio(); 2.68 - AppSettings settings = new AppSettings(true); 2.69 - settings.setAudioRenderer("Send"); 2.70 - app.setSettings(settings); 2.71 - app.setShowSettings(false); 2.72 - app.setPauseOnLostFocus(false); 2.73 - 2.74 - try {Capture.captureVideo(app, new File("/home/r/tmp/out")); 2.75 - Capture.captureAudio(app, new File("/home/r/tmp/main.wav"));} 2.76 - catch (IOException e) {e.printStackTrace();} 2.77 - app.start(); 2.78 - 2.79 - } 2.80 - 2.81 - private MotionTrack motionControl; 2.82 - 2.83 - 2.84 - private Geometry makeEar(Node root, Vector3f position){ 2.85 - Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 2.86 - Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f)); 2.87 - ear.setLocalTranslation(position); 2.88 - mat.setColor("Color", ColorRGBA.Green); 2.89 - ear.setMaterial(mat); 2.90 - root.attachChild(ear); 2.91 - return ear; 2.92 - } 2.93 - 2.94 - private Geometry bell; 2.95 - 2.96 - private Geometry ear1; 2.97 - private Geometry ear2; 2.98 - private Geometry ear3; 2.99 - 2.100 - 2.101 - 2.102 - private Vector3f[] path = new Vector3f[]{ 2.103 - // loop 1 2.104 - new Vector3f(0, 0, 0), 2.105 - new Vector3f(0, 0, -10), 2.106 - new Vector3f(-2, 0, -14), 2.107 - new Vector3f(-6, 0, -20), 2.108 - new Vector3f(0, 0, -26), 2.109 - new Vector3f(6, 0, -20), 2.110 - new Vector3f(0, 0, -14), 2.111 - new Vector3f(-6, 0, -20), 2.112 - new Vector3f(0, 0, -26), 2.113 - new Vector3f(6, 0, -20), 2.114 - // loop 2 2.115 - new Vector3f(5, 0, -5), 2.116 - new Vector3f(7, 0, 1.5f), 2.117 - new Vector3f(14, 0, 2), 2.118 - new Vector3f(20, 0, 6), 2.119 - new Vector3f(26, 0, 0), 2.120 - new Vector3f(20, 0, -6), 2.121 - new Vector3f(14, 0, 0), 2.122 - new Vector3f(20, 0, 6), 2.123 - new Vector3f(26, 0, 0), 2.124 - new Vector3f(20, 0, -6), 2.125 - new Vector3f(14, 0, 0), 2.126 - // loop 3 2.127 - new Vector3f(8, 0, 7.5f), 2.128 - new Vector3f(7, 0, 10.5f), 2.129 - new Vector3f(6, 0, 20), 2.130 - new Vector3f(0, 0, 26), 2.131 - new Vector3f(-6, 0, 20), 2.132 - new Vector3f(0, 0, 14), 2.133 - new Vector3f(6, 0, 20), 2.134 - new Vector3f(0, 0, 26), 2.135 - new Vector3f(-6, 0, 20), 2.136 - new Vector3f(0, 0, 14), 2.137 - // begin ellipse 2.138 - new Vector3f(16, 5, 20), 2.139 - new Vector3f(0, 0, 26), 2.140 - new Vector3f(-16, -10, 20), 2.141 - new Vector3f(0, 0, 14), 2.142 - new Vector3f(16, 20, 20), 2.143 - new Vector3f(0, 0, 26), 2.144 - new Vector3f(-10, -25, 10), 2.145 - new Vector3f(-10, 0, 0), 2.146 - // come at me bro! 2.147 - new Vector3f(-28.00242f, 48.005623f, -34.648228f), 2.148 - new Vector3f(0, 0 , -20), 2.149 - }; 2.150 - 2.151 - 2.152 - 2.153 - private void createScene() { 2.154 - Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 2.155 - bell = new Geometry( "sound-emitter" , new Sphere(15,15,1)); 2.156 - mat.setColor("Color", ColorRGBA.Blue); 2.157 - bell.setMaterial(mat); 2.158 - rootNode.attachChild(bell); 2.159 - 2.160 - DirectionalLight light = new DirectionalLight(); 2.161 - light.setDirection(new Vector3f(0, -1, 0).normalizeLocal()); 2.162 - light.setColor(ColorRGBA.White.mult(1.5f)); 2.163 - rootNode.addLight(light); 2.164 - 2.165 - ear1 = makeEar(rootNode, new Vector3f(0, 0 ,-20)); 2.166 - ear2 = makeEar(rootNode, new Vector3f(0, 0 ,20)); 2.167 - ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0)); 2.168 - 2.169 - 2.170 - MotionPath track = new MotionPath(); 2.171 - 2.172 - for (Vector3f v : path){ 2.173 - track.addWayPoint(v); 2.174 - } 2.175 - 2.176 - 2.177 - track.setCurveTension(0.80f); 2.178 - 2.179 - 2.180 - motionControl = new MotionTrack(bell,track); 2.181 - motionControl.setTimer(new IsoTimer(60)); 2.182 - motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation); 2.183 - motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y)); 2.184 - motionControl.setInitialDuration(20f); 2.185 - motionControl.setSpeed(1f); 2.186 - 2.187 - 2.188 - track.enableDebugShape(assetManager, rootNode); 2.189 - 2.190 - 2.191 - positionCamera(); 2.192 - 2.193 - 2.194 - } 2.195 - 2.196 - 2.197 - private void positionCamera(){ 2.198 - this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); 2.199 - // cam.setLocation(new Vector3f(0,0,-20)); 2.200 - this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f)); 2.201 - } 2.202 - 2.203 - private AudioNode music; 2.204 - 2.205 - 2.206 - 2.207 - 2.208 - 2.209 - private void initAudio() { 2.210 - org.lwjgl.input.Mouse.setGrabbed(false); 2.211 - music = new AudioNode(assetManager, "Sound/Environment/sqr-1kHz.wav", false); 2.212 - 2.213 - rootNode.attachChild(music); 2.214 - audioRenderer.playSource(music); 2.215 - music.setPositional(true); 2.216 - music.setVolume(1f); 2.217 - music.setReverbEnabled(false); 2.218 - music.setDirectional(false); 2.219 - music.setMaxDistance(200.0f); 2.220 - music.setRefDistance(1f); 2.221 - music.setRolloffFactor(1f); 2.222 - music.setLooping(false); 2.223 - audioRenderer.pauseSource(music); 2.224 - 2.225 - } 2.226 - 2.227 - 2.228 - 2.229 - 2.230 - private Listener auxListener; 2.231 - //public File data1 = new File("/home/r/tmp/data1.wav"); 2.232 - //public File data2 = new File("/home/r/tmp/data2.wav"); 2.233 - //public File data3 = new File("/home/r/tmp/data3.wav"); 2.234 - //public File data4 = new File("/home/r/tmp/data4.wav"); 2.235 - //public File data5 = new File("/home/r/tmp/data5.wav"); 2.236 - //public File data6 = new File("/home/r/tmp/data6.wav"); 2.237 - 2.238 - 2.239 - public class Dancer implements SoundProcessor { 2.240 - Geometry entity; 2.241 - float scale = 2; 2.242 - public Dancer(Geometry entity){ 2.243 - this.entity = entity; 2.244 - } 2.245 - 2.246 - /** 2.247 - * this method is irrelevant since there is no state to cleanup. 2.248 - */ 2.249 - public void cleanup() {} 2.250 - 2.251 - 2.252 - /** 2.253 - * Dance to the beat! This is the brain of an AI entity that 2.254 - * hears it's surroundings and reacts to them. 2.255 - */ 2.256 - public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) { 2.257 - audioSamples.clear(); 2.258 - byte[] data = new byte[numSamples]; 2.259 - float[] out = new float[numSamples]; 2.260 - audioSamples.get(data); 2.261 - FloatSampleTools.byte2floatInterleaved(data, 0, out, 0, 2.262 - numSamples/format.getFrameSize(), format); 2.263 - 2.264 - float max = Float.NEGATIVE_INFINITY; 2.265 - for (float f : out){if (f > max) max = f;} 2.266 - audioSamples.clear(); 2.267 - 2.268 - if (max > 0.1){entity.getMaterial().setColor("Color", ColorRGBA.Green);} 2.269 - else {entity.getMaterial().setColor("Color", ColorRGBA.Gray);} 2.270 - 2.271 - //entity.scale(this.scale); 2.272 - //if (this.scale == 2f){this.scale = 0.5f;} 2.273 - //else {this.scale = 2;} 2.274 - } 2.275 - 2.276 - 2.277 - } 2.278 - 2.279 - 2.280 - 2.281 - private void prepareEar(Geometry ear, int n){ 2.282 - if (this.audioRenderer instanceof MultiListener){ 2.283 - MultiListener rf = (MultiListener)this.audioRenderer; 2.284 - 2.285 - auxListener = new Listener(); 2.286 - auxListener.setLocation(ear.getLocalTranslation()); 2.287 - 2.288 - rf.addListener(auxListener); 2.289 - WaveFileWriter aux = null; 2.290 - 2.291 - try {aux = new WaveFileWriter(new File("/home/r/tmp/ear"+n+".wav"));} 2.292 - catch (FileNotFoundException e) {e.printStackTrace();} 2.293 - 2.294 - rf.registerSoundProcessor(auxListener, 2.295 - new CompositeSoundProcessor(new Dancer(ear), aux)); 2.296 - 2.297 - } 2.298 - } 2.299 - 2.300 - 2.301 - public void simpleInitApp() { 2.302 - this.setTimer(new IsoTimer(60)); 2.303 - initAudio(); 2.304 - initKeys(); 2.305 - createScene(); 2.306 - 2.307 - prepareEar(ear1, 1); 2.308 - prepareEar(ear2, 1); 2.309 - prepareEar(ear3, 1); 2.310 - 2.311 - motionControl.play(); 2.312 - } 2.313 - 2.314 - 2.315 - 2.316 - 2.317 - 2.318 - private void initKeys() { 2.319 - inputManager.addMapping("Shoot", new MouseButtonTrigger(0)); 2.320 - inputManager.addListener(actionListener, "Shoot"); 2.321 - } 2.322 - 2.323 - /** Defining the "Shoot" action: Play a gun sound. */ 2.324 - private ActionListener actionListener = new ActionListener() { 2.325 - @Override 2.326 - public void onAction(String name, boolean keyPressed, float tpf) { 2.327 - if (name.equals("Shoot") && !keyPressed) { 2.328 - 2.329 - System.out.println(bell.getLocalTranslation().subtract(listener.getLocation()).length()); 2.330 - //bell.getMaterial().setColor("Color", ColorRGBA.randomColor()); 2.331 - //audioRenderer.playSource(music); 2.332 - System.out.println(music.getRefDistance()); 2.333 - 2.334 - } 2.335 - } 2.336 - }; 2.337 - 2.338 - /** Move the listener with the camera - for 3D audio. */ 2.339 - 2.340 - 2.341 - //private Vector3f prevBellPos = Vector3f.ZERO; 2.342 - private int countdown = 0; 2.343 - 2.344 - public void simpleUpdate(float tpf) { 2.345 - if (countdown == 0){ 2.346 - music.play(); 2.347 - } 2.348 - Vector3f loc = cam.getLocation(); 2.349 - Quaternion rot = cam.getRotation(); 2.350 - listener.setLocation(loc); 2.351 - listener.setRotation(rot); 2.352 - audioRenderer.updateListenerParam(listener, ListenerParam.Rotation); 2.353 - 2.354 - //System.out.println(countdown); 2.355 - 2.356 - //if (countdown++ == 300) { this.requestClose(false);} 2.357 - 2.358 - //System.out.println("channel "+ music.getChannel()); 2.359 - //listener.setLocation(cam.getLocation()); 2.360 - //listener.setRotation(cam.getRotation()); 2.361 - //auxListener.setLocation(loc); 2.362 - //auxListener.setRotation(rot); 2.363 - //if (music.getStatus() != AudioNode.Status.Playing){ 2.364 - //audioRenderer.playSource(music); 2.365 - //music.play(); 2.366 - // bell.getMaterial().setColor("Color", ColorRGBA.randomColor()); 2.367 - //System.out.println("I'm playing! <3"); 2.368 - //} 2.369 - //audioRenderer.updateSourceParam(music, AudioParam.Direction); 2.370 - 2.371 - //Vector3f bellVelocity = bell.getLocalTranslation().subtract(prevBellPos).mult(1.0f/tpf); 2.372 - //prevBellPos = bell.getLocalTranslation(); 2.373 - 2.374 - music.setLocalTranslation(bell.getLocalTranslation()); 2.375 - 2.376 - //System.out.println("distance: " + 2.377 - // music.getLocalTranslation().subtract(listener.getLocation()).length()); 2.378 - 2.379 - //music.setVelocity(bellVelocity); 2.380 - 2.381 - //audioRenderer.updateSourceParam(music, AudioParam.Position); 2.382 - //audioRenderer.updateSourceParam(music, AudioParam.Velocity); 2.383 - 2.384 - 2.385 - //System.out.println("main:" + listener.getVolume()); 2.386 - //System.out.println("aux:" + auxListener.getVolume()); 2.387 - //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_MIN_GAIN, 0f); 2.388 - //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_ROLLOFF_FACTOR, 5f); 2.389 - 2.390 - } 2.391 - 2.392 -}
3.1 --- a/src/com/aurellem/capture/examples/AdvancedVideo.java Thu Nov 03 16:39:32 2011 -0700 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,75 +0,0 @@ 3.4 -package com.aurellem.capture.examples; 3.5 - 3.6 -import java.io.File; 3.7 -import java.io.IOException; 3.8 - 3.9 -import com.aurellem.capture.Capture; 3.10 -import com.aurellem.capture.IsoTimer; 3.11 -import com.aurellem.capture.video.AbstractVideoRecorder; 3.12 -import com.jme3.app.SimpleApplication; 3.13 -import com.jme3.material.Material; 3.14 -import com.jme3.math.ColorRGBA; 3.15 -import com.jme3.math.Vector3f; 3.16 -import com.jme3.scene.Geometry; 3.17 -import com.jme3.scene.shape.Box; 3.18 - 3.19 -/** Recording Video from an application suitable for upload to youtube.*/ 3.20 -public class AdvancedVideo extends SimpleApplication { 3.21 - 3.22 - /*File staticVideo = 3.23 - new File("/home/r/bullshit.avi"); 3.24 - */ 3.25 - File movingVideo = 3.26 - new File("/home/r/tmp/bullshit2.flv"); 3.27 - 3.28 - AbstractVideoRecorder movingRecorder ; 3.29 - 3.30 - public static void main(String[] args){ 3.31 - AdvancedVideo app = new AdvancedVideo(); 3.32 - app.start(); 3.33 - } 3.34 - 3.35 - public void initVideo(){ 3.36 - this.setTimer(new IsoTimer(60)); 3.37 - /*try{ 3.38 - // set the timer to 30fps lock-step 3.39 - this.setTimer(new IsoTimer(30)); 3.40 - 3.41 - //ViewPort compositeViewPort = renderManager.createFinalView("composite", cam); 3.42 - //compositeViewPort.attachScene(this.rootNode); 3.43 - //compositeViewPort.attachScene(this.guiNode); 3.44 - this.viewPort.setClearFlags(true, true, true); 3.45 - this.viewPort.setBackgroundColor(ColorRGBA.Black); 3.46 - movingRecorder = new AVIVideoRecorder(movingVideo); 3.47 - this.stateManager.attach(movingRecorder); 3.48 - this.viewPort.addFinalProcessor(movingRecorder); 3.49 - this.viewPort.attachScene(this.guiNode); 3.50 - 3.51 - }catch (IOException e) { 3.52 - e.printStackTrace();} 3.53 - */ 3.54 - try {Capture.captureVideo(this, movingVideo);} 3.55 - catch (IOException e) {e.printStackTrace();} 3.56 - 3.57 - } 3.58 - protected Geometry player; 3.59 - 3.60 - public void simpleInitApp() { 3.61 - initVideo(); // begin recording! 3.62 - /** this blue box is our player character */ 3.63 - Box b = new Box(Vector3f.ZERO, 1, 1, 1); 3.64 - player = new Geometry("blue cube", b); 3.65 - Material mat = new Material(assetManager, 3.66 - "Common/MatDefs/Misc/Unshaded.j3md"); 3.67 - mat.setColor("Color", ColorRGBA.Blue); 3.68 - player.setMaterial(mat); 3.69 - rootNode.attachChild(player); 3.70 - } 3.71 - 3.72 - /* Use the main event loop to trigger repeating actions. */ 3.73 - public void simpleUpdate(float tpf) { 3.74 - // make the player rotate: 3.75 - player.rotate(0, 2*tpf, 0); 3.76 - } 3.77 - 3.78 -} 3.79 \ No newline at end of file