Mot Long
YaBB Newbies
Offline
Posts: 5
smooth(),minim and complexity
Jun 11th , 2009, 12:31am
Hello, i'm trying to learn how to use processing and the minim library. I've wrote a little program.But it runs very slow. package musique; import processing.core.*; import ddf.minim.*; public class Ifreq1 extends PApplet { private static final long serialVersionUID = 1L; Minim minim; AudioPlayer player; float ut=1; public void setup(){ size(640, 640); smooth(); minim = new Minim(this); player = minim.loadFile("/home/gregoire/Public/bauhaus - in the flat field/cp.mp3"); player.loop(); } public void draw(){ background(255); stroke(0); float[] left = player.left.toArray(); float[] right = player.right.toArray(); for ( int i = 0; i < left.length - 1; i++ ) { //stroke(random(100),random(0),random(0)); if(left[i]>0.00001){ fill(random(90),random(190),random(30)); } else{ fill(random(255),random(200,255),random(255)); stroke(255); } float x1 = map(i, 0, player.bufferSize(), 0, width); float x2 = map(i+1, 0, player.bufferSize(), 0, height); ellipse(100+height/3-right[i+1]*120,x2*10,height/3-left[i]*150,x1*10); } } public void stop(){ player.close(); minim.stop(); super.stop(); } You see, this program is very bad for complexity. Is there a way to reduce this complexity? I have just one idea, but i don't know how to do it : Is it possible to get : float[] left = player.left.toArray(); float[] right = player.right.toArray(); before launching the song ? (i don't really understand the way minim works so..) Thank you for reading this and i wish you a nice and pleasant day.