# HG changeset patch # User Robert McIntyre # Date 1320008236 25200 # Node ID c4bfbf5d090eff57887838bc4da035853f21730a # Parent b67ffa8aa0b953ecfe54497540a36571a2370ae3 starting to get something that can percieve sound diff -r b67ffa8aa0b9 -r c4bfbf5d090e build.xml --- a/build.xml Sun Oct 30 10:17:09 2011 -0700 +++ b/build.xml Sun Oct 30 13:57:16 2011 -0700 @@ -20,7 +20,7 @@ - + diff -r b67ffa8aa0b9 -r c4bfbf5d090e src/com/aurellem/capture/audio/WaveFileWriter.java --- a/src/com/aurellem/capture/audio/WaveFileWriter.java Sun Oct 30 10:17:09 2011 -0700 +++ b/src/com/aurellem/capture/audio/WaveFileWriter.java Sun Oct 30 13:57:16 2011 -0700 @@ -32,7 +32,7 @@ } public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) { - + audioSamples.clear(); if (!initialized){ init(format); initialized = true; diff -r b67ffa8aa0b9 -r c4bfbf5d090e src/com/aurellem/capture/examples/AdvancedAudio.java --- a/src/com/aurellem/capture/examples/AdvancedAudio.java Sun Oct 30 10:17:09 2011 -0700 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java Sun Oct 30 13:57:16 2011 -0700 @@ -1,13 +1,20 @@ package com.aurellem.capture.examples; import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; import java.nio.ByteBuffer; import javax.sound.sampled.AudioFormat; +import org.tritonus.share.sampled.FloatSampleTools; + +import com.aurellem.capture.Capture; import com.aurellem.capture.IsoTimer; +import com.aurellem.capture.audio.CompositeSoundProcessor; import com.aurellem.capture.audio.MultiListener; import com.aurellem.capture.audio.SoundProcessor; +import com.aurellem.capture.audio.WaveFileWriter; import com.jme3.app.SimpleApplication; import com.jme3.audio.AudioNode; import com.jme3.audio.Listener; @@ -59,6 +66,8 @@ app.setShowSettings(false); app.setPauseOnLostFocus(false); org.lwjgl.input.Mouse.setGrabbed(false); + try {Capture.captureVideo(app, new File("/home/r/tmp/out.avi"));} + catch (IOException e) {e.printStackTrace();} app.start(); } @@ -162,10 +171,11 @@ motionControl = new MotionTrack(bell,track); + motionControl.setTimer(new IsoTimer(60)); motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation); motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y)); - motionControl.setInitialDuration(10f); - motionControl.setSpeed(0.1f); + motionControl.setInitialDuration(20f); + motionControl.setSpeed(1f); track.enableDebugShape(assetManager, rootNode); @@ -195,12 +205,12 @@ rootNode.attachChild(music); audioRenderer.playSource(music); + music.setPositional(true); + //music.setVolume(1f); - music.setVolume(1f); - music.setPositional(true); - music.setMaxDistance(200.0f); - music.setRefDistance(0.1f); - music.setRolloffFactor(5f); + //music.setMaxDistance(200.0f); + //music.setRefDistance(0.1f); + //music.setRolloffFactor(5f); audioRenderer.pauseSource(music); } @@ -222,9 +232,10 @@ Spatial entity; float scale = 2; - - public Dancer(Spatial entity){ + String debug; + public Dancer(Spatial entity, String debug){ this.entity = entity; + this.debug = debug; } /** @@ -238,10 +249,24 @@ * hears it's surroundings and reacts to them. */ public void process(ByteBuffer audioSamples, int numSamples, AudioFormat format) { - //System.out.println("I'm DANCING <3"); - entity.scale(this.scale); - if (this.scale == 2f){this.scale = 0.5f;} - else {this.scale = 2;} + audioSamples.clear(); + byte[] data = new byte[numSamples]; + float[] out = new float[numSamples]; + audioSamples.get(data); + FloatSampleTools.byte2floatInterleaved(data, 0, out, 0, + numSamples/format.getFrameSize(), format); + + float max = Float.NEGATIVE_INFINITY; + for (float f : out){if (f > max) max = f;} + + System.out.println(debug); + System.out.println(max); + + + + //entity.scale(this.scale); + //if (this.scale == 2f){this.scale = 0.5f;} + //else {this.scale = 2;} } @@ -260,10 +285,21 @@ rf.addListener(auxListener); + WaveFileWriter writer = null; + WaveFileWriter writer2 = null; + auxListener.setLocation(ear1.getLocalTranslation()); + listener.setLocation(ear1.getLocalTranslation()); + try {writer = new WaveFileWriter(new File("/home/r/tmp/out.wav"));} + catch (FileNotFoundException e) {e.printStackTrace();} - //rf.registerSoundProcessor(new WaveFileWriter(data1)); - rf.registerSoundProcessor(auxListener, new Dancer(ear1)); + try {writer2 = new WaveFileWriter(new File("/home/r/tmp/outmain.wav"));} + catch (FileNotFoundException e) {e.printStackTrace();} + + rf.registerSoundProcessor(auxListener, + new CompositeSoundProcessor(new Dancer(ear1, "aux"), writer)); + rf.registerSoundProcessor( + new CompositeSoundProcessor(new Dancer(ear1, "main"), writer2)); } motionControl.play(); @@ -285,7 +321,7 @@ if (name.equals("Shoot") && !keyPressed) { System.out.println("I'm playing! <3"); System.out.println(bell.getLocalTranslation().subtract(cam.getLocation()).length()); - + bell.getMaterial().setColor("Color", ColorRGBA.randomColor()); audioRenderer.playSource(music); System.out.println(music.getRefDistance()); @@ -297,6 +333,8 @@ private Vector3f prevBellPos = Vector3f.ZERO; + + public void simpleUpdate(float tpf) { //Vector3f loc = cam.getLocation(); //Quaternion rot = cam.getRotation(); @@ -304,14 +342,14 @@ //listener.setRotation(rot); - listener.setLocation(cam.getLocation()); - listener.setRotation(cam.getRotation()); + //listener.setLocation(cam.getLocation()); + //listener.setRotation(cam.getRotation()); //auxListener.setLocation(loc); //auxListener.setRotation(rot); - //if (music.getStatus() == AudioNode.Status.Stopped){ - - //music.playInstance(); - //} + if (music.getStatus() != AudioNode.Status.Playing){ + audioRenderer.playSource(music); + bell.getMaterial().setColor("Color", ColorRGBA.randomColor()); + } //audioRenderer.updateSourceParam(music, AudioParam.Direction); Vector3f bellVelocity = bell.getLocalTranslation().subtract(prevBellPos).mult(1.0f/tpf);