5..2 Processing to Rhino using OSC – Sound

 

You can downloads the above definition here: sound_cylinder.zip

In the sketch below we are sending the data from the sound buffer to use as the radius of an array of circles in rhino. Keep in mind that the sound buffer contains 1024 values. Rather than send all of the values we are sending every 20th value (or about 50 values, which is plenty) and then lofting the circles to create a tube. Sending all 1024 values 30 times a second may cause Grasshopper to crash or update slower.

//load sound library
import ddf.minim.*;

//load network and osc library
import netP5.*;
import oscP5.*;

//declare objects to hold the ip address and port 
//sendign to, the osc message, and the osc object
NetAddress myBroadcastLocation; 
OscMessage myMessage;
OscP5 oscP5;

//declare minim object
Minim minim;
//audio input object
AudioInput sound;

//sound amplitude multiplier
float amplitude = 150;

void setup() {
  size(800, 400);
  
  //set osc object and port to send out from
  oscP5 = new OscP5(this,6880);
  //set ip addess in this case your computer and port to send to
  myBroadcastLocation = new NetAddress("localhost",1200);
  
  //set minim object and sound input
  minim = new Minim(this);
  sound = minim.getLineIn(Minim.STEREO, 1024);
  
}

void draw()
{
  background(0);
  stroke(255);
  
  //rest OSC message
  myMessage = new OscMessage("/sound");
  // draw the waveform with a loop
  for(int i = 0; i < sound.bufferSize(); i++){
    point( i, height/2 + sound.mix.get(i)*amplitude);
    
    //check to see if i is evenly divisible by 20 and then
    //add every 20th sound value to the OSC message to send
    if(i%20 == 0){
      myMessage.add(sound.mix.get(i)*amplitude);
    }
  }
  
  //send OSC messgae
  oscP5.send(myMessage, myBroadcastLocation);
}