Class Name

Waveform

Description

This is a Waveform analyzer. It returns the waveform of an audio stream the moment it is queried with the analyze() method.
Note that by default all sound generators (including microphone capture from AudioIn) have an amplitude of 1, which means that the values of their waveform will be numbers in the range [-0.5, 0.5].

Examples

  • import processing.sound.*;
    
    SoundFile sample;
    Waveform waveform;
    
    int samples = 100;
    
    public void setup()
    {
      size(640, 360);
      background(255);
    
      sample = new SoundFile(this, "beat.aiff");
      sample.loop();
    
      waveform = new Waveform(this, samples);
      waveform.input(sample);
    }
    
    public void draw()
    {
      background(0);
      stroke(255);
      strokeWeight(2);
      noFill();
    
    
      waveform.analyze();
    
      beginShape();
      for(int i = 0; i < samples; i++)
      {
        vertex(
          map(i, 0, samples, 0, width),
          map(waveform.data[i], -1, 1, 0, height)
        );
      }
      endShape();
    }
    

Constructors

  • Waveform(parent, nsamples)

Parameters

  • parent(PApplet)typically use "this"
  • nsamples(int)number of waveform samples that you want to be able to read at once (a positive integer).

Methods

  • analyze()Gets the content of the current audiobuffer from the input source.
  • input()Define the audio input for the analyzer.