Mercurial > jmeCapture
comparison src/com/aurellem/capture/examples/AdvancedAudio.java @ 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 |
comparison
equal
deleted
inserted
replaced
18:2543c95a0fd2 | 19:4de7988407ef |
---|---|
5 import com.aurellem.capture.IsoTimer; | 5 import com.aurellem.capture.IsoTimer; |
6 import com.aurellem.capture.audio.MultiListener; | 6 import com.aurellem.capture.audio.MultiListener; |
7 import com.aurellem.capture.audio.WaveFileWriter; | 7 import com.aurellem.capture.audio.WaveFileWriter; |
8 import com.jme3.app.SimpleApplication; | 8 import com.jme3.app.SimpleApplication; |
9 import com.jme3.audio.AudioNode; | 9 import com.jme3.audio.AudioNode; |
10 import com.jme3.audio.AudioParam; | |
11 import com.jme3.audio.Listener; | 10 import com.jme3.audio.Listener; |
12 import com.jme3.cinematic.MotionPath; | 11 import com.jme3.cinematic.MotionPath; |
13 import com.jme3.cinematic.events.MotionTrack; | 12 import com.jme3.cinematic.events.MotionTrack; |
14 import com.jme3.input.controls.ActionListener; | 13 import com.jme3.input.controls.ActionListener; |
15 import com.jme3.input.controls.MouseButtonTrigger; | 14 import com.jme3.input.controls.MouseButtonTrigger; |
71 root.attachChild(ear); | 70 root.attachChild(ear); |
72 } | 71 } |
73 | 72 |
74 private Geometry bell; | 73 private Geometry bell; |
75 | 74 |
75 | |
76 private Vector3f[] path = new Vector3f[]{ | |
77 // loop 1 | |
78 new Vector3f(0, 0, 0), | |
79 new Vector3f(0, 0, -10), | |
80 new Vector3f(-2, 0, -14), | |
81 new Vector3f(-6, 0, -20), | |
82 new Vector3f(0, 0, -26), | |
83 new Vector3f(6, 0, -20), | |
84 new Vector3f(0, 0, -14), | |
85 new Vector3f(-6, 0, -20), | |
86 new Vector3f(0, 0, -26), | |
87 new Vector3f(6, 0, -20), | |
88 // loop 2 | |
89 new Vector3f(5, 0, -5), | |
90 new Vector3f(7, 0, 1.5f), | |
91 new Vector3f(14, 0, 2), | |
92 new Vector3f(20, 0, 6), | |
93 new Vector3f(26, 0, 0), | |
94 new Vector3f(20, 0, -6), | |
95 new Vector3f(14, 0, 0), | |
96 new Vector3f(20, 0, 6), | |
97 new Vector3f(26, 0, 0), | |
98 new Vector3f(20, 0, -6), | |
99 new Vector3f(14, 0, 0), | |
100 // loop 3 | |
101 new Vector3f(8, 0, 7.5f), | |
102 new Vector3f(7, 0, 10.5f), | |
103 new Vector3f(6, 0, 20), | |
104 new Vector3f(0, 0, 26), | |
105 new Vector3f(-6, 0, 20), | |
106 new Vector3f(0, 0, 14), | |
107 new Vector3f(6, 0, 20), | |
108 new Vector3f(0, 0, 26), | |
109 new Vector3f(-6, 0, 20), | |
110 new Vector3f(0, 0, 14), | |
111 // begin ellipse | |
112 new Vector3f(16, 5, 20), | |
113 new Vector3f(0, 0, 26), | |
114 new Vector3f(-16, -10, 20), | |
115 new Vector3f(0, 0, 14), | |
116 new Vector3f(16, 20, 20), | |
117 new Vector3f(0, 0, 26), | |
118 new Vector3f(-10, -25, 10), | |
119 new Vector3f(-10, 0, 0), | |
120 // come at me bro! | |
121 new Vector3f(-28.00242f, 48.005623f, -34.648228f), | |
122 new Vector3f(0, 0 , -20), | |
123 }; | |
124 | |
125 | |
126 | |
76 private void createScene() { | 127 private void createScene() { |
77 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); | 128 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); |
78 bell = new Geometry( "sound-emitter" , new Sphere(15,15,1)); | 129 bell = new Geometry( "sound-emitter" , new Sphere(15,15,1)); |
79 mat.setColor("Color", ColorRGBA.Blue); | 130 mat.setColor("Color", ColorRGBA.Blue); |
80 bell.setMaterial(mat); | 131 bell.setMaterial(mat); |
88 makeEar(rootNode, new Vector3f(0, 0 ,20)); | 139 makeEar(rootNode, new Vector3f(0, 0 ,20)); |
89 makeEar(rootNode, new Vector3f(0, 0 ,-20)); | 140 makeEar(rootNode, new Vector3f(0, 0 ,-20)); |
90 makeEar(rootNode, new Vector3f(20, 0 ,0)); | 141 makeEar(rootNode, new Vector3f(20, 0 ,0)); |
91 makeEar(rootNode, new Vector3f(-20, 0 ,0)); | 142 makeEar(rootNode, new Vector3f(-20, 0 ,0)); |
92 | 143 |
93 MotionPath path = new MotionPath(); | 144 MotionPath track = new MotionPath(); |
94 | 145 |
95 // loop 1 | 146 for (Vector3f v : path){ |
96 path.addWayPoint(new Vector3f(0, 0, 0)); | 147 track.addWayPoint(v); |
97 path.addWayPoint(new Vector3f(0, 0, -10)); | 148 } |
98 path.addWayPoint(new Vector3f(-2, 0, -14)); | 149 |
99 path.addWayPoint(new Vector3f(-6, 0, -20)); | 150 |
100 path.addWayPoint(new Vector3f(0, 0, -26)); | 151 track.setCurveTension(0.80f); |
101 path.addWayPoint(new Vector3f(6, 0, -20)); | 152 |
102 path.addWayPoint(new Vector3f(0, 0, -14)); | 153 |
103 path.addWayPoint(new Vector3f(-6, 0, -20)); | 154 motionControl = new MotionTrack(bell,track); |
104 path.addWayPoint(new Vector3f(0, 0, -26)); | |
105 path.addWayPoint(new Vector3f(6, 0, -20)); | |
106 | |
107 | |
108 // loop 2 | |
109 path.addWayPoint(new Vector3f(5, 0, -5)); | |
110 path.addWayPoint(new Vector3f(7, 0, 1.5f)); | |
111 path.addWayPoint(new Vector3f(14, 0, 2)); | |
112 path.addWayPoint(new Vector3f(20, 0, 6)); | |
113 path.addWayPoint(new Vector3f(26, 0, 0)); | |
114 path.addWayPoint(new Vector3f(20, 0, -6)); | |
115 path.addWayPoint(new Vector3f(14, 0, 0)); | |
116 path.addWayPoint(new Vector3f(20, 0, 6)); | |
117 path.addWayPoint(new Vector3f(26, 0, 0)); | |
118 path.addWayPoint(new Vector3f(20, 0, -6)); | |
119 path.addWayPoint(new Vector3f(14, 0, 0)); | |
120 | |
121 | |
122 | |
123 // loop 3 | |
124 path.addWayPoint(new Vector3f(8, 0, 7.5f)); | |
125 path.addWayPoint(new Vector3f(7, 0, 10.5f)); | |
126 path.addWayPoint(new Vector3f(6, 0, 20)); | |
127 path.addWayPoint(new Vector3f(0, 0, 26)); | |
128 path.addWayPoint(new Vector3f(-6, 0, 20)); | |
129 path.addWayPoint(new Vector3f(0, 0, 14)); | |
130 path.addWayPoint(new Vector3f(6, 0, 20)); | |
131 path.addWayPoint(new Vector3f(0, 0, 26)); | |
132 path.addWayPoint(new Vector3f(-6, 0, 20)); | |
133 path.addWayPoint(new Vector3f(0, 0, 14)); | |
134 | |
135 | |
136 // begin elipse | |
137 | |
138 path.addWayPoint(new Vector3f(16, 5, 20)); | |
139 path.addWayPoint(new Vector3f(0, 0, 26)); | |
140 path.addWayPoint(new Vector3f(-16, -10, 20)); | |
141 path.addWayPoint(new Vector3f(0, 0, 14)); | |
142 path.addWayPoint(new Vector3f(16, 20, 20)); | |
143 path.addWayPoint(new Vector3f(0, 0, 26)); | |
144 path.addWayPoint(new Vector3f(-10, -25, 10)); | |
145 path.addWayPoint(new Vector3f(-10, 0, 0)); | |
146 | |
147 // come at me bro! | |
148 path.addWayPoint(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); | |
149 //path.addWayPoint(new Vector3f(0, 0 , -20)); | |
150 | |
151 path.setCurveTension(0.80f); | |
152 | |
153 | |
154 motionControl = new MotionTrack(bell,path); | |
155 motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation); | 155 motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation); |
156 motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y)); | 156 motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y)); |
157 motionControl.setInitialDuration(10f); | 157 motionControl.setInitialDuration(10f); |
158 motionControl.setSpeed(0.1f); | 158 motionControl.setSpeed(0.1f); |
159 | 159 |
160 | 160 |
161 path.enableDebugShape(assetManager, rootNode); | 161 track.enableDebugShape(assetManager, rootNode); |
162 | 162 |
163 | 163 |
164 positionCamera(); | 164 positionCamera(); |
165 | 165 |
166 | 166 |
167 } | 167 } |
168 | 168 |
169 | 169 |
170 private void positionCamera(){ | 170 private void positionCamera(){ |
171 //this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); | 171 this.cam.setLocation(new Vector3f(-28.00242f, 48.005623f, -34.648228f)); |
172 // cam.setLocation(new Vector3f(0,0,-20)); | |
172 this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f)); | 173 this.cam.setRotation(new Quaternion(0.3359635f, 0.34280345f, -0.13281013f, 0.8671653f)); |
173 } | 174 } |
174 | |
175 | |
176 | |
177 | |
178 | 175 |
179 private AudioNode music; | 176 private AudioNode music; |
177 | |
178 | |
179 | |
180 | |
181 | |
182 private void initAudio() { | |
183 | |
184 music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false); | |
185 | |
186 rootNode.attachChild(music); | |
187 audioRenderer.playSource(music); | |
188 | |
189 music.setVolume(1f); | |
190 music.setPositional(true); | |
191 music.setMaxDistance(200.0f); | |
192 music.setRefDistance(0.1f); | |
193 music.setRolloffFactor(5f); | |
194 audioRenderer.pauseSource(music); | |
195 | |
196 } | |
197 | |
198 | |
180 | 199 |
181 | 200 |
182 private Listener auxListener = new Listener(); | 201 private Listener auxListener = new Listener(); |
183 public File data1 = new File("/home/r/tmp/data1.wav"); | 202 public File data1 = new File("/home/r/tmp/data1.wav"); |
184 public File data2 = new File("/home/r/tmp/data2.wav"); | 203 public File data2 = new File("/home/r/tmp/data2.wav"); |
185 public File data3 = new File("/home/r/tmp/data3.wav"); | 204 public File data3 = new File("/home/r/tmp/data3.wav"); |
186 | 205 public File data4 = new File("/home/r/tmp/data4.wav"); |
206 public File data5 = new File("/home/r/tmp/data5.wav"); | |
207 public File data6 = new File("/home/r/tmp/data6.wav"); | |
187 | 208 |
188 | 209 |
189 public void simpleInitApp() { | 210 public void simpleInitApp() { |
190 this.setTimer(new IsoTimer(60)); | 211 this.setTimer(new IsoTimer(60)); |
191 | 212 |
200 rf.addListener(auxListener); | 221 rf.addListener(auxListener); |
201 rf.addListener(listener3); | 222 rf.addListener(listener3); |
202 rf.registerSoundProcessor(new WaveFileWriter(data1)); | 223 rf.registerSoundProcessor(new WaveFileWriter(data1)); |
203 rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2)); | 224 rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2)); |
204 rf.registerSoundProcessor(listener3, new WaveFileWriter(data3)); | 225 rf.registerSoundProcessor(listener3, new WaveFileWriter(data3)); |
205 } | 226 } |
206 | |
207 | |
208 | |
209 | |
210 | |
211 | |
212 initAudio(); | 227 initAudio(); |
213 initKeys(); | 228 initKeys(); |
214 createScene(); | 229 createScene(); |
215 | |
216 | |
217 motionControl.play(); | 230 motionControl.play(); |
218 | 231 } |
219 //this.audioRenderer.playSource(music); | 232 |
220 | 233 |
221 | 234 |
222 | 235 |
223 } | |
224 | |
225 /** We create two audio nodes. */ | |
226 private void initAudio() { | |
227 //audioRenderer.setEnvironment(Environment.Cavern); | |
228 | |
229 music = new AudioNode(assetManager, "Sound/Environment/pure.wav", false); | |
230 | |
231 //music.setLooping(true); | |
232 | |
233 | |
234 | |
235 | |
236 | |
237 rootNode.attachChild(music); | |
238 audioRenderer.playSource(music); | |
239 | |
240 music.setVolume(1f); | |
241 music.setPositional(true); | |
242 music.setMaxDistance(200.0f); | |
243 music.setRefDistance(0.1f); | |
244 music.setRolloffFactor(5f); | |
245 audioRenderer.pauseSource(music); | |
246 | |
247 | |
248 | |
249 } | |
250 | |
251 /** Declaring the "Shoot" action, and | |
252 * mapping it to a trigger (mouse click). */ | |
253 | |
254 | |
255 /** Defining the "Shoot" action: Play a gun sound. */ | |
256 | 236 |
257 private void initKeys() { | 237 private void initKeys() { |
258 inputManager.addMapping("Shoot", new MouseButtonTrigger(0)); | 238 inputManager.addMapping("Shoot", new MouseButtonTrigger(0)); |
259 inputManager.addListener(actionListener, "Shoot"); | 239 inputManager.addListener(actionListener, "Shoot"); |
260 } | 240 } |
273 } | 253 } |
274 } | 254 } |
275 }; | 255 }; |
276 | 256 |
277 /** Move the listener with the camera - for 3D audio. */ | 257 /** Move the listener with the camera - for 3D audio. */ |
278 @Override | 258 |
259 | |
260 private Vector3f prevBellPos = Vector3f.ZERO; | |
279 public void simpleUpdate(float tpf) { | 261 public void simpleUpdate(float tpf) { |
280 //Vector3f loc = cam.getLocation(); | 262 //Vector3f loc = cam.getLocation(); |
281 //Quaternion rot = cam.getRotation(); | 263 //Quaternion rot = cam.getRotation(); |
282 //listener.setLocation(loc); | 264 //listener.setLocation(loc); |
283 //listener.setRotation(rot); | 265 //listener.setRotation(rot); |
291 | 273 |
292 //music.playInstance(); | 274 //music.playInstance(); |
293 //} | 275 //} |
294 //audioRenderer.updateSourceParam(music, AudioParam.Direction); | 276 //audioRenderer.updateSourceParam(music, AudioParam.Direction); |
295 | 277 |
278 Vector3f bellVelocity = bell.getLocalTranslation().subtract(prevBellPos).mult(1.0f/tpf); | |
279 prevBellPos = bell.getLocalTranslation(); | |
280 | |
296 music.setLocalTranslation(bell.getLocalTranslation()); | 281 music.setLocalTranslation(bell.getLocalTranslation()); |
282 music.setVelocity(bellVelocity); | |
297 | 283 |
298 //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_MIN_GAIN, 0f); | 284 //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_MIN_GAIN, 0f); |
299 //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_ROLLOFF_FACTOR, 5f); | 285 //org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_ROLLOFF_FACTOR, 5f); |
300 | 286 |
301 } | 287 } |