//Processing Code
import ddf.minim.*;
import ddf.minim.signals.*;
import processing.serial.*;
Serial myPort; // Create object from Serial class
Minim minim;
AudioOutput out;
SineWave sine1;
int val; // Data received from the serial port
float amp1 = 0.8;
float sr = 44100;
void setup()
{
size(512, 200, P2D);
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
minim = new Minim(this);
out = minim.getLineOut(Minim.STEREO, 2048);
sine1 = new SineWave(val, amp1, sr);
out.addSignal(sine1);
}
void draw()
{
background(0);
stroke(255);
if ( myPort.available() > 0) {
val = myPort.read();
println(val);
}
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, 150 + out.right.get(i)*50, x2, 150 +
out.right.get(i+1)*50);
}
sine1.setFreq(val*2);
}
void stop()
{
out.close();
minim.stop();
super.stop();
}
import ddf.minim.*;
import ddf.minim.signals.*;
import processing.serial.*;
Serial myPort; // Create object from Serial class
Minim minim;
AudioOutput out;
SineWave sine1;
int val; // Data received from the serial port
float amp1 = 0.8;
float sr = 44100;
void setup()
{
size(512, 200, P2D);
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
minim = new Minim(this);
out = minim.getLineOut(Minim.STEREO, 2048);
sine1 = new SineWave(val, amp1, sr);
out.addSignal(sine1);
}
void draw()
{
background(0);
stroke(255);
if ( myPort.available() > 0) {
val = myPort.read();
println(val);
}
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, 150 + out.right.get(i)*50, x2, 150 +
out.right.get(i+1)*50);
}
sine1.setFreq(val*2);
}
void stop()
{
out.close();
minim.stop();
super.stop();
}
No comments:
Post a Comment