open-audiovisual
Search GitHub

oav-p5 reference · Microphone and audio analysis

bass#

variableoav-p5
bass

Also: mid treble

How much of the microphone's sound is low (bass), middle (mid) or high (treble), each from 0 to 1.

Use them like micLevel, one number per band: fill(200 + bass * 160, 70, 100) pushes the colour with the low end. The three share one entry because they behave the same; only the frequency range differs.

Unlike micLevel they are not measured in decibels: each is the average strength of the frequencies in its band, scaled by micSensitivity() and held to 1. A band that is faint in your room can stay close to 0; raise the sensitivity rather than multiplying by a large number.

Type
Number
Range
0..1

The energy in 20–250 Hz (bass), 250–2000 Hz (mid) and 2000–8000 Hz (treble). Updated once per display frame while the microphone is on; 0 otherwise.

Before it has a value

Reading any of them asks for the microphone the first time, exactly like micLevel; until you allow it they are 0.

Notes

  • A sketch that already has its own variable, function or library called bass, mid or treble keeps it: oav-p5 leaves that name alone and never starts the microphone for it. Assigning one later turns the name back into a plain variable.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  colorMode(HSB, 360, 100, 100);
}

function draw() {
  background(230, 40, 10);
  fill(200 + bass * 160, 70, 100);   // low sounds push the colour toward magenta
  circle(width / 2, height / 2, 80 + bass * 220);
}
A circle that swells and changes colour with the low end: tap the desk or play something with a kick. Asks for the microphone
jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  noStroke();
}

function draw() {
  background(20);
  const bands = [bass, mid, treble];
  for (let i = 0; i < 3; i++) {
    fill(255, 80 + i * 70, 120);
    rect(60 + i * 110, height - 20, 80, -20 - bands[i] * 240);
  }
}
Three bars, one per band, from low to high. Whistle for the right one, hum for the left. Asks for the microphone

To be confirmed

Typical values for speech and for music depend on the microphone and the room; no typical numbers are given here until they have been measured.

Related

  • micLevel How loud the microphone hears things, from 0 (a quiet room) to 1 (shouting).
  • beat True for one frame each time the microphone (or the drum machine) hears a beat.
  • micSensitivity() Makes the microphone more or less sensitive: micSensitivity(2) is twice as sensitive, micSensitivity() says what it is now.
  • kickDetected() You define these; oav-p5 calls them when the microphone (or the drum machine) hears a kick, a snare or a hat.

p5/oav-p5.js, line 1045

↑ Back to top · All names