changeset 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 d924d7d29063
files src/com/aurellem/capture/examples/AdvancedAudio.java
diffstat 1 files changed, 56 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/src/com/aurellem/capture/examples/AdvancedAudio.java	Sat Oct 29 15:16:06 2011 -0700
     1.2 +++ b/src/com/aurellem/capture/examples/AdvancedAudio.java	Sat Oct 29 16:22:57 2011 -0700
     1.3 @@ -1,9 +1,11 @@
     1.4  package com.aurellem.capture.examples;
     1.5  
     1.6  import java.io.File;
     1.7 +import java.nio.ByteBuffer;
     1.8  
     1.9  import com.aurellem.capture.IsoTimer;
    1.10  import com.aurellem.capture.audio.MultiListener;
    1.11 +import com.aurellem.capture.audio.SoundProcessor;
    1.12  import com.aurellem.capture.audio.WaveFileWriter;
    1.13  import com.jme3.app.SimpleApplication;
    1.14  import com.jme3.audio.AudioNode;
    1.15 @@ -20,6 +22,7 @@
    1.16  import com.jme3.math.Vector3f;
    1.17  import com.jme3.scene.Geometry;
    1.18  import com.jme3.scene.Node;
    1.19 +import com.jme3.scene.Spatial;
    1.20  import com.jme3.scene.shape.Box;
    1.21  import com.jme3.scene.shape.Sphere;
    1.22  import com.jme3.system.AppSettings;
    1.23 @@ -50,7 +53,7 @@
    1.24  		  
    1.25  			AdvancedAudio app = new AdvancedAudio();
    1.26  			AppSettings settings = new AppSettings(true);
    1.27 -			//settings.setAudioRenderer("Send");
    1.28 +			settings.setAudioRenderer("Send");
    1.29  			app.setSettings(settings);
    1.30  			app.setShowSettings(false);
    1.31  			app.setPauseOnLostFocus(false);
    1.32 @@ -61,17 +64,23 @@
    1.33  	 private MotionTrack motionControl;
    1.34  	
    1.35  	 
    1.36 -	 private void makeEar(Node root, Vector3f position){
    1.37 +	 private Spatial makeEar(Node root, Vector3f position){
    1.38  		 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    1.39  		 Geometry ear = new Geometry("ear", new Box(1.0f, 1.0f, 1.0f));
    1.40  		 ear.setLocalTranslation(position);
    1.41  		 mat.setColor("Color", ColorRGBA.Green);
    1.42  		 ear.setMaterial(mat);
    1.43  		 root.attachChild(ear);
    1.44 +		 return ear;
    1.45  	 } 
    1.46  	 
    1.47  	 private Geometry bell;
    1.48  	 
    1.49 +	 private Spatial ear1;
    1.50 +	 private Spatial ear2;
    1.51 +	 private Spatial ear3;
    1.52 +	 private Spatial ear4;
    1.53 +	 
    1.54  	 
    1.55  	 private Vector3f[] path = new Vector3f[]{
    1.56  			 // loop 1
    1.57 @@ -136,10 +145,10 @@
    1.58  		 light.setColor(ColorRGBA.White.mult(1.5f));
    1.59  		 rootNode.addLight(light);
    1.60  
    1.61 -		 makeEar(rootNode, new Vector3f(0, 0 ,20));
    1.62 -		 makeEar(rootNode, new Vector3f(0, 0 ,-20));
    1.63 -		 makeEar(rootNode, new Vector3f(20, 0 ,0));
    1.64 -		 makeEar(rootNode, new Vector3f(-20, 0 ,0));
    1.65 +		 ear1 = makeEar(rootNode, new Vector3f(0, 0 ,20));
    1.66 +		 ear2 = makeEar(rootNode, new Vector3f(0, 0 ,-20));
    1.67 +		 ear3 = makeEar(rootNode, new Vector3f(20, 0 ,0));
    1.68 +		 ear4 = makeEar(rootNode, new Vector3f(-20, 0 ,0));
    1.69  
    1.70  		 MotionPath track = new MotionPath();
    1.71  		 
    1.72 @@ -205,28 +214,57 @@
    1.73    public File data4 = new File("/home/r/tmp/data4.wav");
    1.74    public File data5 = new File("/home/r/tmp/data5.wav");
    1.75    public File data6 = new File("/home/r/tmp/data6.wav");
    1.76 +
    1.77 +
    1.78 +  public class Dancer implements SoundProcessor {
    1.79 +
    1.80 +	  Spatial entity;
    1.81 +
    1.82 +	  float scale = 2;
    1.83 +	  
    1.84 +	  public Dancer(Spatial entity){
    1.85 +		  this.entity = entity;
    1.86 +	  }
    1.87 +
    1.88 +	  /**
    1.89 +	   * this method is irrelevant since there is no state to cleanup.
    1.90 +	   */
    1.91 +	  public void cleanup() {}
    1.92 +
    1.93 +
    1.94 +	  /**
    1.95 +	   * Dance to the beat!  This is the brain of an AI entity that 
    1.96 +	   * hears it's surroundings and reacts to them.
    1.97 +	   */
    1.98 +	  public void process(ByteBuffer audioSamples, int numSamples) {
    1.99 +		  System.out.println("I'm DANCING <3");
   1.100 +		  entity.scale(this.scale);
   1.101 +		  if (this.scale == 2f){this.scale = 0.5f;}
   1.102 +		  else {this.scale = 2;}
   1.103 +	  }
   1.104 +
   1.105 +
   1.106 +  }
   1.107 +
   1.108 +  
   1.109    
   1.110    
   1.111    public void simpleInitApp() {
   1.112  	this.setTimer(new IsoTimer(60));
   1.113 -	
   1.114 +    initAudio();
   1.115 +    initKeys();
   1.116 +	createScene();
   1.117  	if (this.audioRenderer instanceof MultiListener){
   1.118  		MultiListener rf = (MultiListener)this.audioRenderer;
   1.119  		
   1.120 -		for (int n = 0; n < 0; n++){
   1.121 -			Listener zzz = new Listener();
   1.122 -			rf.addListener(zzz);
   1.123 -		}
   1.124 -		Listener listener3 = new Listener();
   1.125 +		
   1.126  		rf.addListener(auxListener);
   1.127 -		rf.addListener(listener3);
   1.128 +		
   1.129  		rf.registerSoundProcessor(new WaveFileWriter(data1));
   1.130 -		rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2));
   1.131 -		rf.registerSoundProcessor(listener3, new WaveFileWriter(data3));
   1.132 +		rf.registerSoundProcessor(auxListener, new Dancer(ear1));
   1.133 +		
   1.134  	}   
   1.135 -    initAudio();
   1.136 -    initKeys();
   1.137 -	createScene();
   1.138 +
   1.139      motionControl.play();
   1.140    }
   1.141