view src/com/aurellem/capture/hello/HelloAudio.java @ 10:4c5fc53778c1

moved randelshofer stuff to rightfull place, enabled XuggleVideoRecorder
author Robert McIntyre <rlm@mit.edu>
date Wed, 26 Oct 2011 09:38:27 -0700
parents 5dfc9e768816
children 8a6b1684f536
line wrap: on
line source
1 package com.aurellem.capture.hello;
3 import java.io.File;
5 import com.aurellem.capture.IsoTimer;
6 import com.aurellem.capture.audio.MultiListener;
7 import com.aurellem.capture.audio.WaveFileWriter;
8 import com.jme3.app.SimpleApplication;
9 import com.jme3.audio.AudioNode;
10 import com.jme3.audio.Listener;
11 import com.jme3.input.controls.ActionListener;
12 import com.jme3.input.controls.MouseButtonTrigger;
13 import com.jme3.material.Material;
14 import com.jme3.math.ColorRGBA;
15 import com.jme3.math.Quaternion;
16 import com.jme3.math.Vector3f;
17 import com.jme3.scene.Geometry;
18 import com.jme3.scene.shape.Box;
19 import com.jme3.system.AppSettings;
21 /** Sample 11 - playing 3D audio. */
22 public class HelloAudio extends SimpleApplication {
24 private AudioNode audio_gun;
25 private AudioNode audio_nature;
26 private Geometry player;
27 private Listener auxListener = new Listener();
28 public File data1 = new File("/home/r/tmp/data1.wav");
29 public File data2 = new File("/home/r/tmp/data2.wav");
30 public File data3 = new File("/home/r/tmp/data3.wav");
32 private File makeTarget(int n){
33 return new File("/home/r/tmp/assload-" + n + ".wav");
34 }
37 public static void main(String[] args) {
39 // Logger.getLogger("com.jme3").setLevel(Level.OFF);
41 HelloAudio app = new HelloAudio();
42 AppSettings settings = new AppSettings(true);
44 settings.setAudioRenderer("Send");
45 app.setSettings(settings);
46 app.setShowSettings(false);
47 app.start();
48 app.setPauseOnLostFocus(false);
49 }
51 @Override
52 public void simpleInitApp() {
53 this.setTimer(new IsoTimer(60));
56 if (this.audioRenderer instanceof MultiListener){
57 MultiListener rf = (MultiListener)this.audioRenderer;
59 for (int n = 0; n < 0; n++){
60 Listener zzz = new Listener();
61 rf.addListener(zzz);
62 rf.registerSoundProcessor(
63 zzz, new WaveFileWriter(makeTarget(n)));
64 }
65 Listener listener3 = new Listener();
66 rf.addListener(auxListener);
67 rf.addListener(listener3);
68 rf.registerSoundProcessor(new WaveFileWriter(data1));
69 rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2));
70 rf.registerSoundProcessor(listener3, new WaveFileWriter(data3));
71 }
72 flyCam.setMoveSpeed(40);
74 /** just a blue box floating in space */
75 Box box1 = new Box(Vector3f.ZERO, 1, 1, 1);
76 player = new Geometry("Player", box1);
77 Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
78 mat1.setColor("Color", ColorRGBA.Blue);
79 player.setMaterial(mat1);
80 rootNode.attachChild(player);
82 /** custom init methods, see below */
83 initKeys();
84 initAudio();
86 this.audioRenderer.playSource(audio_gun);
90 }
92 /** We create two audio nodes. */
93 private void initAudio() {
94 //audioRenderer.setEnvironment(Environment.Cavern);
95 /* gun shot sound is to be triggered by a mouse click. */
96 audio_gun = new AudioNode(audioRenderer, assetManager, "Sound/Effects/Gun.wav", false);
97 //audio_gun = new AudioNode(assetManager, "Sound/Effects/dream.wav", false, false);
98 audio_gun.setLooping(false);
99 audio_gun.setVolume(2);
100 audio_gun.setPositional(true);
103 /* nature sound - keeps playing in a loop. */
104 audio_nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", false, false);
105 audio_nature.setLooping(true);
106 audio_nature.setPositional(true);
107 audio_nature.setLocalTranslation(Vector3f.ZERO.clone());
108 audio_nature.setVolume(3);
109 audio_nature.updateGeometricState();
110 }
112 /** Declaring the "Shoot" action, and
113 * mapping it to a trigger (mouse click). */
114 private void initKeys() {
115 inputManager.addMapping("Shoot", new MouseButtonTrigger(0));
116 inputManager.addListener(actionListener, "Shoot");
117 }
119 /** Defining the "Shoot" action: Play a gun sound. */
120 private ActionListener actionListener = new ActionListener() {
121 @Override
122 public void onAction(String name, boolean keyPressed, float tpf) {
123 if (name.equals("Shoot") && !keyPressed) {
124 audioRenderer.playSource(audio_gun); // play once!
125 }
126 }
127 };
129 /** Move the listener with the camera - for 3D audio. */
130 @Override
131 public void simpleUpdate(float tpf) {
132 Vector3f loc = cam.getLocation();
133 Quaternion rot = cam.getRotation();
134 listener.setLocation(loc);
135 listener.setRotation(rot);
136 auxListener.setLocation(loc);
137 auxListener.setRotation(rot);
138 if (audio_gun.getStatus() == AudioNode.Status.Stopped){
139 System.out.println("I'm Stopped!");
140 this.requestClose(false);
141 }
144 }
146 }