Jeff Zych's Alien Baby

Posted by emily

emily's picture

Description

These musical instruments are dedicated to Rebecca Black, the racist girl at UCLA and the Asian student songwriter's response, Animal Collective's "Lion in a Coma," 404's, 808's, and heartbreaks.  We created several instruments that play both digital and actuated sound.  They include:

  • the Alien Baby (photocell controls pitch and an FSR to changes the waveform)
  • a sound shaker with an FSR that plays a short mp3 clip
  • a glass bottle metronome that keeps time using a DC motor
  • a sump pump didgeridoo
  • a metal rain stick filled with marbles, ball bearings, and bells

Code

Alien Baby

/* filterExample

   is an example of using the different filters
   in continuous sound.

   author: Damien Di Fede, Anderson Mills
   Anderson Mills's work was supported by numediart (www.numediart.org)
*/

// import everything necessary to make sound.
import ddf.minim.*;
import ddf.minim.ugens.*;
// the effects package is needed because the filters are there for now.
import ddf.minim.effects.*;

import processing.serial.*;
import cc.arduino.*;

// Change this to the portname your Arduino board
String portname = "/dev/tty.usbmodem1a21"; // or "1d11"
int photocellPin = 0;
int fsrPin = 1;

final int CUT_OSC_MIN = 5;
final int CUT_OSC_MAX = 50;
final int MAX_FSR_SAMPLES = 50;
int index = 0;
int sampleTotal = 0;
int[] fsrSamples = new int[MAX_FSR_SAMPLES];

// create all of the variables that will need to be accessed
Arduino arduino;
Minim minim;
AudioOutput out;
Serial port;

// create all of the variables
IIRFilter filt;
Oscil osc;
Oscil cutOsc;
Constant cutoff;

// setup is run once at the beginning
void setup()
{
// initialize the drawing window
  size(300, 200, P2D);
  port = new Serial(this, portname, 9600);

  // Initialize array
  for (int i = 0; i < MAX_FSR_SAMPLES; i++) {
    fsrSamples[i] = 0;
  }

  // initialize Arduino
  arduino = new Arduino(this, Arduino.list()[0], 57600);

  // initialize the minim and out objects
  minim = new Minim(this);
  out = minim.getLineOut();

  // initialize the oscillator
  // (a sawtooth wave has energy across the spectrum)
  osc = new Oscil(500, 0.2, Waves.SAW);

  // uncoment one of the filters to hear its effect
  //filt = new LowPassSP(400, out.sampleRate());
  //filt = new LowPassFS(400, out.sampleRate());
  filt = new BandPass(400, 100, out.sampleRate());
  //filt = new HighPassSP(400, out.sampleRate());  // really annoying!
  //filt = new NotchFilter(400, 100, out.sampleRate());

  // create a summer, then add a constant to an oscillating value using it
  Summer sum = new Summer();
  cutoff = new Constant(1000);
  cutOsc = new Oscil(1, 800, Waves.SINE);
  cutoff.patch(sum);
  cutOsc.patch(sum);

  // patch that sum to the cutoff frequency of the filter
  sum.patch(filt.cutoff);

  // patch the sawtooth oscil through the filter and then to the output
  osc.patch(filt).patch(out);
}


// draw is run many times
void draw()
{
  // erase the window to black
  background( 0 );
  // draw using a white stroke
  stroke( 255 );
  // draw the waveforms
  for( int i = 0; i < out.bufferSize() - 1; i++ )
  {
    // find the x position of each buffer value
    float x1  =  map( i, 0, out.bufferSize(), 0, width );
    float x2  =  map( i+1, 0, out.bufferSize(), 0, width );
    // draw a line from one buffer position to the next for both channels
    line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
  }

  // with portamento on the frequency will change smoothly
  //float freq = map(port.read(), 0, 1024, 1500, 60);
  //int freq = port.read();
  //osc.setPhase(freq/height);
  //osc.setFrequency(freq);
  //filt.setFreq(freq*10.0);

  // Get Arduino data
  float mainFreq = map(arduino.analogRead(photocellPin), 0, 800, 1500, 60);

  sampleTotal = sampleTotal - fsrSamples[index];
  fsrSamples[index] = arduino.analogRead(fsrPin);
  sampleTotal = sampleTotal + fsrSamples[index];
  //float cutFreqAvg = sampleTotal/MAX_FSR_SAMPLES*1.0;

  float cutFreqAvg = constrain(map(sampleTotal/MAX_FSR_SAMPLES*1.0, 0,
512, CUT_OSC_MIN, CUT_OSC_MAX), CUT_OSC_MIN, CUT_OSC_MAX);

  // Cannot place in serialEvent, crashes
  osc.setFrequency(mainFreq);
  cutOsc.setFrequency(cutFreqAvg);

  println("freq: " + mainFreq + ", cutFreq: " + cutFreqAvg);

  // Loop index to the beginning
  index++;
  if (index >= MAX_FSR_SAMPLES) index = 0;
}

/*
void serialEvent(Serial p)
{
  int c = port.read();
  if (c != lf && c != cr) {
    buf += char(c);
  }
  if (c == lf) {
    serialData = int(buf);
    if (serialData != 0) {
      println("freq="+serialData);
    }
    buf = "";
  }
} */

// stop is run when the user presses stop
void stop()
{
  // close the AudioOutput
  out.close();
  // stop the minim object
  minim.stop();
  // stop the processing object
  super.stop();
}

Shaker

import ddf.minim.*;

import processing.serial.*;


Minim minim;

AudioPlayer song;

Serial myPort;

String portname = "/dev/tty.usbmodem411";

String buf = "";

int cr = 13;  // ASCII return   == 13

int lf = 10;  // ASCII linefeed == 10

int fsrVal = 0;

int isPlaying = 0;


void setup()

{

  size(100, 100);

  minim = new Minim(this);

  myPort = new Serial(this, portname, 9600);


  // this loads mysong.mp3 from the data folder

  song = minim.loadFile("clap1.mp3");

  //song2 = minim.loadFile("clap2.mp3");

}



//called whenever serial data arrives

void serialEvent(Serial p) {

  //read a byte from the serial port:

  int inByte = myPort.read();

  if (inByte != lf && inByte != cr){

    buf += char(inByte);

  }

  if (inByte == lf){

    fsrVal = int(buf);

    println("fsr value = " + fsrVal);

    buf = "";

  }

}


void draw() {

    if (fsrVal != 0 && !song.isPlaying()) {

    song = minim.loadFile("clap1.mp3");

    song.play();

  }

}



void stop()

{

  song.close();

  minim.stop();

  super.stop();

}

Metronome

 

/*
 * one pot fades one motor
 * modified version of AnalogInput
 * by DojoDave <http://www.0j0.org>
 * http://www.arduino.cc/en/Tutorial/AnalogInput 
 * Modified again by dave
 */

int sensorPin = 2;   // select the input pin for the light sensor

int potPin = 0;   // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0;      // variable to store the value coming from the sensor
void setup() {
  Serial.begin(9600);
}
void loop() {
  val = analogRead(potPin);    // read the value from the sensor, between 0 - 
1024
//  val = analogRead(sensorPin); // read the value of the light sensor
  Serial.println(val);
  analogWrite(motorPin, val/4); // analogWrite can be between 0-255
}

Videos

Jeff's instrument

Emily's instrument

Walter's instrument

The Making Of...

0
Your rating: None