Skip to content

Language Settings

Frequency Spectrum

Visualize the frequency spectrum of live audio input.

To run this example locally, you will need the p5.sound library and a running local server.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let mic, fft;
function setup() {
  createCanvas(710, 400);
  noFill();
  mic = new p5.AudioIn();
  mic.start();
  fft = new p5.FFT();
  fft.setInput(mic);
}
function draw() {
  background(200);
  let spectrum = fft.analyze();
  beginShape();
  for (i = 0; i < spectrum.length; i++) {
    vertex(i, map(spectrum[i], 0, 255, height, 0));
  }
  endShape();
}
X

creative commons license