Mercurial > jmeCapture
changeset 19:4de7988407ef
added CompositeSoundProcessor for combining SoundProcessors
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 29 Oct 2011 15:16:06 -0700 |
parents | 2543c95a0fd2 |
children | bc6fbfbbadd9 |
files | src/com/aurellem/capture/audio/CompositeSoundProcessor.java src/com/aurellem/capture/examples/AdvancedAudio.java |
diffstat | 2 files changed, 129 insertions(+), 111 deletions(-) [+] |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/com/aurellem/capture/audio/CompositeSoundProcessor.java Sat Oct 29 15:16:06 2011 -0700 1.3 @@ -0,0 +1,32 @@ 1.4 +package com.aurellem.capture.audio; 1.5 + 1.6 +import java.nio.ByteBuffer; 1.7 + 1.8 +/** 1.9 + * Method of Combination for sound processors. This SoundProcessor will 1.10 + * run the methods of each of its constituent SoundProcessors in the order 1.11 + * in which it was constructed. 1.12 + * 1.13 + * @author Robert McIntyre 1.14 + * 1.15 + */ 1.16 +public class CompositeSoundProcessor implements SoundProcessor{ 1.17 + 1.18 + SoundProcessor[] processors; 1.19 + 1.20 + public CompositeSoundProcessor(SoundProcessor...processors){ 1.21 + this.processors = processors; 1.22 + } 1.23 + 1.24 + public void process(ByteBuffer audioSamples, int numSamples) { 1.25 + for (SoundProcessor sp : processors){ 1.26 + sp.process(audioSamples, numSamples); 1.27 + } 1.28 + } 1.29 + 1.30 + public void cleanup() { 1.31 + for (SoundProcessor sp : processors){ 1.32 + sp.cleanup(); 1.33 + } 1.34 + } 1.35 +}
2.1 --- a/src/com/aurellem/capture/examples/AdvancedAudio.java Sat Oct 29 14:39:19 2011 -0700 2.2 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java Sat Oct 29 15:16:06 2011 -0700 2.3 @@ -7,7 +7,6 @@ 2.4 import com.aurellem.capture.audio.WaveFileWriter; 2.5 import com.jme3.app.SimpleApplication; 2.6 import com.jme3.audio.AudioNode; 2.7 -import com.jme3.audio.AudioParam; 2.8 import com.jme3.audio.Listener; 2.9 import com.jme3.cinematic.MotionPath; 2.10 import com.jme3.cinematic.events.MotionTrack; 2.11 @@ -73,6 +72,58 @@ 2.12 2.13 private Geometry bell; 2.14 2.15 + 2.16 + private Vector3f[] path = new Vector3f[]{ 2.17 + // loop 1 2.18 + new Vector3f(0, 0, 0), 2.19 + new Vector3f(0, 0, -10), 2.20 + new Vector3f(-2, 0, -14), 2.21 + new Vector3f(-6, 0, -20), 2.22 + new Vector3f(0, 0, -26), 2.23 + new Vector3f(6, 0, -20), 2.24 + new Vector3f(0, 0, -14), 2.25 + new Vector3f(-6, 0, -20), 2.26 + new Vector3f(0, 0, -26), 2.27 + new Vector3f(6, 0, -20), 2.28 + // loop 2 2.29 + new Vector3f(5, 0, -5), 2.30 + new Vector3f(7, 0, 1.5f), 2.31 + new Vector3f(14, 0, 2), 2.32 + new Vector3f(20, 0, 6), 2.33 + new Vector3f(26, 0, 0), 2.34 + new Vector3f(20, 0, -6), 2.35 + new Vector3f(14, 0, 0), 2.36 + new Vector3f(20, 0, 6), 2.37 + new Vector3f(26, 0, 0), 2.38 + new Vector3f(20, 0, -6), 2.39 + new Vector3f(14, 0, 0), 2.40 + // loop 3 2.41 + new Vector3f(8, 0, 7.5f), 2.42 + new Vector3f(7, 0, 10.5f), 2.43 + new Vector3f(6, 0, 20), 2.44 + new Vector3f(0, 0, 26), 2.45 + new Vector3f(-6, 0, 20), 2.46 + new Vector3f(0, 0, 14), 2.47 + new Vector3f(6, 0, 20), 2.48 + new Vector3f(0, 0, 26), 2.49 + new Vector3f(-6, 0, 20), 2.50 + new Vector3f(0, 0, 14), 2.51 + // begin ellipse 2.52 + new Vector3f(16, 5, 20), 2.53 + new Vector3f(0, 0, 26), 2.54 + new Vector3f(-16, -10, 20), 2.55 + new Vector3f(0, 0, 14), 2.56 + new Vector3f(16, 20, 20), 2.57 + new Vector3f(0, 0, 26), 2.58 + new Vector3f(-10, -25, 10), 2.59 + new Vector3f(-10, 0, 0), 2.60 + // come at me bro! 2.61 + new Vector3f(-28.00242f, 48.005623f, -34.648228f), 2.62 + new Vector3f(0, 0 , -20), 2.63 + }; 2.64 + 2.65 + 2.66 + 2.67 private void createScene() { 2.68 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 2.69 bell = new Geometry( "sound-emitter" , new Sphere(15,15,1)); 2.70 @@ -90,75 +141,24 @@ 2.71 makeEar(rootNode, new Vector3f(20, 0 ,0)); 2.72 makeEar(rootNode, new Vector3f(-20, 0 ,0)); 2.73 2.74 - MotionPath path = new MotionPath(); 2.75 + MotionPath track = new MotionPath(); 2.76 2.77 - // loop 1 2.78 - path.addWayPoint(new Vector3f(0, 0, 0)); 2.79 - path.addWayPoint(new Vector3f(0, 0, -10)); 2.80 - path.addWayPoint(new Vector3f(-2, 0, -14)); 2.81 - path.addWayPoint(new Vector3f(-6, 0, -20)); 2.82 - path.addWayPoint(new Vector3f(0, 0, -26)); 2.83 - path.addWayPoint(new Vector3f(6, 0, -20)); 2.84 - path.addWayPoint(new Vector3f(0, 0, -14)); 2.85 - path.addWayPoint(new Vector3f(-6, 0, -20)); 2.86 - path.addWayPoint(new Vector3f(0, 0, -26)); 2.87 - path.addWayPoint(new Vector3f(6, 0, -20)); 2.88 - 2.89 - 2.90 - // loop 2 2.91 - path.addWayPoint(new Vector3f(5, 0, -5)); 2.92 - path.addWayPoint(new Vector3f(7, 0, 1.5f)); 2.93 - path.addWayPoint(new Vector3f(14, 0, 2)); 2.94 - path.addWayPoint(new Vector3f(20, 0, 6)); 2.95 - path.addWayPoint(new Vector3f(26, 0, 0)); 2.96 - path.addWayPoint(new Vector3f(20, 0, -6)); 2.97 - path.addWayPoint(new Vector3f(14, 0, 0)); 2.98 - path.addWayPoint(new Vector3f(20, 0, 6)); 2.99 - path.addWayPoint(new Vector3f(26, 0, 0)); 2.100 - path.addWayPoint(new Vector3f(20, 0, -6)); 2.101 - path.addWayPoint(new Vector3f(14, 0, 0)); 2.102 - 2.103 - 2.104 - 2.105 - // loop 3 2.106 - path.addWayPoint(new Vector3f(8, 0, 7.5f)); 2.107 - path.addWayPoint(new Vector3f(7, 0, 10.5f)); 2.108 - path.addWayPoint(new Vector3f(6, 0, 20)); 2.109 - path.addWayPoint(new Vector3f(0, 0, 26)); 2.110 - path.addWayPoint(new Vector3f(-6, 0, 20)); 2.111 - path.addWayPoint(new Vector3f(0, 0, 14)); 2.112 - path.addWayPoint(new Vector3f(6, 0, 20)); 2.113 - path.addWayPoint(new Vector3f(0, 0, 26)); 2.114 - path.addWayPoint(new Vector3f(-6, 0, 20)); 2.115 - path.addWayPoint(new Vector3f(0, 0, 14)); 2.116 - 2.117 - 2.118 - // begin elipse 2.119 - 2.120 - path.addWayPoint(new Vector3f(16, 5, 20)); 2.121 - path.addWayPoint(new Vector3f(0, 0, 26)); 2.122 - path.addWayPoint(new Vector3f(-16, -10, 20)); 2.123 - path.addWayPoint(new Vector3f(0, 0, 14)); 2.124 - path.addWayPoint(new Vector3f(16, 20, 20)); 2.125 - path.addWayPoint(new Vector3f(0, 0, 26)); 2.126 - path.addWayPoint(new Vector3f(-10, -25, 10)); 2.127 - path.addWayPoint(new Vector3f(-10, 0, 0)); 2.128 - 2.129 - // come at me bro! 2.130 - path.addWayPoint(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); 2.131 - //path.addWayPoint(new Vector3f(0, 0 , -20)); 2.132 - 2.133 - path.setCurveTension(0.80f); 2.134 + for (Vector3f v : path){ 2.135 + track.addWayPoint(v); 2.136 + } 2.137 + 2.138 + 2.139 + track.setCurveTension(0.80f); 2.140 2.141 2.142 - motionControl = new MotionTrack(bell,path); 2.143 + motionControl = new MotionTrack(bell,track); 2.144 motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation); 2.145 motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y)); 2.146 motionControl.setInitialDuration(10f); 2.147 motionControl.setSpeed(0.1f); 2.148 2.149 2.150 - path.enableDebugShape(assetManager, rootNode); 2.151 + track.enableDebugShape(assetManager, rootNode); 2.152 2.153 2.154 positionCamera(); 2.155 @@ -168,22 +168,43 @@ 2.156 2.157 2.158 private void positionCamera(){ 2.159 - //this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); 2.160 + this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); 2.161 + // cam.setLocation(new Vector3f(0,0,-20)); 2.162 this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f)); 2.163 } 2.164 - 2.165 - 2.166 - 2.167 - 2.168 2.169 private AudioNode music; 2.170 2.171 2.172 + 2.173 + 2.174 + 2.175 + private void initAudio() { 2.176 + 2.177 + music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false); 2.178 + 2.179 + rootNode.attachChild(music); 2.180 + audioRenderer.playSource(music); 2.181 + 2.182 + music.setVolume(1f); 2.183 + music.setPositional(true); 2.184 + music.setMaxDistance(200.0f); 2.185 + music.setRefDistance(0.1f); 2.186 + music.setRolloffFactor(5f); 2.187 + audioRenderer.pauseSource(music); 2.188 + 2.189 + } 2.190 + 2.191 + 2.192 + 2.193 + 2.194 private Listener auxListener = new Listener(); 2.195 public File data1 = new File("/home/r/tmp/data1.wav"); 2.196 public File data2 = new File("/home/r/tmp/data2.wav"); 2.197 public File data3 = new File("/home/r/tmp/data3.wav"); 2.198 - 2.199 + public File data4 = new File("/home/r/tmp/data4.wav"); 2.200 + public File data5 = new File("/home/r/tmp/data5.wav"); 2.201 + public File data6 = new File("/home/r/tmp/data6.wav"); 2.202 2.203 2.204 public void simpleInitApp() { 2.205 @@ -202,57 +223,16 @@ 2.206 rf.registerSoundProcessor(new WaveFileWriter(data1)); 2.207 rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2)); 2.208 rf.registerSoundProcessor(listener3, new WaveFileWriter(data3)); 2.209 - } 2.210 - 2.211 - 2.212 - 2.213 - 2.214 - 2.215 - 2.216 + } 2.217 initAudio(); 2.218 initKeys(); 2.219 createScene(); 2.220 - 2.221 - 2.222 motionControl.play(); 2.223 - 2.224 - //this.audioRenderer.playSource(music); 2.225 - 2.226 - 2.227 - 2.228 } 2.229 2.230 - /** We create two audio nodes. */ 2.231 - private void initAudio() { 2.232 - //audioRenderer.setEnvironment(Environment.Cavern); 2.233 - 2.234 - music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false); 2.235 - 2.236 - //music.setLooping(true); 2.237 - 2.238 - 2.239 - 2.240 - 2.241 - 2.242 - rootNode.attachChild(music); 2.243 - audioRenderer.playSource(music); 2.244 - 2.245 - music.setVolume(1f); 2.246 - music.setPositional(true); 2.247 - music.setMaxDistance(200.0f); 2.248 - music.setRefDistance(0.1f); 2.249 - music.setRolloffFactor(5f); 2.250 - audioRenderer.pauseSource(music); 2.251 - 2.252 - 2.253 - 2.254 - } 2.255 + 2.256 2.257 - /** Declaring the "Shoot" action, and 2.258 - * mapping it to a trigger (mouse click). */ 2.259 - 2.260 2.261 - /** Defining the "Shoot" action: Play a gun sound. */ 2.262 2.263 private void initKeys() { 2.264 inputManager.addMapping("Shoot", new MouseButtonTrigger(0)); 2.265 @@ -275,7 +255,9 @@ 2.266 }; 2.267 2.268 /** Move the listener with the camera - for 3D audio. */ 2.269 - @Override 2.270 + 2.271 + 2.272 + private Vector3f prevBellPos = Vector3f.ZERO; 2.273 public void simpleUpdate(float tpf) { 2.274 //Vector3f loc = cam.getLocation(); 2.275 //Quaternion rot = cam.getRotation(); 2.276 @@ -293,7 +275,11 @@ 2.277 //} 2.278 //audioRenderer.updateSourceParam(music, AudioParam.Direction); 2.279 2.280 + Vector3f bellVelocity = bell.getLocalTranslation().subtract(prevBellPos).mult(1.0f/tpf); 2.281 + prevBellPos = bell.getLocalTranslation(); 2.282 + 2.283 music.setLocalTranslation(bell.getLocalTranslation()); 2.284 + music.setVelocity(bellVelocity); 2.285 2.286 //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_MIN_GAIN, 0f); 2.287 //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_ROLLOFF_FACTOR, 5f);