Mercurial > jmeCapture
comparison src/com/aurellem/capture/examples/AdvancedAudio.java @ 35:c969b04fa0dc
working on divergence
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 31 Oct 2011 00:14:46 -0700 |
parents | 13d354e1184b |
children | 2a525e937d86 |
comparison
equal
deleted
inserted
replaced
34:13d354e1184b | 35:c969b04fa0dc |
---|---|
2 | 2 |
3 import java.io.File; | 3 import java.io.File; |
4 import java.io.FileNotFoundException; | 4 import java.io.FileNotFoundException; |
5 import java.io.IOException; | 5 import java.io.IOException; |
6 import java.nio.ByteBuffer; | 6 import java.nio.ByteBuffer; |
7 import java.util.logging.Level; | |
8 import java.util.logging.Logger; | |
7 | 9 |
8 import javax.sound.sampled.AudioFormat; | 10 import javax.sound.sampled.AudioFormat; |
9 | 11 |
10 import org.tritonus.share.sampled.FloatSampleTools; | 12 import org.tritonus.share.sampled.FloatSampleTools; |
11 | 13 |
57 */ | 59 */ |
58 | 60 |
59 public class AdvancedAudio extends SimpleApplication { | 61 public class AdvancedAudio extends SimpleApplication { |
60 | 62 |
61 public static void main(String[] args) { | 63 public static void main(String[] args) { |
62 | 64 Logger.getLogger("com.jme3").setLevel(Level.OFF); |
63 AdvancedAudio app = new AdvancedAudio(); | 65 AdvancedAudio app = new AdvancedAudio(); |
64 AppSettings settings = new AppSettings(true); | 66 AppSettings settings = new AppSettings(true); |
65 settings.setAudioRenderer("Send"); | 67 settings.setAudioRenderer("Send"); |
66 app.setSettings(settings); | 68 app.setSettings(settings); |
67 app.setShowSettings(false); | 69 app.setShowSettings(false); |
203 private void initAudio() { | 205 private void initAudio() { |
204 | 206 |
205 music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false); | 207 music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false); |
206 | 208 |
207 rootNode.attachChild(music); | 209 rootNode.attachChild(music); |
208 audioRenderer.playSource(music); | 210 //audioRenderer.playSource(music); |
209 music.setPositional(true); | 211 music.setPositional(true); |
210 music.setVolume(1f); | 212 music.setVolume(1f); |
211 music.setReverbEnabled(false); | 213 music.setReverbEnabled(false); |
212 music.setMaxDistance(200.0f); | 214 music.setMaxDistance(200.0f); |
213 music.setRefDistance(1f); | 215 music.setRefDistance(1f); |
214 music.setRolloffFactor(5f); | 216 music.setRolloffFactor(5f); |
215 audioRenderer.pauseSource(music); | 217 |
218 | |
219 //audioRenderer.pauseSource(music); | |
216 | 220 |
217 } | 221 } |
218 | 222 |
219 | 223 |
220 | 224 |
279 public void simpleInitApp() { | 283 public void simpleInitApp() { |
280 this.setTimer(new IsoTimer(60)); | 284 this.setTimer(new IsoTimer(60)); |
281 initAudio(); | 285 initAudio(); |
282 initKeys(); | 286 initKeys(); |
283 createScene(); | 287 createScene(); |
288 listener.setLocation(ear1.getLocalTranslation()); | |
284 if (this.audioRenderer instanceof MultiListener){ | 289 if (this.audioRenderer instanceof MultiListener){ |
285 MultiListener rf = (MultiListener)this.audioRenderer; | 290 MultiListener rf = (MultiListener)this.audioRenderer; |
286 | 291 |
287 | 292 |
288 listener.setLocation(ear1.getLocalTranslation()); | 293 |
289 auxListener = new Listener(listener); | 294 auxListener = new Listener(listener); |
290 | 295 |
291 rf.addListener(auxListener); | 296 rf.addListener(auxListener); |
292 WaveFileWriter aux = null; | 297 WaveFileWriter aux = null; |
293 WaveFileWriter main = null; | 298 WaveFileWriter main = null; |
321 /** Defining the "Shoot" action: Play a gun sound. */ | 326 /** Defining the "Shoot" action: Play a gun sound. */ |
322 private ActionListener actionListener = new ActionListener() { | 327 private ActionListener actionListener = new ActionListener() { |
323 @Override | 328 @Override |
324 public void onAction(String name, boolean keyPressed, float tpf) { | 329 public void onAction(String name, boolean keyPressed, float tpf) { |
325 if (name.equals("Shoot") && !keyPressed) { | 330 if (name.equals("Shoot") && !keyPressed) { |
326 System.out.println("I'm playing! <3"); | 331 |
327 System.out.println(bell.getLocalTranslation().subtract(cam.getLocation()).length()); | 332 System.out.println(bell.getLocalTranslation().subtract(listener.getLocation()).length()); |
328 bell.getMaterial().setColor("Color", ColorRGBA.randomColor()); | 333 //bell.getMaterial().setColor("Color", ColorRGBA.randomColor()); |
329 audioRenderer.playSource(music); | 334 //audioRenderer.playSource(music); |
330 System.out.println(music.getRefDistance()); | 335 System.out.println(music.getRefDistance()); |
331 | 336 |
332 } | 337 } |
333 } | 338 } |
334 }; | 339 }; |
335 | 340 |
336 /** Move the listener with the camera - for 3D audio. */ | 341 /** Move the listener with the camera - for 3D audio. */ |
337 | 342 |
338 | 343 |
339 private Vector3f prevBellPos = Vector3f.ZERO; | 344 //private Vector3f prevBellPos = Vector3f.ZERO; |
340 | 345 private int countdown = 0; |
341 | 346 |
342 public void simpleUpdate(float tpf) { | 347 public void simpleUpdate(float tpf) { |
343 //Vector3f loc = cam.getLocation(); | 348 //Vector3f loc = cam.getLocation(); |
344 //Quaternion rot = cam.getRotation(); | 349 //Quaternion rot = cam.getRotation(); |
345 //listener.setLocation(loc); | 350 //listener.setLocation(loc); |
346 //listener.setRotation(rot); | 351 //listener.setRotation(rot); |
347 | 352 System.out.println(countdown); |
348 | 353 if (countdown++ == 14) { this.requestClose(false);} |
354 | |
355 System.out.println("channel "+ music.getChannel()); | |
349 //listener.setLocation(cam.getLocation()); | 356 //listener.setLocation(cam.getLocation()); |
350 //listener.setRotation(cam.getRotation()); | 357 //listener.setRotation(cam.getRotation()); |
351 //auxListener.setLocation(loc); | 358 //auxListener.setLocation(loc); |
352 //auxListener.setRotation(rot); | 359 //auxListener.setRotation(rot); |
353 if (music.getStatus() != AudioNode.Status.Playing){ | 360 if (music.getStatus() != AudioNode.Status.Playing){ |
354 audioRenderer.playSource(music); | 361 //audioRenderer.playSource(music); |
362 music.play(); | |
355 bell.getMaterial().setColor("Color", ColorRGBA.randomColor()); | 363 bell.getMaterial().setColor("Color", ColorRGBA.randomColor()); |
364 System.out.println("I'm playing! <3"); | |
356 } | 365 } |
357 //audioRenderer.updateSourceParam(music, AudioParam.Direction); | 366 //audioRenderer.updateSourceParam(music, AudioParam.Direction); |
358 | 367 |
359 Vector3f bellVelocity = bell.getLocalTranslation().subtract(prevBellPos).mult(1.0f/tpf); | 368 //Vector3f bellVelocity = bell.getLocalTranslation().subtract(prevBellPos).mult(1.0f/tpf); |
360 prevBellPos = bell.getLocalTranslation(); | 369 //prevBellPos = bell.getLocalTranslation(); |
361 | 370 |
362 music.setLocalTranslation(bell.getLocalTranslation()); | 371 music.setLocalTranslation(bell.getLocalTranslation()); |
363 music.setVelocity(bellVelocity); | 372 //music.setVelocity(bellVelocity); |
364 | 373 |
365 //audioRenderer.updateSourceParam(music, AudioParam.Position); | 374 //audioRenderer.updateSourceParam(music, AudioParam.Position); |
366 //audioRenderer.updateSourceParam(music, AudioParam.Velocity); | 375 //audioRenderer.updateSourceParam(music, AudioParam.Velocity); |
367 | 376 |
368 | 377 |