comparison src/com/aurellem/capture/examples/AdvancedAudio.java @ 18:2543c95a0fd2

fixed sound problem
author Robert McIntyre <rlm@mit.edu>
date Sat, 29 Oct 2011 14:39:19 -0700
parents dae169178d11
children 4de7988407ef
comparison
equal deleted inserted replaced
17:dae169178d11 18:2543c95a0fd2
5 import com.aurellem.capture.IsoTimer; 5 import com.aurellem.capture.IsoTimer;
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.AudioParam;
10 import com.jme3.audio.Listener; 11 import com.jme3.audio.Listener;
11 import com.jme3.cinematic.MotionPath; 12 import com.jme3.cinematic.MotionPath;
12 import com.jme3.cinematic.events.MotionTrack; 13 import com.jme3.cinematic.events.MotionTrack;
14 import com.jme3.input.controls.ActionListener;
15 import com.jme3.input.controls.MouseButtonTrigger;
13 import com.jme3.light.DirectionalLight; 16 import com.jme3.light.DirectionalLight;
14 import com.jme3.material.Material; 17 import com.jme3.material.Material;
15 import com.jme3.math.ColorRGBA; 18 import com.jme3.math.ColorRGBA;
16 import com.jme3.math.FastMath; 19 import com.jme3.math.FastMath;
17 import com.jme3.math.Quaternion; 20 import com.jme3.math.Quaternion;
53 app.setShowSettings(false); 56 app.setShowSettings(false);
54 app.setPauseOnLostFocus(false); 57 app.setPauseOnLostFocus(false);
55 org.lwjgl.input.Mouse.setGrabbed(false); 58 org.lwjgl.input.Mouse.setGrabbed(false);
56 app.start(); 59 app.start();
57 } 60 }
58
59
60
61 61
62 private MotionTrack motionControl; 62 private MotionTrack motionControl;
63 63
64 64
65 private void makeEar(Node root, Vector3f position){ 65 private void makeEar(Node root, Vector3f position){
144 path.addWayPoint(new Vector3f(-10, -25, 10)); 144 path.addWayPoint(new Vector3f(-10, -25, 10));
145 path.addWayPoint(new Vector3f(-10, 0, 0)); 145 path.addWayPoint(new Vector3f(-10, 0, 0));
146 146
147 // come at me bro! 147 // come at me bro!
148 path.addWayPoint(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); 148 path.addWayPoint(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
149 //path.addWayPoint(new Vector3f(0, 0 , -20));
150
149 path.setCurveTension(0.80f); 151 path.setCurveTension(0.80f);
150 152
151 153
152 motionControl = new MotionTrack(bell,path); 154 motionControl = new MotionTrack(bell,path);
153 motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation); 155 motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation);
154 motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y)); 156 motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
155 motionControl.setInitialDuration(10f); 157 motionControl.setInitialDuration(10f);
156 motionControl.setSpeed(0.1f); 158 motionControl.setSpeed(0.1f);
157 159
158 160
159 //path.enableDebugShape(assetManager, rootNode); 161 path.enableDebugShape(assetManager, rootNode);
160 162
161 163
162 positionCamera(); 164 positionCamera();
163 165
164 166
165 } 167 }
166 168
167 169
168 private void positionCamera(){ 170 private void positionCamera(){
169 this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); 171 //this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f));
170 this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f)); 172 this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f));
171
172
173 } 173 }
174 174
175 175
176 176
177 177
183 public File data1 = new File("/home/r/tmp/data1.wav"); 183 public File data1 = new File("/home/r/tmp/data1.wav");
184 public File data2 = new File("/home/r/tmp/data2.wav"); 184 public File data2 = new File("/home/r/tmp/data2.wav");
185 public File data3 = new File("/home/r/tmp/data3.wav"); 185 public File data3 = new File("/home/r/tmp/data3.wav");
186 186
187 187
188 @Override 188
189 public void simpleInitApp() { 189 public void simpleInitApp() {
190 this.setTimer(new IsoTimer(60)); 190 this.setTimer(new IsoTimer(60));
191 191
192 if (this.audioRenderer instanceof MultiListener){ 192 if (this.audioRenderer instanceof MultiListener){
193 MultiListener rf = (MultiListener)this.audioRenderer; 193 MultiListener rf = (MultiListener)this.audioRenderer;
208 208
209 209
210 210
211 211
212 initAudio(); 212 initAudio();
213 initKeys();
213 createScene(); 214 createScene();
214 215
215 216
216 motionControl.play(); 217 motionControl.play();
217 218
218 this.audioRenderer.playSource(music); 219 //this.audioRenderer.playSource(music);
219 220
220 221
221 222
222 } 223 }
223 224
224 /** We create two audio nodes. */ 225 /** We create two audio nodes. */
225 private void initAudio() { 226 private void initAudio() {
226 //audioRenderer.setEnvironment(Environment.Cavern); 227 //audioRenderer.setEnvironment(Environment.Cavern);
227 228
228 music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false); 229 music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false);
229 music.setLooping(true); 230
230 music.setVolume(2); 231 //music.setLooping(true);
231 music.setRefDistance(0.1f); 232
232 music.setMaxDistance(200); 233
234
235
236
237 rootNode.attachChild(music);
238 audioRenderer.playSource(music);
239
240 music.setVolume(1f);
233 music.setPositional(true); 241 music.setPositional(true);
242 music.setMaxDistance(200.0f);
243 music.setRefDistance(0.1f);
244 music.setRolloffFactor(5f);
245 audioRenderer.pauseSource(music);
246
247
248
234 } 249 }
235 250
236 /** Declaring the "Shoot" action, and 251 /** Declaring the "Shoot" action, and
237 * mapping it to a trigger (mouse click). */ 252 * mapping it to a trigger (mouse click). */
238 253
239 254
240 /** Defining the "Shoot" action: Play a gun sound. */ 255 /** Defining the "Shoot" action: Play a gun sound. */
241 256
257 private void initKeys() {
258 inputManager.addMapping("Shoot", new MouseButtonTrigger(0));
259 inputManager.addListener(actionListener, "Shoot");
260 }
261
262 /** Defining the "Shoot" action: Play a gun sound. */
263 private ActionListener actionListener = new ActionListener() {
264 @Override
265 public void onAction(String name, boolean keyPressed, float tpf) {
266 if (name.equals("Shoot") && !keyPressed) {
267 System.out.println("I'm playing! <3");
268 System.out.println(bell.getLocalTranslation().subtract(cam.getLocation()).length());
269
270 audioRenderer.playSource(music);
271 System.out.println(music.getRefDistance());
272
273 }
274 }
275 };
242 276
243 /** Move the listener with the camera - for 3D audio. */ 277 /** Move the listener with the camera - for 3D audio. */
244 @Override 278 @Override
245 public void simpleUpdate(float tpf) { 279 public void simpleUpdate(float tpf) {
246 Vector3f loc = cam.getLocation(); 280 //Vector3f loc = cam.getLocation();
247 Quaternion rot = cam.getRotation(); 281 //Quaternion rot = cam.getRotation();
248 listener.setLocation(loc); 282 //listener.setLocation(loc);
249 listener.setRotation(rot); 283 //listener.setRotation(rot);
250 auxListener.setLocation(loc); 284
251 auxListener.setRotation(rot); 285
286 listener.setLocation(cam.getLocation());
287 listener.setRotation(cam.getRotation());
288 //auxListener.setLocation(loc);
289 //auxListener.setRotation(rot);
290 //if (music.getStatus() == AudioNode.Status.Stopped){
291
292 //music.playInstance();
293 //}
294 //audioRenderer.updateSourceParam(music, AudioParam.Direction);
252 295
253 music.setLocalTranslation(bell.getLocalTranslation()); 296 music.setLocalTranslation(bell.getLocalTranslation());
254 297
298 //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_MIN_GAIN, 0f);
299 //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_ROLLOFF_FACTOR, 5f);
255 300
256 } 301 }
257 302
258 } 303 }