rlm@14: package com.aurellem.capture.examples; rlm@14: rlm@14: import java.io.File; rlm@14: rlm@14: import com.aurellem.capture.IsoTimer; rlm@14: import com.aurellem.capture.audio.MultiListener; rlm@14: import com.aurellem.capture.audio.WaveFileWriter; rlm@14: import com.jme3.app.SimpleApplication; rlm@14: import com.jme3.audio.AudioNode; rlm@14: import com.jme3.audio.Listener; rlm@15: import com.jme3.cinematic.MotionPath; rlm@15: import com.jme3.cinematic.events.MotionTrack; rlm@15: import com.jme3.light.DirectionalLight; rlm@14: import com.jme3.material.Material; rlm@14: import com.jme3.math.ColorRGBA; rlm@15: import com.jme3.math.FastMath; rlm@14: import com.jme3.math.Quaternion; rlm@14: import com.jme3.math.Vector3f; rlm@14: import com.jme3.scene.Geometry; rlm@15: import com.jme3.scene.Node; rlm@14: import com.jme3.scene.shape.Box; rlm@15: import com.jme3.scene.shape.Sphere; rlm@14: import com.jme3.system.AppSettings; rlm@14: rlm@14: rlm@14: /** rlm@14: * rlm@14: * Demonstrates advanced use of the audio capture and recording features. rlm@14: * Multiple perspectives of the same scene are simultaneously rendered to rlm@14: * different sound files. rlm@14: * rlm@14: * A key limitation of the way multiple listeners are implemented is that rlm@14: * only 3D positioning effects are realized for listeners other than the rlm@14: * main LWJGL listener. This means that audio effects such as environment rlm@14: * settings will *not* be heard on any auxiliary listeners, though sound rlm@14: * attenuation will work correctly. rlm@14: * rlm@14: * Multiple listeners as realized here might be used to make AI entities rlm@14: * that can each hear the world from their own perspective. rlm@14: * rlm@14: * @author Robert McIntyre rlm@14: * rlm@14: */ rlm@14: rlm@14: public class AdvancedAudio extends SimpleApplication { rlm@15: rlm@15: public static void main(String[] args) { rlm@15: rlm@15: AdvancedAudio app = new AdvancedAudio(); rlm@15: AppSettings settings = new AppSettings(true); rlm@15: //settings.setAudioRenderer("Send"); rlm@15: app.setSettings(settings); rlm@15: app.setShowSettings(false); rlm@15: app.setPauseOnLostFocus(false); rlm@15: org.lwjgl.input.Mouse.setGrabbed(false); rlm@15: app.start(); rlm@15: } rlm@15: rlm@14: rlm@16: rlm@16: rlm@15: private MotionTrack motionControl; rlm@15: rlm@15: rlm@15: private void makeEar(Node root, Vector3f position){ rlm@15: Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); rlm@15: Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f)); rlm@15: ear.setLocalTranslation(position); rlm@15: mat.setColor("Color", ColorRGBA.Green); rlm@15: ear.setMaterial(mat); rlm@15: root.attachChild(ear); rlm@16: } rlm@15: rlm@17: private Geometry bell; rlm@17: rlm@15: private void createScene() { rlm@15: Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); rlm@17: bell = new Geometry( "sound-emitter" , new Sphere(15,15,1)); rlm@15: mat.setColor("Color", ColorRGBA.Blue); rlm@15: bell.setMaterial(mat); rlm@15: rootNode.attachChild(bell); rlm@15: rlm@15: DirectionalLight light = new DirectionalLight(); rlm@15: light.setDirection(new Vector3f(0, -1, 0).normalizeLocal()); rlm@15: light.setColor(ColorRGBA.White.mult(1.5f)); rlm@15: rootNode.addLight(light); rlm@15: rlm@15: makeEar(rootNode, new Vector3f(0, 0 ,20)); rlm@15: makeEar(rootNode, new Vector3f(0, 0 ,-20)); rlm@15: makeEar(rootNode, new Vector3f(20, 0 ,0)); rlm@15: makeEar(rootNode, new Vector3f(-20, 0 ,0)); rlm@15: rlm@15: MotionPath path = new MotionPath(); rlm@15: rlm@15: // loop 1 rlm@15: path.addWayPoint(new Vector3f(0, 0, 0)); rlm@15: path.addWayPoint(new Vector3f(0, 0, -10)); rlm@15: path.addWayPoint(new Vector3f(-2, 0, -14)); rlm@15: path.addWayPoint(new Vector3f(-6, 0, -20)); rlm@15: path.addWayPoint(new Vector3f(0, 0, -26)); rlm@15: path.addWayPoint(new Vector3f(6, 0, -20)); rlm@15: path.addWayPoint(new Vector3f(0, 0, -14)); rlm@15: path.addWayPoint(new Vector3f(-6, 0, -20)); rlm@15: path.addWayPoint(new Vector3f(0, 0, -26)); rlm@15: path.addWayPoint(new Vector3f(6, 0, -20)); rlm@15: rlm@15: rlm@15: // loop 2 rlm@15: path.addWayPoint(new Vector3f(5, 0, -5)); rlm@15: path.addWayPoint(new Vector3f(7, 0, 1.5f)); rlm@15: path.addWayPoint(new Vector3f(14, 0, 2)); rlm@15: path.addWayPoint(new Vector3f(20, 0, 6)); rlm@15: path.addWayPoint(new Vector3f(26, 0, 0)); rlm@15: path.addWayPoint(new Vector3f(20, 0, -6)); rlm@15: path.addWayPoint(new Vector3f(14, 0, 0)); rlm@15: path.addWayPoint(new Vector3f(20, 0, 6)); rlm@15: path.addWayPoint(new Vector3f(26, 0, 0)); rlm@15: path.addWayPoint(new Vector3f(20, 0, -6)); rlm@15: path.addWayPoint(new Vector3f(14, 0, 0)); rlm@15: rlm@15: rlm@15: rlm@15: // loop 3 rlm@15: path.addWayPoint(new Vector3f(8, 0, 7.5f)); rlm@15: path.addWayPoint(new Vector3f(7, 0, 10.5f)); rlm@15: path.addWayPoint(new Vector3f(6, 0, 20)); rlm@15: path.addWayPoint(new Vector3f(0, 0, 26)); rlm@15: path.addWayPoint(new Vector3f(-6, 0, 20)); rlm@15: path.addWayPoint(new Vector3f(0, 0, 14)); rlm@15: path.addWayPoint(new Vector3f(6, 0, 20)); rlm@15: path.addWayPoint(new Vector3f(0, 0, 26)); rlm@15: path.addWayPoint(new Vector3f(-6, 0, 20)); rlm@15: path.addWayPoint(new Vector3f(0, 0, 14)); rlm@15: rlm@15: rlm@15: // begin elipse rlm@15: rlm@15: path.addWayPoint(new Vector3f(16, 5, 20)); rlm@15: path.addWayPoint(new Vector3f(0, 0, 26)); rlm@15: path.addWayPoint(new Vector3f(-16, -10, 20)); rlm@15: path.addWayPoint(new Vector3f(0, 0, 14)); rlm@15: path.addWayPoint(new Vector3f(16, 20, 20)); rlm@15: path.addWayPoint(new Vector3f(0, 0, 26)); rlm@15: path.addWayPoint(new Vector3f(-10, -25, 10)); rlm@15: path.addWayPoint(new Vector3f(-10, 0, 0)); rlm@15: rlm@15: // come at me bro! rlm@15: path.addWayPoint(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); rlm@15: path.setCurveTension(0.80f); rlm@15: rlm@15: rlm@15: motionControl = new MotionTrack(bell,path); rlm@15: motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation); rlm@15: motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y)); rlm@15: motionControl.setInitialDuration(10f); rlm@15: motionControl.setSpeed(0.1f); rlm@15: rlm@15: rlm@15: //path.enableDebugShape(assetManager, rootNode); rlm@15: rlm@15: rlm@15: positionCamera(); rlm@15: rlm@15: rlm@15: } rlm@15: rlm@15: rlm@15: private void positionCamera(){ rlm@15: this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); rlm@15: this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f)); rlm@15: rlm@15: rlm@15: } rlm@15: rlm@15: rlm@15: rlm@15: rlm@14: rlm@17: private AudioNode music; rlm@17: rlm@17: rlm@14: private Listener auxListener = new Listener(); rlm@14: public File data1 = new File("/home/r/tmp/data1.wav"); rlm@14: public File data2 = new File("/home/r/tmp/data2.wav"); rlm@14: public File data3 = new File("/home/r/tmp/data3.wav"); rlm@14: rlm@14: rlm@14: @Override rlm@14: public void simpleInitApp() { rlm@17: this.setTimer(new IsoTimer(60)); rlm@14: rlm@14: if (this.audioRenderer instanceof MultiListener){ rlm@14: MultiListener rf = (MultiListener)this.audioRenderer; rlm@14: rlm@14: for (int n = 0; n < 0; n++){ rlm@14: Listener zzz = new Listener(); rlm@14: rf.addListener(zzz); rlm@14: } rlm@14: Listener listener3 = new Listener(); rlm@14: rf.addListener(auxListener); rlm@14: rf.addListener(listener3); rlm@14: rf.registerSoundProcessor(new WaveFileWriter(data1)); rlm@14: rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2)); rlm@14: rf.registerSoundProcessor(listener3, new WaveFileWriter(data3)); rlm@14: } rlm@14: rlm@14: rlm@15: rlm@15: rlm@15: rlm@17: rlm@14: initAudio(); rlm@15: createScene(); rlm@15: rlm@15: rlm@15: motionControl.play(); rlm@14: rlm@17: this.audioRenderer.playSource(music); rlm@14: rlm@14: rlm@14: rlm@14: } rlm@14: rlm@14: /** We create two audio nodes. */ rlm@14: private void initAudio() { rlm@14: //audioRenderer.setEnvironment(Environment.Cavern); rlm@17: rlm@17: music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false); rlm@17: music.setLooping(true); rlm@17: music.setVolume(2); rlm@17: music.setRefDistance(0.1f); rlm@17: music.setMaxDistance(200); rlm@17: music.setPositional(true); rlm@14: } rlm@14: rlm@14: /** Declaring the "Shoot" action, and rlm@14: * mapping it to a trigger (mouse click). */ rlm@17: rlm@14: rlm@14: /** Defining the "Shoot" action: Play a gun sound. */ rlm@17: rlm@14: rlm@14: /** Move the listener with the camera - for 3D audio. */ rlm@14: @Override rlm@14: public void simpleUpdate(float tpf) { rlm@14: Vector3f loc = cam.getLocation(); rlm@14: Quaternion rot = cam.getRotation(); rlm@14: listener.setLocation(loc); rlm@14: listener.setRotation(rot); rlm@14: auxListener.setLocation(loc); rlm@14: auxListener.setRotation(rot); rlm@15: rlm@17: music.setLocalTranslation(bell.getLocalTranslation()); rlm@17: rlm@14: rlm@14: } rlm@14: rlm@14: }