# HG changeset patch # User Robert McIntyre # Date 1319926566 25200 # Node ID 4de7988407ef316aa3b7a07da02ee6553f2a3cc1 # Parent 2543c95a0fd2179f52677a83469641d696049e7b added CompositeSoundProcessor for combining SoundProcessors diff -r 2543c95a0fd2 -r 4de7988407ef src/com/aurellem/capture/audio/CompositeSoundProcessor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/aurellem/capture/audio/CompositeSoundProcessor.java Sat Oct 29 15:16:06 2011 -0700 @@ -0,0 +1,32 @@ +package com.aurellem.capture.audio; + +import java.nio.ByteBuffer; + +/** + * Method of Combination for sound processors. This SoundProcessor will + * run the methods of each of its constituent SoundProcessors in the order + * in which it was constructed. + * + * @author Robert McIntyre + * + */ +public class CompositeSoundProcessor implements SoundProcessor{ + + SoundProcessor[] processors; + + public CompositeSoundProcessor(SoundProcessor...processors){ + this.processors = processors; + } + + public void process(ByteBuffer audioSamples, int numSamples) { + for (SoundProcessor sp : processors){ + sp.process(audioSamples, numSamples); + } + } + + public void cleanup() { + for (SoundProcessor sp : processors){ + sp.cleanup(); + } + } +} diff -r 2543c95a0fd2 -r 4de7988407ef src/com/aurellem/capture/examples/AdvancedAudio.java --- a/src/com/aurellem/capture/examples/AdvancedAudio.java Sat Oct 29 14:39:19 2011 -0700 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java Sat Oct 29 15:16:06 2011 -0700 @@ -7,7 +7,6 @@ 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; @@ -73,6 +72,58 @@ private Geometry bell; + + private Vector3f[] path = new Vector3f[]{ + // loop 1 + new Vector3f(0, 0, 0), + new Vector3f(0, 0, -10), + new Vector3f(-2, 0, -14), + new Vector3f(-6, 0, -20), + new Vector3f(0, 0, -26), + new Vector3f(6, 0, -20), + new Vector3f(0, 0, -14), + new Vector3f(-6, 0, -20), + new Vector3f(0, 0, -26), + new Vector3f(6, 0, -20), + // loop 2 + new Vector3f(5, 0, -5), + new Vector3f(7, 0, 1.5f), + new Vector3f(14, 0, 2), + new Vector3f(20, 0, 6), + new Vector3f(26, 0, 0), + new Vector3f(20, 0, -6), + new Vector3f(14, 0, 0), + new Vector3f(20, 0, 6), + new Vector3f(26, 0, 0), + new Vector3f(20, 0, -6), + new Vector3f(14, 0, 0), + // loop 3 + new Vector3f(8, 0, 7.5f), + new Vector3f(7, 0, 10.5f), + new Vector3f(6, 0, 20), + new Vector3f(0, 0, 26), + new Vector3f(-6, 0, 20), + new Vector3f(0, 0, 14), + new Vector3f(6, 0, 20), + new Vector3f(0, 0, 26), + new Vector3f(-6, 0, 20), + new Vector3f(0, 0, 14), + // begin ellipse + new Vector3f(16, 5, 20), + new Vector3f(0, 0, 26), + new Vector3f(-16, -10, 20), + new Vector3f(0, 0, 14), + new Vector3f(16, 20, 20), + new Vector3f(0, 0, 26), + new Vector3f(-10, -25, 10), + new Vector3f(-10, 0, 0), + // come at me bro! + new Vector3f(-28.00242f, 48.005623f, -34.648228f), + new Vector3f(0, 0 , -20), + }; + + + private void createScene() { Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); bell = new Geometry( "sound-emitter" , new Sphere(15,15,1)); @@ -90,75 +141,24 @@ makeEar(rootNode, new Vector3f(20, 0 ,0)); makeEar(rootNode, new Vector3f(-20, 0 ,0)); - MotionPath path = new MotionPath(); + MotionPath track = new MotionPath(); - // loop 1 - path.addWayPoint(new Vector3f(0, 0, 0)); - path.addWayPoint(new Vector3f(0, 0, -10)); - path.addWayPoint(new Vector3f(-2, 0, -14)); - path.addWayPoint(new Vector3f(-6, 0, -20)); - path.addWayPoint(new Vector3f(0, 0, -26)); - path.addWayPoint(new Vector3f(6, 0, -20)); - path.addWayPoint(new Vector3f(0, 0, -14)); - path.addWayPoint(new Vector3f(-6, 0, -20)); - path.addWayPoint(new Vector3f(0, 0, -26)); - path.addWayPoint(new Vector3f(6, 0, -20)); - - - // loop 2 - path.addWayPoint(new Vector3f(5, 0, -5)); - path.addWayPoint(new Vector3f(7, 0, 1.5f)); - path.addWayPoint(new Vector3f(14, 0, 2)); - path.addWayPoint(new Vector3f(20, 0, 6)); - path.addWayPoint(new Vector3f(26, 0, 0)); - path.addWayPoint(new Vector3f(20, 0, -6)); - path.addWayPoint(new Vector3f(14, 0, 0)); - path.addWayPoint(new Vector3f(20, 0, 6)); - path.addWayPoint(new Vector3f(26, 0, 0)); - path.addWayPoint(new Vector3f(20, 0, -6)); - path.addWayPoint(new Vector3f(14, 0, 0)); - - - - // loop 3 - path.addWayPoint(new Vector3f(8, 0, 7.5f)); - path.addWayPoint(new Vector3f(7, 0, 10.5f)); - path.addWayPoint(new Vector3f(6, 0, 20)); - path.addWayPoint(new Vector3f(0, 0, 26)); - path.addWayPoint(new Vector3f(-6, 0, 20)); - path.addWayPoint(new Vector3f(0, 0, 14)); - path.addWayPoint(new Vector3f(6, 0, 20)); - path.addWayPoint(new Vector3f(0, 0, 26)); - path.addWayPoint(new Vector3f(-6, 0, 20)); - path.addWayPoint(new Vector3f(0, 0, 14)); - - - // begin elipse - - path.addWayPoint(new Vector3f(16, 5, 20)); - path.addWayPoint(new Vector3f(0, 0, 26)); - path.addWayPoint(new Vector3f(-16, -10, 20)); - path.addWayPoint(new Vector3f(0, 0, 14)); - path.addWayPoint(new Vector3f(16, 20, 20)); - path.addWayPoint(new Vector3f(0, 0, 26)); - path.addWayPoint(new Vector3f(-10, -25, 10)); - path.addWayPoint(new Vector3f(-10, 0, 0)); - - // 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); + for (Vector3f v : path){ + track.addWayPoint(v); + } + + + track.setCurveTension(0.80f); - motionControl = new MotionTrack(bell,path); + motionControl = new MotionTrack(bell,track); motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation); motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y)); motionControl.setInitialDuration(10f); motionControl.setSpeed(0.1f); - path.enableDebugShape(assetManager, rootNode); + track.enableDebugShape(assetManager, rootNode); positionCamera(); @@ -168,22 +168,43 @@ 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)); + // cam.setLocation(new Vector3f(0,0,-20)); this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f)); } - - - - private AudioNode music; + + + + private void initAudio() { + + music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false); + + 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); + + } + + + + private Listener auxListener = new Listener(); public File data1 = new File("/home/r/tmp/data1.wav"); public File data2 = new File("/home/r/tmp/data2.wav"); public File data3 = new File("/home/r/tmp/data3.wav"); - + public File data4 = new File("/home/r/tmp/data4.wav"); + public File data5 = new File("/home/r/tmp/data5.wav"); + public File data6 = new File("/home/r/tmp/data6.wav"); public void simpleInitApp() { @@ -202,57 +223,16 @@ rf.registerSoundProcessor(new WaveFileWriter(data1)); rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2)); rf.registerSoundProcessor(listener3, new WaveFileWriter(data3)); - } - - - - - - + } initAudio(); initKeys(); createScene(); - - motionControl.play(); - - //this.audioRenderer.playSource(music); - - - } - /** We create two audio nodes. */ - private void initAudio() { - //audioRenderer.setEnvironment(Environment.Cavern); - - music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false); - - //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 - * mapping it to a trigger (mouse click). */ - - /** Defining the "Shoot" action: Play a gun sound. */ private void initKeys() { inputManager.addMapping("Shoot", new MouseButtonTrigger(0)); @@ -275,7 +255,9 @@ }; /** Move the listener with the camera - for 3D audio. */ - @Override + + + private Vector3f prevBellPos = Vector3f.ZERO; public void simpleUpdate(float tpf) { //Vector3f loc = cam.getLocation(); //Quaternion rot = cam.getRotation(); @@ -293,7 +275,11 @@ //} //audioRenderer.updateSourceParam(music, AudioParam.Direction); + Vector3f bellVelocity = bell.getLocalTranslation().subtract(prevBellPos).mult(1.0f/tpf); + prevBellPos = bell.getLocalTranslation(); + music.setLocalTranslation(bell.getLocalTranslation()); + music.setVelocity(bellVelocity); //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);