Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Sketch lagging

$
0
0
Hey guys, me again.

I've got a pretty cool sketch worked out where I have numerous different "frequency circles" appearing and they disappear and re-appear over time using alpha only to eventually turn into really random flecks of colour across the screen.

I'm having some real difficulties though because the sketch is lagging so damn much that eventually all my nicely timed if functions end up being really out of time by a few seconds meaning that things don't change on the beat/at the right point.

Any help you guys could give would be great!

p.s. this time I actually made sure I was using the right milliseconds.

Here's the code;

  1. import ddf.minim.*;
    import ddf.minim.analysis.*;
    AudioPlayer player, player1;
    Minim minim;
    FFT fft;
    int timeSize = 1024;
    int sampleRate = 44100;
    int bufferSize = 512;
    int fftSize = floor(bufferSize*.5f)+1;
    float ai = TWO_PI/fftSize;
    float aj = TWO_PI/fftSize;


    int value;
    int value2;
    int value3;
    int value4;
    int value5;
    int value6;
    int value7;
    int value8;
    int value9;
    int time;


    void setup() {
     
     
      size(400, 400, P3D);
      smooth();
      noStroke();
      colorMode(HSB, fftSize, 10, 10);
      //frameRate(120);
        minim = new Minim(this);
      player = minim.loadFile("intro.mp3");

      player.play();
     
      fft=new FFT(player.bufferSize(), player.sampleRate());
     

      //smooth();
    }
     
    void draw() {
     
      value = upDownCounter(255, 1);
      value2 = upDownCounter(255, 5);
      value3 = upDownCounter(255, 8);
      value4 = upDownCounter(255, 13);
      value5 = upDownCounter(225, 20);
      value6 = upDownCounter(255, 10);
      value7 = upDownCounter(255, 20);
      value8 = upDownCounter(225, 2);
      value9 = upDownCounter(225, 3);
     
      time = millis();
      
      fft.forward(player.mix);
     
      for (int i = 0; i < fftSize; i++) {
        float band = fft.getBand(i);
        float band2 = fft.getBand(i);
       
       
      { 
         background(value2*(band), value3*(band), value4*(band));
       

      }
     
      
      for (int j = 0; j < fftSize; j++) {
        float band3 = fft.getBand(j);
        float band4 = fft.getBand(j);
     

        {
         
          if(time > 197500){
           
            fill(j, 150+100*(band3), 100, value);

         arc(random(width), random(height), 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
        
         fill(j, 150+100*(band3), 100, value8);

         arc(random(width), random(height), 50+band3 * (j+1)/8, 50+band3 * (j+1)/8, aj*j, aj*(j+1));
        
         fill(j, 150+100*(band3), 100, value8);
        
         arc(random(width), random(height), 10+band3 * (j+1)/8, 10+band3 * (j+1)/8, aj*j, aj*(j+1));
        
      
         
        }else   if(time > 192500){
           
            fill(j, 150+100*(band3), 100, value);

         arc(200, 200, 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
        
         fill(j, 150+100*(band3), 100, value8);

         arc(random(width), random(height), 50+band3 * (j+1)/8, 50+band3 * (j+1)/8, aj*j, aj*(j+1));
        
         fill(j, 150+100*(band3), 100, value8);
        
         arc(random(width), random(height), 10+band3 * (j+1)/8, 10+band3 * (j+1)/8, aj*j, aj*(j+1));
         

         
        }else if(time > 187000){
          
            fill(j, 150+100*(band3), 100, value);

         arc(200, 200, 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
        
         fill(j, 150+100*(band3), 100, value8);

         arc(300, 300, 50+band3 * (j+1)/8, 50+band3 * (j+1)/8, aj*j, aj*(j+1));
        
         fill(j, 150+100*(band3), 100, value8);
        
         arc(random(width), random(height), 10+band3 * (j+1)/8, 10+band3 * (j+1)/8, aj*j, aj*(j+1));
        

            
          
        }  else if(time > 142000){
           
         fill(j, 150+100*(band3), 100, value);

         arc(200, 200, 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
        
         fill(j, 150+100*(band3), 100, value8);

         arc(300, 300, 50+band3 * (j+1)/8, 50+band3 * (j+1)/8, aj*j, aj*(j+1));
        
         fill(j, 150+100*(band3), 100, value8);
        
         arc(50, 50, 10+band3 * (j+1)/8, 10+band3 * (j+1)/8, aj*j, aj*(j+1));
         
         
      
         
        }else if(time > 119000){
          fill(j, 150+100*(band3), 100, value8);

         arc(200, 200, 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
         
         
          fill(j, 150+100*(band3), 100, value8);

         arc(300, 300, 50+band3 * (j+1)/8, 50+band3 * (j+1)/8, aj*j, aj*(j+1));
         
         
          }else if(time > 108000){
         
          fill(j, 150+100*(band3), 100, value9);

         arc(200, 200, 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
        

        
          }else {
           
         fill(j, (value7*band3), 100, value7); 
           
         arc(200, 200, (value2*band3) * (j+1)/8, (value2*band3) * (j+1)/8, aj*j, aj*(j+1));
        

           
            }
        }
      }

      }
     }
     
     
       
     





    int upDownCounter(int maxValue, int factor) {
      int doubleMaxValue = 2*maxValue;
      int fcd = (frameCount/factor)%doubleMaxValue;
      return (fcd<maxValue)?fcd:doubleMaxValue-fcd; // this line is also important!
    }


    void stop()
    {
      player.close();
      player1.close();
      minim.stop();
      super.stop();
    }

Viewing all articles
Browse latest Browse all 1768

Trending Articles