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

Millis() out of time

$
0
0
Hey guys I'm currently working on a sketch that uses FFT's and to make the background flicker different colours and to make a circular frequency "bar" thingy bounce in time with the music. What I'm having trouble with though is using millis().


I have a number of "if" functions so that at a 1:48 minutes into the program the frequency circle appears and then at 1:59 and 2:22 the alpha of the frequency circle increases. These changes are timed to beats and other things happening in the music but they keep happening too early (and not just by a few milliseconds either). Can anyone help?

Thanks.

  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 mins;
    int mins2;
    int value;
    int value2;
    int value3;
    int value4;
    int value5;
    int value6;
    int time;

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

      player.play();
     
      fft=new FFT(player.bufferSize(), player.sampleRate());
      //fft=new FFT(player1.bufferSize(), player1.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);
      mins = millis()/100;
      mins2 = millis()/1000;
      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 > 133200){
           
            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));
         
        }else if(time > 95400){
          fill(j, 150+100*(band3), 100, value2);

         arc(200, 200, 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
          
         
         
          }else if(time > 88800){
         
          fill(j, 150+100*(band3), 100, value6);

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

      }
     }
     
     
       
     





    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