comparison src/com/aurellem/capture/examples/AdvancedAudio.java @ 37:094a92b556a2

still trying to debug stupid program
author Robert McIntyre <rlm@mit.edu>
date Mon, 31 Oct 2011 02:35:35 -0700
parents 2a525e937d86
children adeb88787645
comparison
equal deleted inserted replaced
36:2a525e937d86 37:094a92b556a2
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; 22 import com.jme3.audio.AudioParam;
23 import com.jme3.audio.Listener; 23 import com.jme3.audio.Listener;
24 import com.jme3.audio.ListenerParam;
24 import com.jme3.cinematic.MotionPath; 25 import com.jme3.cinematic.MotionPath;
25 import com.jme3.cinematic.events.MotionTrack; 26 import com.jme3.cinematic.events.MotionTrack;
26 import com.jme3.input.controls.ActionListener; 27 import com.jme3.input.controls.ActionListener;
27 import com.jme3.input.controls.MouseButtonTrigger; 28 import com.jme3.input.controls.MouseButtonTrigger;
28 import com.jme3.light.DirectionalLight; 29 import com.jme3.light.DirectionalLight;
67 settings.setAudioRenderer("Send"); 68 settings.setAudioRenderer("Send");
68 app.setSettings(settings); 69 app.setSettings(settings);
69 app.setShowSettings(false); 70 app.setShowSettings(false);
70 app.setPauseOnLostFocus(false); 71 app.setPauseOnLostFocus(false);
71 org.lwjgl.input.Mouse.setGrabbed(false); 72 org.lwjgl.input.Mouse.setGrabbed(false);
72 try {Capture.captureVideo(app, new File("/home/r/tmp/out.avi"));} 73 //try {Capture.captureVideo(app, new File("/home/r/tmp/out.avi"));}
73 catch (IOException e) {e.printStackTrace();} 74 //catch (IOException e) {e.printStackTrace();}
74 app.start(); 75 app.start();
75 } 76 }
76 77
77 private MotionTrack motionControl; 78 private MotionTrack motionControl;
78 79
156 DirectionalLight light = new DirectionalLight(); 157 DirectionalLight light = new DirectionalLight();
157 light.setDirection(new Vector3f(0, -1, 0).normalizeLocal()); 158 light.setDirection(new Vector3f(0, -1, 0).normalizeLocal());
158 light.setColor(ColorRGBA.White.mult(1.5f)); 159 light.setColor(ColorRGBA.White.mult(1.5f));
159 rootNode.addLight(light); 160 rootNode.addLight(light);
160 161
161 ear1 = makeEar(rootNode, new Vector3f(0, 0 ,20)); 162 ear1 = makeEar(rootNode, new Vector3f(0, 0 ,-20));
162 //ear2 = makeEar(rootNode, new Vector3f(0, 0 ,-20)); 163 //ear2 = makeEar(rootNode, new Vector3f(0, 0 ,-20));
163 //ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0)); 164 //ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0));
164 //ear4 = makeEar(rootNode, new Vector3f(-20, 0 ,0)); 165 //ear4 = makeEar(rootNode, new Vector3f(-20, 0 ,0));
165 166
166 MotionPath track = new MotionPath(); 167 MotionPath track = new MotionPath();
202 203
203 204
204 205
205 private void initAudio() { 206 private void initAudio() {
206 207
207 music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false); 208 music = new AudioNode(assetManager, "Sound/Environment/sqr-1kHz.wav", false);
208 209
209 rootNode.attachChild(music); 210 rootNode.attachChild(music);
210 audioRenderer.playSource(music); 211 //audioRenderer.playSource(music);
211 music.setPositional(false); 212 //music.setPositional(true);
212 music.setVolume(1f); 213 //music.setVolume(1f);
213 music.setReverbEnabled(false); 214 //music.setReverbEnabled(false);
214 music.setMaxDistance(200.0f); 215 //music.setDirectional(false);
215 music.setRefDistance(1f); 216 //music.setMaxDistance(200.0f);
216 music.setRolloffFactor(5f); 217 //music.setRefDistance(1f);
217 audioRenderer.pauseSource(music); 218 //music.setRolloffFactor(1f);
218 219 //music.setLooping(false);
219 } 220 //audioRenderer.pauseSource(music);
220 221
221 222 }
222 223
223 224
224 private Listener auxListener = new Listener(); 225
226
227 private Listener auxListener;
225 //public File data1 = new File("/home/r/tmp/data1.wav"); 228 //public File data1 = new File("/home/r/tmp/data1.wav");
226 //public File data2 = new File("/home/r/tmp/data2.wav"); 229 //public File data2 = new File("/home/r/tmp/data2.wav");
227 //public File data3 = new File("/home/r/tmp/data3.wav"); 230 //public File data3 = new File("/home/r/tmp/data3.wav");
228 //public File data4 = new File("/home/r/tmp/data4.wav"); 231 //public File data4 = new File("/home/r/tmp/data4.wav");
229 //public File data5 = new File("/home/r/tmp/data5.wav"); 232 //public File data5 = new File("/home/r/tmp/data5.wav");
282 this.setTimer(new IsoTimer(60)); 285 this.setTimer(new IsoTimer(60));
283 initAudio(); 286 initAudio();
284 initKeys(); 287 initKeys();
285 createScene(); 288 createScene();
286 listener.setLocation(ear1.getLocalTranslation()); 289 listener.setLocation(ear1.getLocalTranslation());
290 listener.setRotation(new Quaternion().fromAngleAxis(0, Vector3f.UNIT_Y));
287 if (this.audioRenderer instanceof MultiListener){ 291 if (this.audioRenderer instanceof MultiListener){
288 MultiListener rf = (MultiListener)this.audioRenderer; 292 MultiListener rf = (MultiListener)this.audioRenderer;
289 293
290 294
291 295
341 345
342 //private Vector3f prevBellPos = Vector3f.ZERO; 346 //private Vector3f prevBellPos = Vector3f.ZERO;
343 private int countdown = 0; 347 private int countdown = 0;
344 348
345 public void simpleUpdate(float tpf) { 349 public void simpleUpdate(float tpf) {
350 if (countdown == 0){
351 music.play();
352 }
346 //Vector3f loc = cam.getLocation(); 353 //Vector3f loc = cam.getLocation();
347 //Quaternion rot = cam.getRotation(); 354 //Quaternion rot = cam.getRotation();
348 //listener.setLocation(loc); 355 //listener.setLocation(loc);
349 //listener.setRotation(rot); 356 listener.setRotation(new Quaternion().fromAngleAxis(0, music.getLocalTranslation().subtract(listener.getLocation())));
357 audioRenderer.updateListenerParam(listener, ListenerParam.Rotation);
358
350 System.out.println(countdown); 359 System.out.println(countdown);
351 if (countdown++ == 400) { this.requestClose(false);} 360
352 361 if (countdown++ == 700) { this.requestClose(false);}
353 System.out.println("channel "+ music.getChannel()); 362
363 //System.out.println("channel "+ music.getChannel());
354 //listener.setLocation(cam.getLocation()); 364 //listener.setLocation(cam.getLocation());
355 //listener.setRotation(cam.getRotation()); 365 //listener.setRotation(cam.getRotation());
356 //auxListener.setLocation(loc); 366 //auxListener.setLocation(loc);
357 //auxListener.setRotation(rot); 367 //auxListener.setRotation(rot);
358 if (music.getStatus() != AudioNode.Status.Playing){ 368 //if (music.getStatus() != AudioNode.Status.Playing){
359 //audioRenderer.playSource(music); 369 //audioRenderer.playSource(music);
360 music.play(); 370 //music.play();
361 bell.getMaterial().setColor("Color", ColorRGBA.randomColor()); 371 // bell.getMaterial().setColor("Color", ColorRGBA.randomColor());
362 System.out.println("I'm playing! <3"); 372 //System.out.println("I'm playing! <3");
363 } 373 //}
364 //audioRenderer.updateSourceParam(music, AudioParam.Direction); 374 //audioRenderer.updateSourceParam(music, AudioParam.Direction);
365 375
366 //Vector3f bellVelocity = bell.getLocalTranslation().subtract(prevBellPos).mult(1.0f/tpf); 376 //Vector3f bellVelocity = bell.getLocalTranslation().subtract(prevBellPos).mult(1.0f/tpf);
367 //prevBellPos = bell.getLocalTranslation(); 377 //prevBellPos = bell.getLocalTranslation();
368 378
369 music.setLocalTranslation(bell.getLocalTranslation()); 379 music.setLocalTranslation(bell.getLocalTranslation());
380
381 System.out.println("distance: " +
382 music.getLocalTranslation().subtract(listener.getLocation()).length());
383
370 //music.setVelocity(bellVelocity); 384 //music.setVelocity(bellVelocity);
371 385
372 //audioRenderer.updateSourceParam(music, AudioParam.Position); 386 //audioRenderer.updateSourceParam(music, AudioParam.Position);
373 //audioRenderer.updateSourceParam(music, AudioParam.Velocity); 387 //audioRenderer.updateSourceParam(music, AudioParam.Velocity);
374 388