loading vertex(x, y) from audio files in setup()

hello,

i am trying to use preloaded audio files to seed point information using vertex(x, y). in my setup, i successfully load audio files from the data folder and perform fft. (i am using minim.) when i create an array of data points, the resulting array is filled with zeroes even though the files have been loaded. i can make the arrays in draw(), but then i'll have multiple copies of them. but, when i do create the arrays in draw(), the arrays are filled with numbers other than zero.

here is a sample of my code:

float ax[][];
float ay[][];

setup()
{
      ax = new float[27][1024];
      ay = new float[27][1024];

      for(int i = 0; i <= tracks.length; i ++)
      {
           for(int j = 0; j < ffts[i].specSize(); j ++)
           {
                ax[i][j] = scale * ffts[i].getBand(j);
                ay[i][j] = scale * ffts[i].getBand(j);

                println(ffts[i]);  //lists addresses of files in memory in the form: ddf.minim.analysis.FFT@1c33a141
                println(audioFiles[i]);  //lists addresses of files in memory in the form: ddf.minim.AudioPlayer@19fc0de
                println(ffts[i].getBand(j)); //0.0 for every fft[i]
                println(i + ": " + ax[i][j] + ", " + ay[i][j]); //0.0 for every (ax[i][1024], ay[i][1024])
           }
      }
}

what's going wrong?

thanks in advance,

destro

Tagged:

Answers

  • edited December 2013

    pls post the entire code

    e.g. you must load and set path after using size() in setup().

  • hi chrisir,

    i have loaded the files and set the path after size().

    the code is rather large. i'll make a small excerpt and re-post.

    thanks.

  • edited December 2013

    hello again,

    i've extracted part of the code:

    import ddf.minim.*;
    import ddf.minim.analysis.*;
    
    Minim minim;
    AudioPlayer audioFile;
    
    Minim [] minims = new Minim[5];
    AudioPlayer [] audioFiles = new AudioPlayer[5];
    FFT [] ffts = new FFT[5];
    
    int [] tracks = new int[5];
    
    float ax[][];
    float ay[][];
    
    void setup()
    {
          background(0);
          smooth();
          size(1024, 768);
    
          ax = new float[27][1024];
          ay = new float[27][1024];
    
          for(int i = 0; i < tracks.length; i ++)
          {
            minims[i] = new Minim(this);
          }
    
          //loads 1 track
          for(int i = 0; i < numHiHat.length; i ++)
          {
            trackName = "APZX_Amalgamize_Full/0" + (i + 1) + "_HiHat.wav";
            audioFiles[i] = minims[i].loadFile(trackName, 1024);
            audioFiles[i].loop(1);
          }
    
           //loads 4 tracks
          for(int i = 0; i < numBass.length; i ++)
          {
            trackName = "APZX_Amalgamize_Full/0" + (i + 2) + "_Bass" + (i + 1) + ".wav";
            audioFiles[i + 1] = minims[i + 1].loadFile(trackName, 1024);
            audioFiles[i + 1].loop(1);
          }
    
          for(int i = 0; i < tracks.length; i ++)
          {
            ffts[i] = new FFT(audioFiles[i].bufferSize(), audioFiles[i].sampleRate());
            ffts[i].window(FFT.HAMMING);
    
            ffts[i].forward(audioFiles[i].mix); 
          }
    
          for(int i = 0; i < tracks.length; i ++)
          {
            for(int k = 0; k < ffts[i].specSize(); k ++)
              {
                ax[i][k] = scale * ffts[i].getBand(k); 
                ay[i][k] = scale * ffts[i].getBand(k); 
    
                println(ffts[i]);
                println(audioFiles[i]);
                println(ffts[i].getBand(k));
                println(i + ": " + ax[i][k] + ", " + ay[i][k]);
              }
          }
    }
    
  • edited December 2013

    i figured out one problem, but i don't know how to solve it...

    the problem is that in order to get fft.getBand(), the files needs to be mixed. however, the mix needs to occur in draw(). i need to populate the array in setup to prevent extra copies of it, right? so, how can i populate the array in setup if the values can't be generated until after the fft.mix in draw. the fft.mix does not work in setup.

  • edited December 2013

    You can check if it's the first frame:

    if(frameCount==1){
       //populate fft
    }
    else{
       //do your regular drawing
    }
    

    Or use your own counter for the same effect.

    edit for clarity: in draw(), that is.

  • hi velvet, i don't understand your response. could you elaborate a bit about what i'd be checking?

    after switching to using audiofile.left.get(), i noticed the same behavior; it doesn't read values in setup so i couldn't populate my array until i was in draw(). however, my graphics are slow and it seems they are being drawn multiple times since i have to make the arrays in draw().

  • edited December 2013 Answer ✓

    velvetkevorkian meant that you should do your array initialization in the first frame of draw(), since that's where things happens. Then, on the upcoming frames, you just use this data. frameCount is 1 on the first frame (first call of draw()), 2, 3, etc. on the following ones.

    Side note: please, read To newcomers in this forum: read attentively these instructions. At least to learn how to format your code!

  • hi philho,

    after going back to try to get a feasible solution, i figured that i had to do just what you're suggesting. the reason i didn't want to that even though it worked was because it slowed down my sketch so much, even freezing at times from using printlns to debug. i seemed to have worked through it. thanks for your reply.

Sign In or Register to comment.