Mercurial > jmeCapture
diff src/com/aurellem/capture/examples/AdvancedAudio.java @ 39:784a3f4e6202
updating capture-video
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 03 Nov 2011 16:00:46 -0700 |
parents | adeb88787645 |
children |
line wrap: on
line diff
1.1 --- a/src/com/aurellem/capture/examples/AdvancedAudio.java Mon Oct 31 07:43:44 2011 -0700 1.2 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java Thu Nov 03 16:00:46 2011 -0700 1.3 @@ -19,7 +19,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.audio.ListenerParam; 1.10 import com.jme3.cinematic.MotionPath; 1.11 @@ -34,7 +33,6 @@ 1.12 import com.jme3.math.Vector3f; 1.13 import com.jme3.scene.Geometry; 1.14 import com.jme3.scene.Node; 1.15 -import com.jme3.scene.Spatial; 1.16 import com.jme3.scene.shape.Box; 1.17 import com.jme3.scene.shape.Sphere; 1.18 import com.jme3.system.AppSettings; 1.19 @@ -69,16 +67,18 @@ 1.20 app.setSettings(settings); 1.21 app.setShowSettings(false); 1.22 app.setPauseOnLostFocus(false); 1.23 - org.lwjgl.input.Mouse.setGrabbed(false); 1.24 - //try {Capture.captureVideo(app, new File("/home/r/tmp/out.avi"));} 1.25 - //catch (IOException e) {e.printStackTrace();} 1.26 + 1.27 + try {Capture.captureVideo(app, new File("/home/r/tmp/out")); 1.28 + Capture.captureAudio(app, new File("/home/r/tmp/main.wav"));} 1.29 + catch (IOException e) {e.printStackTrace();} 1.30 app.start(); 1.31 + 1.32 } 1.33 1.34 private MotionTrack motionControl; 1.35 1.36 1.37 - private Spatial makeEar(Node root, Vector3f position){ 1.38 + private Geometry makeEar(Node root, Vector3f position){ 1.39 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 1.40 Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f)); 1.41 ear.setLocalTranslation(position); 1.42 @@ -90,10 +90,10 @@ 1.43 1.44 private Geometry bell; 1.45 1.46 - private Spatial ear1; 1.47 - //private Spatial ear2; 1.48 - //private Spatial ear3; 1.49 - //private Spatial ear4; 1.50 + private Geometry ear1; 1.51 + private Geometry ear2; 1.52 + private Geometry ear3; 1.53 + 1.54 1.55 1.56 private Vector3f[] path = new Vector3f[]{ 1.57 @@ -160,9 +160,9 @@ 1.58 rootNode.addLight(light); 1.59 1.60 ear1 = makeEar(rootNode, new Vector3f(0, 0 ,-20)); 1.61 - //ear2 = makeEar(rootNode, new Vector3f(0, 0 ,-20)); 1.62 - //ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0)); 1.63 - //ear4 = makeEar(rootNode, new Vector3f(-20, 0 ,0)); 1.64 + ear2 = makeEar(rootNode, new Vector3f(0, 0 ,20)); 1.65 + ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0)); 1.66 + 1.67 1.68 MotionPath track = new MotionPath(); 1.69 1.70 @@ -204,7 +204,7 @@ 1.71 1.72 1.73 private void initAudio() { 1.74 - 1.75 + org.lwjgl.input.Mouse.setGrabbed(false); 1.76 music = new AudioNode(assetManager, "Sound/Environment/sqr-1kHz.wav", false); 1.77 1.78 rootNode.attachChild(music); 1.79 @@ -234,14 +234,10 @@ 1.80 1.81 1.82 public class Dancer implements SoundProcessor { 1.83 - 1.84 - Spatial entity; 1.85 - 1.86 + Geometry entity; 1.87 float scale = 2; 1.88 - String debug; 1.89 - public Dancer(Spatial entity, String debug){ 1.90 + public Dancer(Geometry entity){ 1.91 this.entity = entity; 1.92 - this.debug = debug; 1.93 } 1.94 1.95 /** 1.96 @@ -265,10 +261,9 @@ 1.97 float max = Float.NEGATIVE_INFINITY; 1.98 for (float f : out){if (f > max) max = f;} 1.99 audioSamples.clear(); 1.100 - System.out.println(debug); 1.101 - System.out.println(max); 1.102 1.103 - 1.104 + if (max > 0.1){entity.getMaterial().setColor("Color", ColorRGBA.Green);} 1.105 + else {entity.getMaterial().setColor("Color", ColorRGBA.Gray);} 1.106 1.107 //entity.scale(this.scale); 1.108 //if (this.scale == 2f){this.scale = 0.5f;} 1.109 @@ -280,38 +275,35 @@ 1.110 1.111 1.112 1.113 + private void prepareEar(Geometry ear, int n){ 1.114 + if (this.audioRenderer instanceof MultiListener){ 1.115 + MultiListener rf = (MultiListener)this.audioRenderer; 1.116 + 1.117 + auxListener = new Listener(); 1.118 + auxListener.setLocation(ear.getLocalTranslation()); 1.119 + 1.120 + rf.addListener(auxListener); 1.121 + WaveFileWriter aux = null; 1.122 + 1.123 + try {aux = new WaveFileWriter(new File("/home/r/tmp/ear"+n+".wav"));} 1.124 + catch (FileNotFoundException e) {e.printStackTrace();} 1.125 + 1.126 + rf.registerSoundProcessor(auxListener, 1.127 + new CompositeSoundProcessor(new Dancer(ear), aux)); 1.128 + 1.129 + } 1.130 + } 1.131 + 1.132 1.133 public void simpleInitApp() { 1.134 this.setTimer(new IsoTimer(60)); 1.135 initAudio(); 1.136 initKeys(); 1.137 createScene(); 1.138 - listener.setLocation(ear1.getLocalTranslation()); 1.139 - listener.setRotation(new Quaternion().fromAngleAxis(0, Vector3f.UNIT_Y)); 1.140 - if (this.audioRenderer instanceof MultiListener){ 1.141 - MultiListener rf = (MultiListener)this.audioRenderer; 1.142 1.143 - 1.144 - 1.145 - auxListener = new Listener(listener); 1.146 - 1.147 - rf.addListener(auxListener); 1.148 - WaveFileWriter aux = null; 1.149 - WaveFileWriter main = null; 1.150 - 1.151 - 1.152 - try {aux = new WaveFileWriter(new File("/home/r/tmp/aux.wav"));} 1.153 - catch (FileNotFoundException e) {e.printStackTrace();} 1.154 - 1.155 - try {main = new WaveFileWriter(new File("/home/r/tmp/main.wav"));} 1.156 - catch (FileNotFoundException e) {e.printStackTrace();} 1.157 - 1.158 - rf.registerSoundProcessor(auxListener, 1.159 - new CompositeSoundProcessor(new Dancer(ear1, "aux"), aux)); 1.160 - 1.161 - rf.registerSoundProcessor( 1.162 - new CompositeSoundProcessor(new Dancer(ear1, "--------\nmain"), main)); 1.163 - } 1.164 + prepareEar(ear1, 1); 1.165 + prepareEar(ear2, 1); 1.166 + prepareEar(ear3, 1); 1.167 1.168 motionControl.play(); 1.169 } 1.170 @@ -350,15 +342,15 @@ 1.171 if (countdown == 0){ 1.172 music.play(); 1.173 } 1.174 - //Vector3f loc = cam.getLocation(); 1.175 - //Quaternion rot = cam.getRotation(); 1.176 - //listener.setLocation(loc); 1.177 - listener.setRotation(new Quaternion().fromAngleAxis(0, music.getLocalTranslation().subtract(listener.getLocation()))); 1.178 + Vector3f loc = cam.getLocation(); 1.179 + Quaternion rot = cam.getRotation(); 1.180 + listener.setLocation(loc); 1.181 + listener.setRotation(rot); 1.182 audioRenderer.updateListenerParam(listener, ListenerParam.Rotation); 1.183 1.184 - System.out.println(countdown); 1.185 + //System.out.println(countdown); 1.186 1.187 - if (countdown++ == 300) { this.requestClose(false);} 1.188 + //if (countdown++ == 300) { this.requestClose(false);} 1.189 1.190 //System.out.println("channel "+ music.getChannel()); 1.191 //listener.setLocation(cam.getLocation()); 1.192 @@ -378,8 +370,8 @@ 1.193 1.194 music.setLocalTranslation(bell.getLocalTranslation()); 1.195 1.196 - System.out.println("distance: " + 1.197 - music.getLocalTranslation().subtract(listener.getLocation()).length()); 1.198 + //System.out.println("distance: " + 1.199 + // music.getLocalTranslation().subtract(listener.getLocation()).length()); 1.200 1.201 //music.setVelocity(bellVelocity); 1.202