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 & HelpSyntax Questions › make Waveform moving
Page Index Toggle Pages: 1
make Waveform moving (Read 571 times)
make Waveform moving
Oct 17th, 2009, 4:19am
 
hi,

i want to draw a waveform with
Code:
noFill();
stroke(255);
beginShape();
for ( int i = 1; i < 400; i++ )
{
vertex(i, height- readings3[i]/3);

}
endShape();


the problem is, the whole waveform should move vom right to left!
like audiosignal an a timeline.
how kann i do this??

regards maik
Re: make Waveform moving
Reply #1 - Oct 17th, 2009, 6:38am
 
Assuming the data in 'readings3' is constantly being updated with new values, then it's perhaps worth looking at using an ArrayList instead of a standard array.  This gives you access to add() and remove() methods (see the linked Java reference description): when new data needs to be written remove() the first (i.e. oldest) element from the array and add() the new data to the end.  You'd then need to make some minor changes to your code to draw the wave: ArrayList has a get() method to access items in the array, and you'd do well to make your loop:

for (int i=0; i<readings3.size(); i++)

If on the other hand the array is static you could just remove a value from the beginning of the array and add it to the end; though in this case you'd need to ensure the initial first and last values 'joined up' or you'd get an obvious break in the wave form...
Re: make Waveform moving
Reply #2 - Oct 24th, 2009, 2:19am
 
hi BlindFish

i found a way to do that  Cool

Code:
/////////////////////////////////AUDIO-Signal///////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
float a(){
float k = map(myFFT.getAvg(range-1), 0, 100, 0, 2);
a= pow(k, 3);
return a;
}
float b(){
float n = map(myFFT.getAvg(range), 0, 100, 0, 2);
b= pow(n, 3);
return b;
}
float c(){
float m = map(myFFT.getAvg(range+1), 0, 100, 0, 2);
c= pow(m, 3);
return c;
}
/////////////////////////////////AUDIO-Array////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
void RenderAll(){
readingsAll[399] = (a+b+c);
for(int z = 0; z < numReadingsAll-1 ; z++){
readingsAll[z]=readingsAll[z+1];}
indexAll = indexAll + 1;
if (indexAll >= numReadingsAll)
indexAll = 0;


}

void Render1(){
readings1[399] = a;
for(int z = 0; z < numReadings1-1 ; z++){
readings1[z]=readings1[z+1];}
index1 = index1 + 1;
if (index1 >= numReadings1)
index1 = 0;

}
void Render2(){
readings2[399] = b;
for(int z = 0; z < numReadings2-1 ; z++){
readings2[z]=readings2[z+1];}
index2 = index2 + 1;
if (index2 >= numReadings2)
index2 = 0;

}

void Render3(){
readings3[399] = c;
for(int z = 0; z < numReadings3-1 ; z++){
readings3[z]=readings3[z+1];}
index3 = index3 + 1;
if (index3 >= numReadings3)
index3 = 0;

}
/////////////////////////////////DRAW-WAVE-FORM's///////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
int ctid = controlP5.window(this).currentTab().id();

if(ctid == 5) {
stroke(150,150,0);
line(20,height-avgAll,width,height-avgAll);
noFill();
stroke(255,255,0);
beginShape();
for(int t = 0; t < numReadingsAll-1 ; t++){
vertex(t,height- (readingsAll[t+1])*Volume);
}
endShape();
} else if (ctid==2) {
stroke(150,0,0);
line(20,height-avg1,width,height-avg1);
noFill();
stroke(255,0,0);
beginShape();
for(int t = 0; t < numReadings1-1 ; t++){
vertex(t,height- (readings1[t+1])*Volume);
}
endShape();
} else if (ctid==3) {
stroke(0,150,0);
line(20,height-avg2,width,height-avg2);
noFill();
stroke(0,255,0);
beginShape();
for(int t = 0; t < numReadings2-1 ; t++){
vertex(t,height- (readings2[t+1])*Volume);
}
endShape();
} else if (ctid==4) {
stroke(0,0,150);
line(20,height-avg3,width,height-avg3);
noFill();
stroke(0,0,255);
beginShape();
for(int t = 0; t < numReadings3-1 ; t++){
vertex(t,height- (readings3[t+1])*Volume);
}
endShape();
}






regards maik
Page Index Toggle Pages: 1