Mercurial > jmeCapture
comparison 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 |
comparison
equal
deleted
inserted
replaced
38:adeb88787645 | 39:784a3f4e6202 |
---|---|
17 import com.aurellem.capture.audio.MultiListener; | 17 import com.aurellem.capture.audio.MultiListener; |
18 import com.aurellem.capture.audio.SoundProcessor; | 18 import com.aurellem.capture.audio.SoundProcessor; |
19 import com.aurellem.capture.audio.WaveFileWriter; | 19 import com.aurellem.capture.audio.WaveFileWriter; |
20 import com.jme3.app.SimpleApplication; | 20 import com.jme3.app.SimpleApplication; |
21 import com.jme3.audio.AudioNode; | 21 import com.jme3.audio.AudioNode; |
22 import com.jme3.audio.AudioParam; | |
23 import com.jme3.audio.Listener; | 22 import com.jme3.audio.Listener; |
24 import com.jme3.audio.ListenerParam; | 23 import com.jme3.audio.ListenerParam; |
25 import com.jme3.cinematic.MotionPath; | 24 import com.jme3.cinematic.MotionPath; |
26 import com.jme3.cinematic.events.MotionTrack; | 25 import com.jme3.cinematic.events.MotionTrack; |
27 import com.jme3.input.controls.ActionListener; | 26 import com.jme3.input.controls.ActionListener; |
32 import com.jme3.math.FastMath; | 31 import com.jme3.math.FastMath; |
33 import com.jme3.math.Quaternion; | 32 import com.jme3.math.Quaternion; |
34 import com.jme3.math.Vector3f; | 33 import com.jme3.math.Vector3f; |
35 import com.jme3.scene.Geometry; | 34 import com.jme3.scene.Geometry; |
36 import com.jme3.scene.Node; | 35 import com.jme3.scene.Node; |
37 import com.jme3.scene.Spatial; | |
38 import com.jme3.scene.shape.Box; | 36 import com.jme3.scene.shape.Box; |
39 import com.jme3.scene.shape.Sphere; | 37 import com.jme3.scene.shape.Sphere; |
40 import com.jme3.system.AppSettings; | 38 import com.jme3.system.AppSettings; |
41 | 39 |
42 | 40 |
67 AppSettings settings = new AppSettings(true); | 65 AppSettings settings = new AppSettings(true); |
68 settings.setAudioRenderer("Send"); | 66 settings.setAudioRenderer("Send"); |
69 app.setSettings(settings); | 67 app.setSettings(settings); |
70 app.setShowSettings(false); | 68 app.setShowSettings(false); |
71 app.setPauseOnLostFocus(false); | 69 app.setPauseOnLostFocus(false); |
72 org.lwjgl.input.Mouse.setGrabbed(false); | 70 |
73 //try {Capture.captureVideo(app, new File("/home/r/tmp/out.avi"));} | 71 try {Capture.captureVideo(app, new File("/home/r/tmp/out")); |
74 //catch (IOException e) {e.printStackTrace();} | 72 Capture.captureAudio(app, new File("/home/r/tmp/main.wav"));} |
73 catch (IOException e) {e.printStackTrace();} | |
75 app.start(); | 74 app.start(); |
75 | |
76 } | 76 } |
77 | 77 |
78 private MotionTrack motionControl; | 78 private MotionTrack motionControl; |
79 | 79 |
80 | 80 |
81 private Spatial makeEar(Node root, Vector3f position){ | 81 private Geometry makeEar(Node root, Vector3f position){ |
82 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); | 82 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); |
83 Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f)); | 83 Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f)); |
84 ear.setLocalTranslation(position); | 84 ear.setLocalTranslation(position); |
85 mat.setColor("Color", ColorRGBA.Green); | 85 mat.setColor("Color", ColorRGBA.Green); |
86 ear.setMaterial(mat); | 86 ear.setMaterial(mat); |
88 return ear; | 88 return ear; |
89 } | 89 } |
90 | 90 |
91 private Geometry bell; | 91 private Geometry bell; |
92 | 92 |
93 private Spatial ear1; | 93 private Geometry ear1; |
94 //private Spatial ear2; | 94 private Geometry ear2; |
95 //private Spatial ear3; | 95 private Geometry ear3; |
96 //private Spatial ear4; | 96 |
97 | 97 |
98 | 98 |
99 private Vector3f[] path = new Vector3f[]{ | 99 private Vector3f[] path = new Vector3f[]{ |
100 // loop 1 | 100 // loop 1 |
101 new Vector3f(0, 0, 0), | 101 new Vector3f(0, 0, 0), |
158 light.setDirection(new Vector3f(0, -1, 0).normalizeLocal()); | 158 light.setDirection(new Vector3f(0, -1, 0).normalizeLocal()); |
159 light.setColor(ColorRGBA.White.mult(1.5f)); | 159 light.setColor(ColorRGBA.White.mult(1.5f)); |
160 rootNode.addLight(light); | 160 rootNode.addLight(light); |
161 | 161 |
162 ear1 = makeEar(rootNode, new Vector3f(0, 0 ,-20)); | 162 ear1 = makeEar(rootNode, new Vector3f(0, 0 ,-20)); |
163 //ear2 = makeEar(rootNode, new Vector3f(0, 0 ,-20)); | 163 ear2 = makeEar(rootNode, new Vector3f(0, 0 ,20)); |
164 //ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0)); | 164 ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0)); |
165 //ear4 = makeEar(rootNode, new Vector3f(-20, 0 ,0)); | 165 |
166 | 166 |
167 MotionPath track = new MotionPath(); | 167 MotionPath track = new MotionPath(); |
168 | 168 |
169 for (Vector3f v : path){ | 169 for (Vector3f v : path){ |
170 track.addWayPoint(v); | 170 track.addWayPoint(v); |
202 | 202 |
203 | 203 |
204 | 204 |
205 | 205 |
206 private void initAudio() { | 206 private void initAudio() { |
207 | 207 org.lwjgl.input.Mouse.setGrabbed(false); |
208 music = new AudioNode(assetManager, "Sound/Environment/sqr-1kHz.wav", false); | 208 music = new AudioNode(assetManager, "Sound/Environment/sqr-1kHz.wav", false); |
209 | 209 |
210 rootNode.attachChild(music); | 210 rootNode.attachChild(music); |
211 audioRenderer.playSource(music); | 211 audioRenderer.playSource(music); |
212 music.setPositional(true); | 212 music.setPositional(true); |
232 //public File data5 = new File("/home/r/tmp/data5.wav"); | 232 //public File data5 = new File("/home/r/tmp/data5.wav"); |
233 //public File data6 = new File("/home/r/tmp/data6.wav"); | 233 //public File data6 = new File("/home/r/tmp/data6.wav"); |
234 | 234 |
235 | 235 |
236 public class Dancer implements SoundProcessor { | 236 public class Dancer implements SoundProcessor { |
237 | 237 Geometry entity; |
238 Spatial entity; | |
239 | |
240 float scale = 2; | 238 float scale = 2; |
241 String debug; | 239 public Dancer(Geometry entity){ |
242 public Dancer(Spatial entity, String debug){ | |
243 this.entity = entity; | 240 this.entity = entity; |
244 this.debug = debug; | |
245 } | 241 } |
246 | 242 |
247 /** | 243 /** |
248 * this method is irrelevant since there is no state to cleanup. | 244 * this method is irrelevant since there is no state to cleanup. |
249 */ | 245 */ |
263 numSamples/format.getFrameSize(), format); | 259 numSamples/format.getFrameSize(), format); |
264 | 260 |
265 float max = Float.NEGATIVE_INFINITY; | 261 float max = Float.NEGATIVE_INFINITY; |
266 for (float f : out){if (f > max) max = f;} | 262 for (float f : out){if (f > max) max = f;} |
267 audioSamples.clear(); | 263 audioSamples.clear(); |
268 System.out.println(debug); | |
269 System.out.println(max); | |
270 | 264 |
271 | 265 if (max > 0.1){entity.getMaterial().setColor("Color", ColorRGBA.Green);} |
266 else {entity.getMaterial().setColor("Color", ColorRGBA.Gray);} | |
272 | 267 |
273 //entity.scale(this.scale); | 268 //entity.scale(this.scale); |
274 //if (this.scale == 2f){this.scale = 0.5f;} | 269 //if (this.scale == 2f){this.scale = 0.5f;} |
275 //else {this.scale = 2;} | 270 //else {this.scale = 2;} |
276 } | 271 } |
277 | 272 |
278 | 273 |
279 } | 274 } |
280 | 275 |
281 | 276 |
277 | |
278 private void prepareEar(Geometry ear, int n){ | |
279 if (this.audioRenderer instanceof MultiListener){ | |
280 MultiListener rf = (MultiListener)this.audioRenderer; | |
281 | |
282 auxListener = new Listener(); | |
283 auxListener.setLocation(ear.getLocalTranslation()); | |
284 | |
285 rf.addListener(auxListener); | |
286 WaveFileWriter aux = null; | |
287 | |
288 try {aux = new WaveFileWriter(new File("/home/r/tmp/ear"+n+".wav"));} | |
289 catch (FileNotFoundException e) {e.printStackTrace();} | |
290 | |
291 rf.registerSoundProcessor(auxListener, | |
292 new CompositeSoundProcessor(new Dancer(ear), aux)); | |
293 | |
294 } | |
295 } | |
282 | 296 |
283 | 297 |
284 public void simpleInitApp() { | 298 public void simpleInitApp() { |
285 this.setTimer(new IsoTimer(60)); | 299 this.setTimer(new IsoTimer(60)); |
286 initAudio(); | 300 initAudio(); |
287 initKeys(); | 301 initKeys(); |
288 createScene(); | 302 createScene(); |
289 listener.setLocation(ear1.getLocalTranslation()); | |
290 listener.setRotation(new Quaternion().fromAngleAxis(0, Vector3f.UNIT_Y)); | |
291 if (this.audioRenderer instanceof MultiListener){ | |
292 MultiListener rf = (MultiListener)this.audioRenderer; | |
293 | 303 |
294 | 304 prepareEar(ear1, 1); |
295 | 305 prepareEar(ear2, 1); |
296 auxListener = new Listener(listener); | 306 prepareEar(ear3, 1); |
297 | |
298 rf.addListener(auxListener); | |
299 WaveFileWriter aux = null; | |
300 WaveFileWriter main = null; | |
301 | |
302 | |
303 try {aux = new WaveFileWriter(new File("/home/r/tmp/aux.wav"));} | |
304 catch (FileNotFoundException e) {e.printStackTrace();} | |
305 | |
306 try {main = new WaveFileWriter(new File("/home/r/tmp/main.wav"));} | |
307 catch (FileNotFoundException e) {e.printStackTrace();} | |
308 | |
309 rf.registerSoundProcessor(auxListener, | |
310 new CompositeSoundProcessor(new Dancer(ear1, "aux"), aux)); | |
311 | |
312 rf.registerSoundProcessor( | |
313 new CompositeSoundProcessor(new Dancer(ear1, "--------\nmain"), main)); | |
314 } | |
315 | 307 |
316 motionControl.play(); | 308 motionControl.play(); |
317 } | 309 } |
318 | 310 |
319 | 311 |
348 | 340 |
349 public void simpleUpdate(float tpf) { | 341 public void simpleUpdate(float tpf) { |
350 if (countdown == 0){ | 342 if (countdown == 0){ |
351 music.play(); | 343 music.play(); |
352 } | 344 } |
353 //Vector3f loc = cam.getLocation(); | 345 Vector3f loc = cam.getLocation(); |
354 //Quaternion rot = cam.getRotation(); | 346 Quaternion rot = cam.getRotation(); |
355 //listener.setLocation(loc); | 347 listener.setLocation(loc); |
356 listener.setRotation(new Quaternion().fromAngleAxis(0, music.getLocalTranslation().subtract(listener.getLocation()))); | 348 listener.setRotation(rot); |
357 audioRenderer.updateListenerParam(listener, ListenerParam.Rotation); | 349 audioRenderer.updateListenerParam(listener, ListenerParam.Rotation); |
358 | 350 |
359 System.out.println(countdown); | 351 //System.out.println(countdown); |
360 | 352 |
361 if (countdown++ == 300) { this.requestClose(false);} | 353 //if (countdown++ == 300) { this.requestClose(false);} |
362 | 354 |
363 //System.out.println("channel "+ music.getChannel()); | 355 //System.out.println("channel "+ music.getChannel()); |
364 //listener.setLocation(cam.getLocation()); | 356 //listener.setLocation(cam.getLocation()); |
365 //listener.setRotation(cam.getRotation()); | 357 //listener.setRotation(cam.getRotation()); |
366 //auxListener.setLocation(loc); | 358 //auxListener.setLocation(loc); |
376 //Vector3f bellVelocity = bell.getLocalTranslation().subtract(prevBellPos).mult(1.0f/tpf); | 368 //Vector3f bellVelocity = bell.getLocalTranslation().subtract(prevBellPos).mult(1.0f/tpf); |
377 //prevBellPos = bell.getLocalTranslation(); | 369 //prevBellPos = bell.getLocalTranslation(); |
378 | 370 |
379 music.setLocalTranslation(bell.getLocalTranslation()); | 371 music.setLocalTranslation(bell.getLocalTranslation()); |
380 | 372 |
381 System.out.println("distance: " + | 373 //System.out.println("distance: " + |
382 music.getLocalTranslation().subtract(listener.getLocation()).length()); | 374 // music.getLocalTranslation().subtract(listener.getLocation()).length()); |
383 | 375 |
384 //music.setVelocity(bellVelocity); | 376 //music.setVelocity(bellVelocity); |
385 | 377 |
386 //audioRenderer.updateSourceParam(music, AudioParam.Position); | 378 //audioRenderer.updateSourceParam(music, AudioParam.Position); |
387 //audioRenderer.updateSourceParam(music, AudioParam.Velocity); | 379 //audioRenderer.updateSourceParam(music, AudioParam.Velocity); |