bass#
variableoav-p5bassAlso: 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,midortreblekeeps 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
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);
}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);
}
}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
micLevelHow loud the microphone hears things, from 0 (a quiet room) to 1 (shouting).beatTrue 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.