Minim core | ugens | analysis |
BeatDetect Fields FREQ_ENERGY SOUND_ENERGY Methods detect ( ) detectMode ( ) detectSize ( ) getDetectCenterFrequency ( ) isHat ( ) isKick ( ) isOnset ( ) isRange ( ) isSnare ( ) setSensitivity ( ) | The BeatDetect class allows you to analyze an audio stream for beats (rhythmic onsets). Beat Detection Algorithms by Frederic Patin describes beats in the following way: The human listening system determines the rhythm of music by detecting a pseudo periodical succession of beats. The signal which is intercepted by the ear contains a certain energy, this energy is converted into an electrical signal which the brain interprets. Obviously, The more energy the sound transports, the louder the sound will seem. But a sound will be heard as a beat only if his energy is largely superior to the sound's energy history, that is to say if the brain detects a brutal variation in sound energy. Therefore if the ear intercepts a monotonous sound with sometimes big energy peaks it will detect beats, however, if you play a continuous loud sound you will not perceive any beats. Thus, the beats are big variations of sound energy. In fact, the two algorithms in this class are based on two algorithms described in that paper. To use this class, inside of `draw()` you must first call `detect()`, passing the `AudioBuffer` you want to analyze. You may then use the `isXXX` functions to find out what beats have occurred in that frame. For example, you might use `isKick()` to cause a circle to pulse. BeatDetect has two modes: sound energy tracking and frequency energy tracking. In sound energy mode, the level of the buffer, as returned by `level()`, is used as the instant energy in each frame. Beats, then, are spikes in this value, relative to the previous one second of sound. In frequency energy mode, the same process is used but instead of tracking the level of the buffer, an FFT is used to obtain a spectrum, which is then divided into average bands using `logAverages()`, and each of these bands is tracked individually. The result is that it is possible to track sounds that occur in different parts of the frequency spectrum independently (like the kick drum and snare drum). In sound energy mode you use `isOnset()` to query the algorithm and in frequency energy mode you use `isOnset(int i)`, `isKick()`, `isSnare()`, and `isRange()` to query particular frequnecy bands or ranges of frequency bands. It should be noted that `isKick()`, `isSnare()`, and `isHat()` merely call `isRange()` with values determined by testing the algorithm against music with a heavy beat and they may not be appropriate for all kinds of music. If you find they are performing poorly with your music, you should use `isRange()` directly to locate the bands that provide the most meaningful information for you. Constructors
    Create a BeatDetect object that is in SOUND_ENERGY mode.
     timeSize and sampleRate will be set to 1024
     and 44100, respectively, so that it is possible to switch into FREQ_ENERGY
     mode with meaningful values.
    BeatDetect()
    Create a BeatDetect object that is in FREQ_ENERGY mode and expects a
     sample buffer with the requested attributes.
    BeatDetect(int timeSize, float sampleRate)
Parameters timeSize — int: the size of the buffer sampleRate — float: the sample rate of the samples in the buffer Related Example
    /**
      * This sketch demonstrates how to use the BeatDetect object song SOUND_ENERGY mode.<br />
      * You must call <code>detect</code> every frame and then you can use <code>isOnset</code>
      * to track the beat of the music.
      * <p>
      * This sketch plays an entire song, so it may be a little slow to load.
      * <p>
      * For more information about Minim and additional features,
      * visit http://code.compartmental.net/minim/
      */

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

    Minim minim;
    AudioPlayer song;
    BeatDetect beat;

    float eRadius;

    void setup()
    {
      size(200, 200, P3D);
      minim = new Minim(this);
      song = minim.loadFile("marcus_kellis_theme.mp3", 2048);
      song.play();
      // a beat detection object song SOUND_ENERGY mode with a sensitivity of 10 milliseconds
      beat = new BeatDetect();

      ellipseMode(RADIUS);
      eRadius = 20;
    }

    void draw()
    {
      background(0);
      beat.detect(song.mix);
      float a = map(eRadius, 20, 80, 60, 255);
      fill(60, 255, 0, a);
      if ( beat.isOnset() ) eRadius = 80;
      ellipse(width/2, height/2, eRadius, eRadius);
      eRadius *= 0.95;
      if ( eRadius < 20 ) eRadius = 20;
    }
Usage Web & Application