# HG changeset patch # User Robert McIntyre # Date 1319924359 25200 # Node ID 2543c95a0fd2179f52677a83469641d696049e7b # Parent dae169178d113fd3f933dd48f0e768a0fc8c859f fixed sound problem diff -r dae169178d11 -r 2543c95a0fd2 src/com/aurellem/capture/examples/AdvancedAudio.java --- a/src/com/aurellem/capture/examples/AdvancedAudio.java Sat Oct 29 00:33:07 2011 -0700 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java Sat Oct 29 14:39:19 2011 -0700 @@ -7,9 +7,12 @@ import com.aurellem.capture.audio.WaveFileWriter; import com.jme3.app.SimpleApplication; import com.jme3.audio.AudioNode; +import com.jme3.audio.AudioParam; import com.jme3.audio.Listener; import com.jme3.cinematic.MotionPath; import com.jme3.cinematic.events.MotionTrack; +import com.jme3.input.controls.ActionListener; +import com.jme3.input.controls.MouseButtonTrigger; import com.jme3.light.DirectionalLight; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; @@ -55,9 +58,6 @@ org.lwjgl.input.Mouse.setGrabbed(false); app.start(); } - - - private MotionTrack motionControl; @@ -146,6 +146,8 @@ // come at me bro! path.addWayPoint(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); + //path.addWayPoint(new Vector3f(0, 0 , -20)); + path.setCurveTension(0.80f); @@ -156,7 +158,7 @@ motionControl.setSpeed(0.1f); - //path.enableDebugShape(assetManager, rootNode); + path.enableDebugShape(assetManager, rootNode); positionCamera(); @@ -166,10 +168,8 @@ private void positionCamera(){ - this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); + //this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f)); - - } @@ -185,7 +185,7 @@ public File data3 = new File("/home/r/tmp/data3.wav"); - @Override + public void simpleInitApp() { this.setTimer(new IsoTimer(60)); @@ -210,12 +210,13 @@ initAudio(); + initKeys(); createScene(); motionControl.play(); - this.audioRenderer.playSource(music); + //this.audioRenderer.playSource(music); @@ -226,11 +227,25 @@ //audioRenderer.setEnvironment(Environment.Cavern); music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false); - music.setLooping(true); - music.setVolume(2); - music.setRefDistance(0.1f); - music.setMaxDistance(200); + + //music.setLooping(true); + + + + + + rootNode.attachChild(music); + audioRenderer.playSource(music); + + music.setVolume(1f); music.setPositional(true); + music.setMaxDistance(200.0f); + music.setRefDistance(0.1f); + music.setRolloffFactor(5f); + audioRenderer.pauseSource(music); + + + } /** Declaring the "Shoot" action, and @@ -239,19 +254,49 @@ /** Defining the "Shoot" action: Play a gun sound. */ + private void initKeys() { + inputManager.addMapping("Shoot", new MouseButtonTrigger(0)); + inputManager.addListener(actionListener, "Shoot"); + } + + /** Defining the "Shoot" action: Play a gun sound. */ + private ActionListener actionListener = new ActionListener() { + @Override + public void onAction(String name, boolean keyPressed, float tpf) { + if (name.equals("Shoot") && !keyPressed) { + System.out.println("I'm playing! <3"); + System.out.println(bell.getLocalTranslation().subtract(cam.getLocation()).length()); + + audioRenderer.playSource(music); + System.out.println(music.getRefDistance()); + + } + } + }; /** Move the listener with the camera - for 3D audio. */ @Override public void simpleUpdate(float tpf) { - Vector3f loc = cam.getLocation(); - Quaternion rot = cam.getRotation(); - listener.setLocation(loc); - listener.setRotation(rot); - auxListener.setLocation(loc); - auxListener.setRotation(rot); + //Vector3f loc = cam.getLocation(); + //Quaternion rot = cam.getRotation(); + //listener.setLocation(loc); + //listener.setRotation(rot); + + + listener.setLocation(cam.getLocation()); + listener.setRotation(cam.getRotation()); + //auxListener.setLocation(loc); + //auxListener.setRotation(rot); + //if (music.getStatus() == AudioNode.Status.Stopped){ + + //music.playInstance(); + //} + //audioRenderer.updateSourceParam(music, AudioParam.Direction); music.setLocalTranslation(bell.getLocalTranslation()); + //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_MIN_GAIN, 0f); + //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_ROLLOFF_FACTOR, 5f); }