114




import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;


Minim minim;
AudioOutput out;
SineWave sine;

void setup(){
size(512,200,P2D);
minim = new Minim(this);
out = minim.getLineOut(Minim.STEREO);
sine = new SineWave(440,0.5,out.sampleRate());
sine.portamento(200);
out.addSignal(sine);
}

void draw(){
background(120,255,220);
stroke(255);
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);


}
}

void mouseMoved(){
// with portamento on the frequency will change smoothly
float freq = map(mouseY, 0, height, 1500, 60);
sine.setFreq(freq);
// pan always changes smoothly to avoid crackles getting into the signal
// note that we could call setPan on out, instead of on sine
// this would sound the same, but the waveforms in out would not reflect the panning
float pan = map(mouseX, 0, width, -1, 1);
sine.setPan(pan);
}

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

super.stop();
save("114.jpg");
}

コメント