how to make a music visualization using beat detect and random lines

edited May 2015 in Library Questions

I'm new at processing and am having difficulties figuring out how to make a very basic music visualization using beat detect or being time based. I want to incorporate a random line for every beat. Anyone able to help? So far, this is all I've got (I'm brand new at this).

import ddf.minim.*; import ddf.minim.analysis.*;

Minim minim; AudioPlayer song; BeatDetect beat;

void setup() { size(1000,550); minim = new Minim(this); song = minim.loadFile("Breeze.mp3");;


void draw() { background(0);



  • Having never done beat detecting myself, I did a quick google search to see what I could find. This came up:

    So you're in the right area. With a little finagling, I got this working! YEAH! Here:

      * This sketch demonstrates how to use an FFT to analyze
      * the audio being generated by an AudioPlayer.
      * <p>
      * FFT stands for Fast Fourier Transform, which is a 
      * method of analyzing audio that allows you to visualize 
      * the frequency content of a signal. You've seen 
      * visualizations like this before in music players 
      * and car stereos.
      * <p>
      * For more information about Minim and additional features, 
      * visit
    import ddf.minim.analysis.*;
    import ddf.minim.*;
    BeatDetect heart = new BeatDetect();
    Minim       minim;
    AudioPlayer jingle;
    FFT         fft;
    void setup()
      size(512, 200, P3D);
      minim = new Minim(this);
      // specify that we want the audio buffers of the AudioPlayer
      // to be 1024 samples long because our FFT needs to have 
      // a power-of-two buffer size and this is a good size.
      jingle = minim.loadFile("jingle.mp3", 1024);
      // loop the file indefinitely
      // create an FFT object that has a time-domain buffer 
      // the same size as jingle's sample buffer
      // note that this needs to be a power of two 
      // and that it means the size of the spectrum will be half as large.
      fft = new FFT( jingle.bufferSize(), jingle.sampleRate() );
    void draw()
      heart.detect( jingle.right );  
      if( heart.isOnset() ){
      // perform a forward FFT on the samples in jingle's mix buffer,
      // which contains the mix of both the left and right channels of the file
      fft.forward( jingle.right );
      for(int i = 0; i < fft.specSize(); i++)
        // draw the line for frequency band i, scaling it up a bit so we can see it
        line( i, height, i, height - fft.getBand(i)*8 );
  • This is great! Thank you! I wasn't trying to go for the heart detect, but this is getting much closer to what I'm trying to get.

    Instead of the heart detect, is there a way to just generate random lines all over the sketch with random x & y points?

  • edited May 2015

    Well yeah. I assumed your problem was getting the detecting to work. The random lines bit is easy. Just pick two random x values using random(width), and two random Y values using random(height), and draw a line using line() (and possibly coloring it with stroke()).

    Post the code of your attempt at it for more help.

Sign In or Register to comment.