comparison src/com/aurellem/capture/examples/AdvancedAudio.java @ 15:be5ac56826be

created part of the advanced documentation
author Robert McIntyre <rlm@mit.edu>
date Fri, 28 Oct 2011 06:52:46 -0700
parents e299cd89074d
children 87f818f58975
comparison
equal deleted inserted replaced
14:e299cd89074d 15:be5ac56826be
6 import com.aurellem.capture.audio.MultiListener; 6 import com.aurellem.capture.audio.MultiListener;
7 import com.aurellem.capture.audio.WaveFileWriter; 7 import com.aurellem.capture.audio.WaveFileWriter;
8 import com.jme3.app.SimpleApplication; 8 import com.jme3.app.SimpleApplication;
9 import com.jme3.audio.AudioNode; 9 import com.jme3.audio.AudioNode;
10 import com.jme3.audio.Listener; 10 import com.jme3.audio.Listener;
11 import com.jme3.cinematic.MotionPath;
12 import com.jme3.cinematic.events.MotionTrack;
13 import com.jme3.input.KeyInput;
11 import com.jme3.input.controls.ActionListener; 14 import com.jme3.input.controls.ActionListener;
15 import com.jme3.input.controls.KeyTrigger;
12 import com.jme3.input.controls.MouseButtonTrigger; 16 import com.jme3.input.controls.MouseButtonTrigger;
17 import com.jme3.light.DirectionalLight;
13 import com.jme3.material.Material; 18 import com.jme3.material.Material;
14 import com.jme3.math.ColorRGBA; 19 import com.jme3.math.ColorRGBA;
20 import com.jme3.math.FastMath;
15 import com.jme3.math.Quaternion; 21 import com.jme3.math.Quaternion;
16 import com.jme3.math.Vector3f; 22 import com.jme3.math.Vector3f;
17 import com.jme3.scene.Geometry; 23 import com.jme3.scene.Geometry;
24 import com.jme3.scene.Node;
25 import com.jme3.scene.Spatial;
18 import com.jme3.scene.shape.Box; 26 import com.jme3.scene.shape.Box;
27 import com.jme3.scene.shape.Sphere;
19 import com.jme3.system.AppSettings; 28 import com.jme3.system.AppSettings;
20 29
21 30
22 /** 31 /**
23 * 32 *
37 * @author Robert McIntyre 46 * @author Robert McIntyre
38 * 47 *
39 */ 48 */
40 49
41 public class AdvancedAudio extends SimpleApplication { 50 public class AdvancedAudio extends SimpleApplication {
42 51
43 public static void main(String[] args) { 52 public static void main(String[] args) {
44 53
45 AdvancedAudio app = new AdvancedAudio(); 54 AdvancedAudio app = new AdvancedAudio();
46 AppSettings settings = new AppSettings(true); 55 AppSettings settings = new AppSettings(true);
47 56 //settings.setAudioRenderer("Send");
48 settings.setAudioRenderer("Send"); 57 app.setSettings(settings);
49 app.setSettings(settings); 58 app.setShowSettings(false);
50 app.setShowSettings(false); 59 app.setPauseOnLostFocus(false);
51 app.start(); 60 org.lwjgl.input.Mouse.setGrabbed(false);
52 app.setPauseOnLostFocus(false); 61 app.start();
53 } 62 }
63
64
65 private Spatial teapot;
66 private boolean active = true;
67 private boolean playing = false;
68 private MotionPath path;
69 private MotionTrack motionControl;
70
71
72 private void makeEar(Node root, Vector3f position){
73 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
74 Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f));
75 ear.setLocalTranslation(position);
76 mat.setColor("Color", ColorRGBA.Green);
77 ear.setMaterial(mat);
78 root.attachChild(ear);
79 }
80
81
82 private void createScene() {
83 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
84 Geometry bell = new Geometry( "sound-emitter" , new Sphere(15,15,1));
85 mat.setColor("Color", ColorRGBA.Blue);
86 bell.setMaterial(mat);
87 rootNode.attachChild(bell);
88
89
90
91
92 DirectionalLight light = new DirectionalLight();
93 light.setDirection(new Vector3f(0, -1, 0).normalizeLocal());
94 light.setColor(ColorRGBA.White.mult(1.5f));
95 rootNode.addLight(light);
96
97 makeEar(rootNode, new Vector3f(0, 0 ,20));
98 makeEar(rootNode, new Vector3f(0, 0 ,-20));
99 makeEar(rootNode, new Vector3f(20, 0 ,0));
100 makeEar(rootNode, new Vector3f(-20, 0 ,0));
101
102 MotionPath path = new MotionPath();
103
104 // loop 1
105 path.addWayPoint(new Vector3f(0, 0, 0));
106 path.addWayPoint(new Vector3f(0, 0, -10));
107 path.addWayPoint(new Vector3f(-2, 0, -14));
108 path.addWayPoint(new Vector3f(-6, 0, -20));
109 path.addWayPoint(new Vector3f(0, 0, -26));
110 path.addWayPoint(new Vector3f(6, 0, -20));
111 path.addWayPoint(new Vector3f(0, 0, -14));
112 path.addWayPoint(new Vector3f(-6, 0, -20));
113 path.addWayPoint(new Vector3f(0, 0, -26));
114 path.addWayPoint(new Vector3f(6, 0, -20));
115
116
117 // loop 2
118 path.addWayPoint(new Vector3f(5, 0, -5));
119 path.addWayPoint(new Vector3f(7, 0, 1.5f));
120 path.addWayPoint(new Vector3f(14, 0, 2));
121 path.addWayPoint(new Vector3f(20, 0, 6));
122 path.addWayPoint(new Vector3f(26, 0, 0));
123 path.addWayPoint(new Vector3f(20, 0, -6));
124 path.addWayPoint(new Vector3f(14, 0, 0));
125 path.addWayPoint(new Vector3f(20, 0, 6));
126 path.addWayPoint(new Vector3f(26, 0, 0));
127 path.addWayPoint(new Vector3f(20, 0, -6));
128 path.addWayPoint(new Vector3f(14, 0, 0));
129
130
131
132 // loop 3
133 path.addWayPoint(new Vector3f(8, 0, 7.5f));
134 path.addWayPoint(new Vector3f(7, 0, 10.5f));
135 path.addWayPoint(new Vector3f(6, 0, 20));
136 path.addWayPoint(new Vector3f(0, 0, 26));
137 path.addWayPoint(new Vector3f(-6, 0, 20));
138 path.addWayPoint(new Vector3f(0, 0, 14));
139 path.addWayPoint(new Vector3f(6, 0, 20));
140 path.addWayPoint(new Vector3f(0, 0, 26));
141 path.addWayPoint(new Vector3f(-6, 0, 20));
142 path.addWayPoint(new Vector3f(0, 0, 14));
143
144
145 // begin elipse
146
147 path.addWayPoint(new Vector3f(16, 5, 20));
148 path.addWayPoint(new Vector3f(0, 0, 26));
149 path.addWayPoint(new Vector3f(-16, -10, 20));
150 path.addWayPoint(new Vector3f(0, 0, 14));
151 path.addWayPoint(new Vector3f(16, 20, 20));
152 path.addWayPoint(new Vector3f(0, 0, 26));
153 path.addWayPoint(new Vector3f(-10, -25, 10));
154 path.addWayPoint(new Vector3f(-10, 0, 0));
155
156 // come at me bro!
157 path.addWayPoint(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
158 path.setCurveTension(0.80f);
159
160
161 motionControl = new MotionTrack(bell,path);
162 motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation);
163 motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
164 motionControl.setInitialDuration(10f);
165 motionControl.setSpeed(0.1f);
166
167
168 //path.enableDebugShape(assetManager, rootNode);
169
170
171 positionCamera();
172
173
174 }
175
176
177 private void positionCamera(){
178 this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
179 this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f));
180
181
182 }
183
184
185
186
54 187
55 private AudioNode audio_gun; 188 private AudioNode audio_gun;
56 private AudioNode audio_nature; 189 private AudioNode audio_nature;
57 private Geometry player; 190 private Geometry player;
58 private Listener auxListener = new Listener(); 191 private Listener auxListener = new Listener();
59 public File data1 = new File("/home/r/tmp/data1.wav"); 192 public File data1 = new File("/home/r/tmp/data1.wav");
60 public File data2 = new File("/home/r/tmp/data2.wav"); 193 public File data2 = new File("/home/r/tmp/data2.wav");
61 public File data3 = new File("/home/r/tmp/data3.wav"); 194 public File data3 = new File("/home/r/tmp/data3.wav");
62 195
63 private File makeTarget(int n){
64 return new File("/home/r/tmp/assload-" + n + ".wav");
65 }
66
67 196
68 @Override 197 @Override
69 public void simpleInitApp() { 198 public void simpleInitApp() {
70 this.setTimer(new IsoTimer(60)); 199 //this.setTimer(new IsoTimer(60));
71
72 200
73 if (this.audioRenderer instanceof MultiListener){ 201 if (this.audioRenderer instanceof MultiListener){
74 MultiListener rf = (MultiListener)this.audioRenderer; 202 MultiListener rf = (MultiListener)this.audioRenderer;
75 203
76 for (int n = 0; n < 0; n++){ 204 for (int n = 0; n < 0; n++){
77 Listener zzz = new Listener(); 205 Listener zzz = new Listener();
78 rf.addListener(zzz); 206 rf.addListener(zzz);
79 rf.registerSoundProcessor(
80 zzz, new WaveFileWriter(makeTarget(n)));
81 } 207 }
82 Listener listener3 = new Listener(); 208 Listener listener3 = new Listener();
83 rf.addListener(auxListener); 209 rf.addListener(auxListener);
84 rf.addListener(listener3); 210 rf.addListener(listener3);
85 rf.registerSoundProcessor(new WaveFileWriter(data1)); 211 rf.registerSoundProcessor(new WaveFileWriter(data1));
86 rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2)); 212 rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2));
87 rf.registerSoundProcessor(listener3, new WaveFileWriter(data3)); 213 rf.registerSoundProcessor(listener3, new WaveFileWriter(data3));
88 } 214 }
89 flyCam.setMoveSpeed(40); 215
90 216
91 /** just a blue box floating in space */ 217
92 Box box1 = new Box(Vector3f.ZERO, 1, 1, 1); 218
93 player = new Geometry("Player", box1); 219
94 Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
95 mat1.setColor("Color", ColorRGBA.Blue);
96 player.setMaterial(mat1);
97 rootNode.attachChild(player);
98
99 /** custom init methods, see below */
100 initKeys(); 220 initKeys();
101 initAudio(); 221 initAudio();
222 createScene();
223
224
225 motionControl.play();
102 226
103 this.audioRenderer.playSource(audio_gun); 227 this.audioRenderer.playSource(audio_gun);
104 228
105 229
106 230
150 Quaternion rot = cam.getRotation(); 274 Quaternion rot = cam.getRotation();
151 listener.setLocation(loc); 275 listener.setLocation(loc);
152 listener.setRotation(rot); 276 listener.setRotation(rot);
153 auxListener.setLocation(loc); 277 auxListener.setLocation(loc);
154 auxListener.setRotation(rot); 278 auxListener.setRotation(rot);
155 if (audio_gun.getStatus() == AudioNode.Status.Stopped){ 279
156 System.out.println("I'm Stopped!");
157 this.requestClose(false);
158 }
159 280
160 281
161 } 282 }
162 283
163 } 284 }