comparison src/com/aurellem/capture/examples/AdvancedAudio.java @ 20:bc6fbfbbadd9 spazz

retarded spazz dancing achieved
author Robert McIntyre <rlm@mit.edu>
date Sat, 29 Oct 2011 16:22:57 -0700
parents 4de7988407ef
children c7a07eefaeea
comparison
equal deleted inserted replaced
19:4de7988407ef 20:bc6fbfbbadd9
1 package com.aurellem.capture.examples; 1 package com.aurellem.capture.examples;
2 2
3 import java.io.File; 3 import java.io.File;
4 import java.nio.ByteBuffer;
4 5
5 import com.aurellem.capture.IsoTimer; 6 import com.aurellem.capture.IsoTimer;
6 import com.aurellem.capture.audio.MultiListener; 7 import com.aurellem.capture.audio.MultiListener;
8 import com.aurellem.capture.audio.SoundProcessor;
7 import com.aurellem.capture.audio.WaveFileWriter; 9 import com.aurellem.capture.audio.WaveFileWriter;
8 import com.jme3.app.SimpleApplication; 10 import com.jme3.app.SimpleApplication;
9 import com.jme3.audio.AudioNode; 11 import com.jme3.audio.AudioNode;
10 import com.jme3.audio.Listener; 12 import com.jme3.audio.Listener;
11 import com.jme3.cinematic.MotionPath; 13 import com.jme3.cinematic.MotionPath;
18 import com.jme3.math.FastMath; 20 import com.jme3.math.FastMath;
19 import com.jme3.math.Quaternion; 21 import com.jme3.math.Quaternion;
20 import com.jme3.math.Vector3f; 22 import com.jme3.math.Vector3f;
21 import com.jme3.scene.Geometry; 23 import com.jme3.scene.Geometry;
22 import com.jme3.scene.Node; 24 import com.jme3.scene.Node;
25 import com.jme3.scene.Spatial;
23 import com.jme3.scene.shape.Box; 26 import com.jme3.scene.shape.Box;
24 import com.jme3.scene.shape.Sphere; 27 import com.jme3.scene.shape.Sphere;
25 import com.jme3.system.AppSettings; 28 import com.jme3.system.AppSettings;
26 29
27 30
48 51
49 public static void main(String[] args) { 52 public static void main(String[] args) {
50 53
51 AdvancedAudio app = new AdvancedAudio(); 54 AdvancedAudio app = new AdvancedAudio();
52 AppSettings settings = new AppSettings(true); 55 AppSettings settings = new AppSettings(true);
53 //settings.setAudioRenderer("Send"); 56 settings.setAudioRenderer("Send");
54 app.setSettings(settings); 57 app.setSettings(settings);
55 app.setShowSettings(false); 58 app.setShowSettings(false);
56 app.setPauseOnLostFocus(false); 59 app.setPauseOnLostFocus(false);
57 org.lwjgl.input.Mouse.setGrabbed(false); 60 org.lwjgl.input.Mouse.setGrabbed(false);
58 app.start(); 61 app.start();
59 } 62 }
60 63
61 private MotionTrack motionControl; 64 private MotionTrack motionControl;
62 65
63 66
64 private void makeEar(Node root, Vector3f position){ 67 private Spatial makeEar(Node root, Vector3f position){
65 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); 68 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
66 Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f)); 69 Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f));
67 ear.setLocalTranslation(position); 70 ear.setLocalTranslation(position);
68 mat.setColor("Color", ColorRGBA.Green); 71 mat.setColor("Color", ColorRGBA.Green);
69 ear.setMaterial(mat); 72 ear.setMaterial(mat);
70 root.attachChild(ear); 73 root.attachChild(ear);
74 return ear;
71 } 75 }
72 76
73 private Geometry bell; 77 private Geometry bell;
78
79 private Spatial ear1;
80 private Spatial ear2;
81 private Spatial ear3;
82 private Spatial ear4;
74 83
75 84
76 private Vector3f[] path = new Vector3f[]{ 85 private Vector3f[] path = new Vector3f[]{
77 // loop 1 86 // loop 1
78 new Vector3f(0, 0, 0), 87 new Vector3f(0, 0, 0),
134 DirectionalLight light = new DirectionalLight(); 143 DirectionalLight light = new DirectionalLight();
135 light.setDirection(new Vector3f(0, -1, 0).normalizeLocal()); 144 light.setDirection(new Vector3f(0, -1, 0).normalizeLocal());
136 light.setColor(ColorRGBA.White.mult(1.5f)); 145 light.setColor(ColorRGBA.White.mult(1.5f));
137 rootNode.addLight(light); 146 rootNode.addLight(light);
138 147
139 makeEar(rootNode, new Vector3f(0, 0 ,20)); 148 ear1 = makeEar(rootNode, new Vector3f(0, 0 ,20));
140 makeEar(rootNode, new Vector3f(0, 0 ,-20)); 149 ear2 = makeEar(rootNode, new Vector3f(0, 0 ,-20));
141 makeEar(rootNode, new Vector3f(20, 0 ,0)); 150 ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0));
142 makeEar(rootNode, new Vector3f(-20, 0 ,0)); 151 ear4 = makeEar(rootNode, new Vector3f(-20, 0 ,0));
143 152
144 MotionPath track = new MotionPath(); 153 MotionPath track = new MotionPath();
145 154
146 for (Vector3f v : path){ 155 for (Vector3f v : path){
147 track.addWayPoint(v); 156 track.addWayPoint(v);
203 public File data2 = new File("/home/r/tmp/data2.wav"); 212 public File data2 = new File("/home/r/tmp/data2.wav");
204 public File data3 = new File("/home/r/tmp/data3.wav"); 213 public File data3 = new File("/home/r/tmp/data3.wav");
205 public File data4 = new File("/home/r/tmp/data4.wav"); 214 public File data4 = new File("/home/r/tmp/data4.wav");
206 public File data5 = new File("/home/r/tmp/data5.wav"); 215 public File data5 = new File("/home/r/tmp/data5.wav");
207 public File data6 = new File("/home/r/tmp/data6.wav"); 216 public File data6 = new File("/home/r/tmp/data6.wav");
217
218
219 public class Dancer implements SoundProcessor {
220
221 Spatial entity;
222
223 float scale = 2;
224
225 public Dancer(Spatial entity){
226 this.entity = entity;
227 }
228
229 /**
230 * this method is irrelevant since there is no state to cleanup.
231 */
232 public void cleanup() {}
233
234
235 /**
236 * Dance to the beat! This is the brain of an AI entity that
237 * hears it's surroundings and reacts to them.
238 */
239 public void process(ByteBuffer audioSamples, int numSamples) {
240 System.out.println("I'm DANCING <3");
241 entity.scale(this.scale);
242 if (this.scale == 2f){this.scale = 0.5f;}
243 else {this.scale = 2;}
244 }
245
246
247 }
248
249
208 250
209 251
210 public void simpleInitApp() { 252 public void simpleInitApp() {
211 this.setTimer(new IsoTimer(60)); 253 this.setTimer(new IsoTimer(60));
212
213 if (this.audioRenderer instanceof MultiListener){
214 MultiListener rf = (MultiListener)this.audioRenderer;
215
216 for (int n = 0; n < 0; n++){
217 Listener zzz = new Listener();
218 rf.addListener(zzz);
219 }
220 Listener listener3 = new Listener();
221 rf.addListener(auxListener);
222 rf.addListener(listener3);
223 rf.registerSoundProcessor(new WaveFileWriter(data1));
224 rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2));
225 rf.registerSoundProcessor(listener3, new WaveFileWriter(data3));
226 }
227 initAudio(); 254 initAudio();
228 initKeys(); 255 initKeys();
229 createScene(); 256 createScene();
257 if (this.audioRenderer instanceof MultiListener){
258 MultiListener rf = (MultiListener)this.audioRenderer;
259
260
261 rf.addListener(auxListener);
262
263 rf.registerSoundProcessor(new WaveFileWriter(data1));
264 rf.registerSoundProcessor(auxListener, new Dancer(ear1));
265
266 }
267
230 motionControl.play(); 268 motionControl.play();
231 } 269 }
232 270
233 271
234 272