Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

DS3 // OSC – Using the IPhone’s Accelerometer in Processing

23. September 2013

I experimented with sound generation from movement using the accelerometer of my IPhone. To send the signal I used the app OSCmote. To receive to OSC protocol messages I made use of the library oscP5. I then used the input to modulate a synth's frequency and gain. The tone was generated with Minim. oscp5  
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.effects.*;
import oscP5.*;
import netP5.*;

OscP5 oscP5;
 
Minim minim;
AudioOutput out;
SquareWave square;
LowPassSP   lowpass;

float[][] graphVals; 
 
void setup()
{
  size(512, 400, P3D);
  minim = new Minim(this);
  square = new SquareWave(200, 0.5, 44100);
  out = minim.getLineOut(Minim.STEREO, 512);
  out.setGain(-24);
  out.addSignal(square);
  
  // OSC Signal Receiver
  oscP5 = new OscP5(this,3333);
  oscP5.plug(this,"accel_function","/acceleration/xyz","fff");
  
  // Set up graphVals
  graphVals = new float[2][];
  for (int i = 0; i < 2; i++) {
    graphVals[i] = new float[width];
    for (int j = 0; j < graphVals[i].length; j++) {
      graphVals[i][j] = 0;
    }
  }
}

public void accel_function(float x, float y, float z) {
  
  // Modulate Freq.
  square.setFreq(340 - z*300);
  sine.setFreq(240 - y*100);
  //out.setPan(x);
  out.setGain(-18 - 30 * y);
   
  for (int i = 0; i < 1; i++) {
    for (int j = 0; j < graphVals[i].length-1; j++) {
      graphVals[i][j] = graphVals[i][j+1]; 
    }
  }
  graphVals[0][graphVals[0].length-1] = square.frequency();
}

void draw()
{
  println("Frequency: "+square.frequency());
  println("Gain: "+out.getGain());
  println("Pan: "+out.getPan());
  background(0);
  stroke(255);
  
  // draw the waveforms
  for(int i = 0; i < out.bufferSize() - 1; i++)
  {
    float x1 = map(i, 0, out.bufferSize(), 0, width);
    float x2 = map(i+1, 0, out.bufferSize(), 0, width);
    line(x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    line(x1, 50 + out.right.get(i)*50, x2, 50 + out.right.get(i+1)*50);
  }
 
  // draw the graph   
  for (int i = 0; i < 1; i++) {
    for (int j = 0; j < graphVals[i].length-1; j++) {
      stroke(230);
      strokeWeight(2);
      line(j,-graphVals[i][j]/10+180+70*(i+1),j+1,-graphVals[i][j+1]/10+180+70*(i+1));
    }
  }
}

 
void stop()
{
  out.close();
  minim.stop();
 
  super.stop();
}