Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sound Kites FINAL PCOMP 2013
// Introduction to Physical Computing - ITP - NYU
// Fall 2013 - Tom Igoe
// Final project - Sound Kites
// Abe Rubenstein + Yu Ji
// PROCESSING
import ddf.minim.*;
import processing.serial.*;
Minim minim;
AudioPlayer player1;
AudioPlayer player2;
AudioPlayer player3;
AudioPlayer player1a; // modulated sound
AudioPlayer player2a; // modulated sound
AudioPlayer player3a; // modulated sound
Serial port;
// sensor initializations (not used anymore)
int init1 = 0;
int init2 = 0;
int init3 = 0;
// sensor data
int s1 = 0;
int s2 = 0;
int s3 = 0;
void setup()
{
//println(Serial.list());
String portName = Serial.list()[4];
port = new Serial(this, portName, 9600);
port.bufferUntil('\n');
size(512, 200);
minim = new Minim(this);
player1 = minim.loadFile("binaural.wav");
player2 = minim.loadFile("binaural2-edit.wav");
player3 = minim.loadFile("binaural3-edit.wav");
player1a = minim.loadFile("binaural-mod.wav");
player2a = minim.loadFile("binaural2-mod.wav");
player3a = minim.loadFile("binaural3-mod.wav");
// initialize sounds and turn gain down
player1.setGain(-50);
player1.play();
player1.loop();
player2.setGain(-50);
player2.play();
player2.loop();
player3.setGain(-50);
player3.play();
player3.loop();
player1a.setGain(-50);
player1a.play();
player1a.loop();
player2a.setGain(-50);
player2a.play();
player2a.loop();
player3a.setGain(-50);
player3a.play();
player3a.loop();
}
void draw() {
// two thresholds for sound
// between 3 and 6/7 is regular sound
// above that is modulated sound
if (s1 > 3) {
if (s1 > 6) player1a.shiftGain(12, -50, 2000);
else player1.shiftGain(0, -50, 2000);
}
if (s2 > 3) {
if (s2 > 7) player2a.shiftGain(12, -50, 2000);
else player2.shiftGain(0, -50, 2000);
}
if (s3 > 3) {
if (s3 > 6) player3a.shiftGain(40, -50, 2000);
else player3.shiftGain(40, -50, 2000);
}
//printSensors();
}
void serialEvent (Serial port) {
String myString = port.readStringUntil('\n');
if (myString != null) {
myString = trim(myString);
int data[] = int(split(myString, ','));
if (data.length == 3) {
s1 = (int)map(data[0], 570,690,10,0);
s2 = (int)map(data[1], 530,640,10,0);
s3 = (int)map(data[2], 520,600,10,0);
}
}
}
void printSensors() {
print("S1: ");
print(s1);
print("/");
print(init1);
print('\t');
print("S2: ");
print(s2);
print("/");
print(init2);
print('\t');
print("S3: ");
print(s3);
print("/");
println(init3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment