We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › Waveform display with ESS
Page Index Toggle Pages: 1
Waveform display with ESS (Read 1111 times)
Waveform display with ESS
Dec 19th, 2006, 1:19pm
 
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);
}
}
Re: Waveform display with ESS
Reply #1 - Dec 19th, 2006, 1:43pm
 
Try moving the background(0) line from setup() into draw().
Re: Waveform display with ESS
Reply #2 - Dec 19th, 2006, 10:05pm
 
Thank you John. That took care of the redraw problem, but the waveform is looking like it is scaled wrong. Here is a picture of it: http://img110.imageshack.us/img110/3203/waveformerrorxu7.jpg
Page Index Toggle Pages: 1