Hello
I am trying to create a program that will generate a sine wave with the frequency and volume based off of the mouse X and Y. I also want it to display the waveform for the current frequency and volume. Here is an example picture: http://www.gemtree.com/SHOOT/sinusoid.gif
The problem I'm having is that the waveform is creating a bunch of lines and not getting rid of the old ones. It also is only creating angled lines and not curves.
Here is what I have so far:
Code:import krister.Ess.*;
AudioStream myStream;
SineWave myWave;
int bufferSize;
int steps;
float limitDiff;
int numAverages=32;
float myDamp=.1f;
float maxLimit,minLimit;
FFT myFFT;
int bufferDuration;
void setup() {
size(640,448);
colorMode(RGB, 255);
// start up Ess
Ess.start(this);
// create a new AudioStream
myStream=new AudioStream();
bufferSize=640;
// set up our FFT
myFFT=new FFT(bufferSize*2);
myFFT.equalizer(true);
// set up our FFT normalization/dampening
minLimit=.005;
maxLimit=.05;
myFFT.limits(minLimit,maxLimit);
myFFT.damp(myDamp);
myFFT.averages(numAverages);
// get the number of bins per average
steps=bufferSize/numAverages;
// get the distance of travel between minimum and maximum limits
limitDiff=maxLimit-minLimit;
// start
myStream.start();
background(0);
bufferDuration=myStream.ms(bufferSize);
}
void draw() {
stroke(0,0,255);
line(0,height/2,width,height/2);
noStroke();
drawSamples();
}
void audioStreamWrite(AudioStream theStream) {
float volume = ((float)mouseY-height)/5;
// our wave
myWave=new SineWave((float)mouseX/100,volume);
// next wave
myWave.generate(myStream);
}
// we are done, clean up Ess
public void stop() {
Ess.stop();
super.stop();
}
void drawSamples() {
stroke(0,255,0);
// interpolate between 0 and writeSamplesSize over writeUpdateTime
int interp=(int)max(0,(((millis()-myStream.bufferStartTime)/(float)bufferDuration)*bufferSize));
for (int i=0;i<640;i++) {
float left=height/2;
float right=height/2;
if (i+interp+1<myStream.buffer2.length) {
left-=myStream.buffer2[i+interp]*75.0;
right-=myStream.buffer2[i+1+interp]*75.0;
}
line(i,left,i+1,right);
}
}