# HG changeset patch # User Robert McIntyre # Date 1319777751 25200 # Node ID e299cd89074d40df5cf05672b9352169ce6c3afc # Parent 6dc62c7866c25421d84e38ea5e59921c6c929544 creating Advanced Audio documentation. diff -r 6dc62c7866c2 -r e299cd89074d build.xml --- a/build.xml Thu Oct 27 21:08:17 2011 -0700 +++ b/build.xml Thu Oct 27 21:55:51 2011 -0700 @@ -7,10 +7,16 @@ - + + + + + + - - + + + diff -r 6dc62c7866c2 -r e299cd89074d src/com/aurellem/capture/examples/AdvancedAudio.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java Thu Oct 27 21:55:51 2011 -0700 @@ -0,0 +1,163 @@ +package com.aurellem.capture.examples; + +import java.io.File; + +import com.aurellem.capture.IsoTimer; +import com.aurellem.capture.audio.MultiListener; +import com.aurellem.capture.audio.WaveFileWriter; +import com.jme3.app.SimpleApplication; +import com.jme3.audio.AudioNode; +import com.jme3.audio.Listener; +import com.jme3.input.controls.ActionListener; +import com.jme3.input.controls.MouseButtonTrigger; +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Quaternion; +import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.shape.Box; +import com.jme3.system.AppSettings; + + +/** + * + * Demonstrates advanced use of the audio capture and recording features. + * Multiple perspectives of the same scene are simultaneously rendered to + * different sound files. + * + * A key limitation of the way multiple listeners are implemented is that + * only 3D positioning effects are realized for listeners other than the + * main LWJGL listener. This means that audio effects such as environment + * settings will *not* be heard on any auxiliary listeners, though sound + * attenuation will work correctly. + * + * Multiple listeners as realized here might be used to make AI entities + * that can each hear the world from their own perspective. + * + * @author Robert McIntyre + * + */ + +public class AdvancedAudio extends SimpleApplication { + + public static void main(String[] args) { + + AdvancedAudio app = new AdvancedAudio(); + AppSettings settings = new AppSettings(true); + + settings.setAudioRenderer("Send"); + app.setSettings(settings); + app.setShowSettings(false); + app.start(); + app.setPauseOnLostFocus(false); + } + + private AudioNode audio_gun; + private AudioNode audio_nature; + private Geometry player; + 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"); + + private File makeTarget(int n){ + return new File("/home/r/tmp/assload-" + n + ".wav"); + } + + + @Override + public void simpleInitApp() { + this.setTimer(new IsoTimer(60)); + + + if (this.audioRenderer instanceof MultiListener){ + MultiListener rf = (MultiListener)this.audioRenderer; + + for (int n = 0; n < 0; n++){ + Listener zzz = new Listener(); + rf.addListener(zzz); + rf.registerSoundProcessor( + zzz, new WaveFileWriter(makeTarget(n))); + } + Listener listener3 = new Listener(); + rf.addListener(auxListener); + rf.addListener(listener3); + rf.registerSoundProcessor(new WaveFileWriter(data1)); + rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2)); + rf.registerSoundProcessor(listener3, new WaveFileWriter(data3)); + } + flyCam.setMoveSpeed(40); + + /** just a blue box floating in space */ + Box box1 = new Box(Vector3f.ZERO, 1, 1, 1); + player = new Geometry("Player", box1); + Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); + mat1.setColor("Color", ColorRGBA.Blue); + player.setMaterial(mat1); + rootNode.attachChild(player); + + /** custom init methods, see below */ + initKeys(); + initAudio(); + + this.audioRenderer.playSource(audio_gun); + + + + } + + /** We create two audio nodes. */ + private void initAudio() { + //audioRenderer.setEnvironment(Environment.Cavern); + /* gun shot sound is to be triggered by a mouse click. */ + audio_gun = new AudioNode(assetManager, "Sound/Effects/Gun.wav", false); + //audio_gun = new AudioNode(assetManager, "Sound/Effects/dream.wav", false, false); + audio_gun.setLooping(false); + audio_gun.setVolume(2); + audio_gun.setPositional(true); + + + /* nature sound - keeps playing in a loop. */ + audio_nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", false, false); + audio_nature.setLooping(true); + audio_nature.setPositional(true); + audio_nature.setLocalTranslation(Vector3f.ZERO.clone()); + audio_nature.setVolume(3); + audio_nature.updateGeometricState(); + } + + /** Declaring the "Shoot" action, and + * mapping it to a trigger (mouse click). */ + 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) { + audioRenderer.playSource(audio_gun); // play once! + } + } + }; + + /** 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); + if (audio_gun.getStatus() == AudioNode.Status.Stopped){ + System.out.println("I'm Stopped!"); + this.requestClose(false); + } + + + } + +} diff -r 6dc62c7866c2 -r e299cd89074d src/com/aurellem/capture/examples/AdvancedVideo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/aurellem/capture/examples/AdvancedVideo.java Thu Oct 27 21:55:51 2011 -0700 @@ -0,0 +1,75 @@ +package com.aurellem.capture.examples; + +import java.io.File; +import java.io.IOException; + +import com.aurellem.capture.Capture; +import com.aurellem.capture.IsoTimer; +import com.aurellem.capture.video.AbstractVideoRecorder; +import com.jme3.app.SimpleApplication; +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.shape.Box; + +/** Recording Video from an application suitable for upload to youtube.*/ +public class AdvancedVideo extends SimpleApplication { + + /*File staticVideo = + new File("/home/r/bullshit.avi"); + */ + File movingVideo = + new File("/home/r/tmp/bullshit2.flv"); + + AbstractVideoRecorder movingRecorder ; + + public static void main(String[] args){ + AdvancedVideo app = new AdvancedVideo(); + app.start(); + } + + public void initVideo(){ + this.setTimer(new IsoTimer(60)); + /*try{ + // set the timer to 30fps lock-step + this.setTimer(new IsoTimer(30)); + + //ViewPort compositeViewPort = renderManager.createFinalView("composite", cam); + //compositeViewPort.attachScene(this.rootNode); + //compositeViewPort.attachScene(this.guiNode); + this.viewPort.setClearFlags(true, true, true); + this.viewPort.setBackgroundColor(ColorRGBA.Black); + movingRecorder = new AVIVideoRecorder(movingVideo); + this.stateManager.attach(movingRecorder); + this.viewPort.addFinalProcessor(movingRecorder); + this.viewPort.attachScene(this.guiNode); + + }catch (IOException e) { + e.printStackTrace();} + */ + try {Capture.captureVideo(this, movingVideo);} + catch (IOException e) {e.printStackTrace();} + + } + protected Geometry player; + + public void simpleInitApp() { + initVideo(); // begin recording! + /** this blue box is our player character */ + Box b = new Box(Vector3f.ZERO, 1, 1, 1); + player = new Geometry("blue cube", b); + Material mat = new Material(assetManager, + "Common/MatDefs/Misc/Unshaded.j3md"); + mat.setColor("Color", ColorRGBA.Blue); + player.setMaterial(mat); + rootNode.attachChild(player); + } + + /* Use the main event loop to trigger repeating actions. */ + public void simpleUpdate(float tpf) { + // make the player rotate: + player.rotate(0, 2*tpf, 0); + } + +} \ No newline at end of file diff -r 6dc62c7866c2 -r e299cd89074d src/com/aurellem/capture/examples/Basic.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/aurellem/capture/examples/Basic.java Thu Oct 27 21:55:51 2011 -0700 @@ -0,0 +1,84 @@ +package com.aurellem.capture.examples; + +import java.io.File; +import java.io.IOException; + +import jme3test.helloworld.HelloAudio; +import jme3test.helloworld.HelloJME3; +import jme3test.niftygui.TestNiftyExamples; +import jme3test.water.TestPostWater; + +import com.aurellem.capture.Capture; +import com.aurellem.capture.IsoTimer; +import com.jme3.app.SimpleApplication; + + +/** + * + * Demonstrates how to use basic Audio/Video capture with a jMonkeyEngine + * application. You can use these techniques to make high quality cutscenes + * or demo videos, even on very slow laptops. + * + * @author Robert McIntyre + * + */ + +public class Basic { + + public static void basicVideo() throws IOException{ + File video = File.createTempFile("HelloJME3", ".avi"); + System.out.println("Saving video to: " + video.getCanonicalPath()); + SimpleApplication app = new HelloJME3(); + app.setTimer(new IsoTimer(60)); + app.setShowSettings(false); + + Capture.captureVideo(app, video); + app.start(); + } + + public static void basicVideoGUI() throws IOException { + File video = File.createTempFile("GUI", ".avi"); + System.out.println("Saving video to: " + video.getCanonicalPath()); + SimpleApplication app = new TestNiftyExamples(); + app.setTimer(new IsoTimer(60)); + app.setShowSettings(false); + + Capture.captureVideo(app, video); + app.start(); + } + + public static void basicAudio() throws IOException{ + File audio = File.createTempFile("BasicAudio", ".wav"); + System.out.println("Saving audio to: " + audio.getCanonicalPath()); + SimpleApplication app = new HelloAudio(); + app.setTimer(new IsoTimer(60)); + app.setShowSettings(false); + + // you will not hear the audio while it is being captured. + Capture.captureAudio(app, audio); + + app.start(); + } + + public static void basicAudioVideo() throws IOException{ + File video = new File("/home/r/tmp/basicVideo.avi"); + File audio = new File("/home/r/tmp/basicAudio.wav"); + + SimpleApplication app = new TestPostWater(); + app.setTimer(new IsoTimer(60)); + app.setShowSettings(false); + + Capture.captureVideo(app, video); + Capture.captureAudio(app, audio); + + app.start(); + } + + + public static void main(String[] ignore) throws IOException{ + basicVideo(); + basicVideoGUI(); + basicAudio(); + basicAudioVideo(); + } +} diff -r 6dc62c7866c2 -r e299cd89074d src/com/aurellem/capture/hello/AdvancedAudio.java --- a/src/com/aurellem/capture/hello/AdvancedAudio.java Thu Oct 27 21:08:17 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,158 +0,0 @@ -package com.aurellem.capture.hello; - -import java.io.File; - -import com.aurellem.capture.IsoTimer; -import com.aurellem.capture.audio.MultiListener; -import com.aurellem.capture.audio.WaveFileWriter; -import com.jme3.app.SimpleApplication; -import com.jme3.audio.AudioNode; -import com.jme3.audio.Listener; -import com.jme3.input.controls.ActionListener; -import com.jme3.input.controls.MouseButtonTrigger; -import com.jme3.material.Material; -import com.jme3.math.ColorRGBA; -import com.jme3.math.Quaternion; -import com.jme3.math.Vector3f; -import com.jme3.scene.Geometry; -import com.jme3.scene.shape.Box; -import com.jme3.system.AppSettings; - - -/** - * - * - * - * @author Robert McIntyre - * - */ - -public class AdvancedAudio extends SimpleApplication { - - - - public static void main(String[] args) { - - // Logger.getLogger("com.jme3").setLevel(Level.OFF); - - AdvancedAudio app = new AdvancedAudio(); - AppSettings settings = new AppSettings(true); - - settings.setAudioRenderer("Send"); - app.setSettings(settings); - app.setShowSettings(false); - app.start(); - app.setPauseOnLostFocus(false); - } - - - - private AudioNode audio_gun; - private AudioNode audio_nature; - private Geometry player; - 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"); - - private File makeTarget(int n){ - return new File("/home/r/tmp/assload-" + n + ".wav"); - } - - - @Override - public void simpleInitApp() { - this.setTimer(new IsoTimer(60)); - - - if (this.audioRenderer instanceof MultiListener){ - MultiListener rf = (MultiListener)this.audioRenderer; - - for (int n = 0; n < 0; n++){ - Listener zzz = new Listener(); - rf.addListener(zzz); - rf.registerSoundProcessor( - zzz, new WaveFileWriter(makeTarget(n))); - } - Listener listener3 = new Listener(); - rf.addListener(auxListener); - rf.addListener(listener3); - rf.registerSoundProcessor(new WaveFileWriter(data1)); - rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2)); - rf.registerSoundProcessor(listener3, new WaveFileWriter(data3)); - } - flyCam.setMoveSpeed(40); - - /** just a blue box floating in space */ - Box box1 = new Box(Vector3f.ZERO, 1, 1, 1); - player = new Geometry("Player", box1); - Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); - mat1.setColor("Color", ColorRGBA.Blue); - player.setMaterial(mat1); - rootNode.attachChild(player); - - /** custom init methods, see below */ - initKeys(); - initAudio(); - - this.audioRenderer.playSource(audio_gun); - - - - } - - /** We create two audio nodes. */ - private void initAudio() { - //audioRenderer.setEnvironment(Environment.Cavern); - /* gun shot sound is to be triggered by a mouse click. */ - audio_gun = new AudioNode(assetManager, "Sound/Effects/Gun.wav", false); - //audio_gun = new AudioNode(assetManager, "Sound/Effects/dream.wav", false, false); - audio_gun.setLooping(false); - audio_gun.setVolume(2); - audio_gun.setPositional(true); - - - /* nature sound - keeps playing in a loop. */ - audio_nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", false, false); - audio_nature.setLooping(true); - audio_nature.setPositional(true); - audio_nature.setLocalTranslation(Vector3f.ZERO.clone()); - audio_nature.setVolume(3); - audio_nature.updateGeometricState(); - } - - /** Declaring the "Shoot" action, and - * mapping it to a trigger (mouse click). */ - 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) { - audioRenderer.playSource(audio_gun); // play once! - } - } - }; - - /** 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); - if (audio_gun.getStatus() == AudioNode.Status.Stopped){ - System.out.println("I'm Stopped!"); - this.requestClose(false); - } - - - } - -} diff -r 6dc62c7866c2 -r e299cd89074d src/com/aurellem/capture/hello/BasicAVRecord.java --- a/src/com/aurellem/capture/hello/BasicAVRecord.java Thu Oct 27 21:08:17 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -package com.aurellem.capture.hello; - -import java.io.File; -import java.io.IOException; - -import jme3test.helloworld.HelloAudio; -import jme3test.helloworld.HelloJME3; -import jme3test.niftygui.TestNiftyExamples; -import jme3test.water.TestPostWater; - -import com.aurellem.capture.Capture; -import com.aurellem.capture.IsoTimer; -import com.jme3.app.SimpleApplication; - - -/** - * - * Demonstrates how to use basic Audio/Video capture with a jMonkeyEngine - * application. - * - * @author Robert McIntyre - * - */ - -public class BasicAVRecord { - - public static void basicVideo() throws IOException{ - File video = File.createTempFile("HelloJME3", ".avi"); - System.out.println("Saving video to: " + video.getCanonicalPath()); - SimpleApplication app = new HelloJME3(); - app.setTimer(new IsoTimer(60)); - - Capture.captureVideo(app, video); - app.start(); - } - - public static void basicVideoGUI() throws IOException { - File video = File.createTempFile("GUI", ".avi"); - System.out.println("Saving video to: " + video.getCanonicalPath()); - SimpleApplication app = new TestNiftyExamples(); - app.setTimer(new IsoTimer(60)); - - Capture.captureVideo(app, video); - app.start(); - } - - public static void basicAudio() throws IOException{ - File audio = File.createTempFile("BasicAudio", ".wav"); - System.out.println("Saving audio to: " + audio.getCanonicalPath()); - SimpleApplication app = new HelloAudio(); - app.setTimer(new IsoTimer(60)); - - // you will not hear the audio while it is being captured. - Capture.captureAudio(app, audio); - - app.start(); - } - - public static void basicAudioVideo() throws IOException{ - File video = new File("/home/r/tmp/basicVideo.avi"); - File audio = new File("/home/r/tmp/basicAudio.wav"); - - SimpleApplication app = new TestPostWater(); - app.setTimer(new IsoTimer(60)); - - Capture.captureVideo(app, video); - Capture.captureAudio(app, audio); - - app.start(); - } - - - public static void main(String[] ignore) throws IOException{ - basicAudio(); - } -} diff -r 6dc62c7866c2 -r e299cd89074d src/com/aurellem/capture/hello/HelloVideo.java --- a/src/com/aurellem/capture/hello/HelloVideo.java Thu Oct 27 21:08:17 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -package com.aurellem.capture.hello; - -import java.io.File; -import java.io.IOException; - -import com.aurellem.capture.Capture; -import com.aurellem.capture.IsoTimer; -import com.aurellem.capture.video.AbstractVideoRecorder; -import com.jme3.app.SimpleApplication; -import com.jme3.material.Material; -import com.jme3.math.ColorRGBA; -import com.jme3.math.Vector3f; -import com.jme3.scene.Geometry; -import com.jme3.scene.shape.Box; - -/** Recording Video from an application suitable for upload to youtube.*/ -public class HelloVideo extends SimpleApplication { - - /*File staticVideo = - new File("/home/r/bullshit.avi"); - */ - File movingVideo = - new File("/home/r/tmp/bullshit2.flv"); - - AbstractVideoRecorder movingRecorder ; - - public static void main(String[] args){ - HelloVideo app = new HelloVideo(); - app.start(); - } - - public void initVideo(){ - this.setTimer(new IsoTimer(60)); - /*try{ - // set the timer to 30fps lock-step - this.setTimer(new IsoTimer(30)); - - //ViewPort compositeViewPort = renderManager.createFinalView("composite", cam); - //compositeViewPort.attachScene(this.rootNode); - //compositeViewPort.attachScene(this.guiNode); - this.viewPort.setClearFlags(true, true, true); - this.viewPort.setBackgroundColor(ColorRGBA.Black); - movingRecorder = new AVIVideoRecorder(movingVideo); - this.stateManager.attach(movingRecorder); - this.viewPort.addFinalProcessor(movingRecorder); - this.viewPort.attachScene(this.guiNode); - - }catch (IOException e) { - e.printStackTrace();} - */ - try {Capture.captureVideo(this, movingVideo);} - catch (IOException e) {e.printStackTrace();} - - } - protected Geometry player; - - public void simpleInitApp() { - initVideo(); // begin recording! - /** this blue box is our player character */ - Box b = new Box(Vector3f.ZERO, 1, 1, 1); - player = new Geometry("blue cube", b); - Material mat = new Material(assetManager, - "Common/MatDefs/Misc/Unshaded.j3md"); - mat.setColor("Color", ColorRGBA.Blue); - player.setMaterial(mat); - rootNode.attachChild(player); - } - - /* Use the main event loop to trigger repeating actions. */ - public void simpleUpdate(float tpf) { - // make the player rotate: - player.rotate(0, 2*tpf, 0); - } - -} \ No newline at end of file