micLevel#
variableoav-p5micLevel
How loud the microphone hears things, from 0 (a quiet room) to 1 (shouting).
Read it in draw() the way you read mouseX: circle(width / 2, height / 2, 50 + micLevel * 300) grows when someone talks. It is a loudness in decibels, which is how an ear hears it, measured from the room itself: the bottom of the scale follows the room's own noise (it settles within a second or two and rises at most 1.5 dB a second, so a voice never becomes the new silence), and −10 dBFS, shouting into a laptop, is 1.
In practice a quiet room reads 0, a quiet voice about 0.4 to 0.6, shouting close to 1. If the microphone is quiet or far away, raise it with micSensitivity().
It follows the browser's animation frames rather than draw(), so a sketch running at frameRate(10) still reads the latest value, and the number stops changing while the tab is hidden (browsers pause animation frames there).
- Type
Number- Range
0..1
Updated once per display frame while the microphone is on. It is 0 while the microphone is off, still asking, blocked or missing.
Before it has a value
Nothing to call. The first time a sketch reads micLevel (or bass, mid, treble, beat), oav-p5 asks the browser for the microphone, and every value stays 0 until you allow it. The page needs https or localhost. If the browser kept audio quiet until a click, the first click or key starts it. ?oav_mic=click makes only the 🎤 button and startMic() turn it on; ?oav_mic=off means nothing can.
Notes
- In the 🎹 panel the 🎤 button turns the microphone on and off by hand and shows the level. When the browser blocked it, a card beside the 🎹 says why and what to press: click the lock left of the address, set Microphone to Allow, then click the canvas.
- On openprocessing.org the sketch frame allows the microphone and MIDI (checked 2026-10-19: its
allowlist containsmicrophoneandmidi), and the first read ofmicLevelthere asks for the microphone. An embed code copied from OpenProcessing does not carry that: addallow="microphone"to that<iframe>. - The raw numbers behind it are
OAVp5.mic.rms(0..1),OAVp5.mic.dbandOAVp5.mic.floor(the room's own noise, in dBFS).
Examples
function setup() {
createCanvas(400, 300);
}
function draw() {
background(20);
circle(width / 2, height / 2, 50 + micLevel * 300);
}function setup() {
createCanvas(400, 300);
}
function draw() {
background(20);
const level = lag(micLevel, 0.03, 0.4); // opens fast, closes slowly
fill(255, 120 + level * 135, 60);
circle(width / 2, height / 2, 50 + level * 300);
}function setup() {
createCanvas(400, 300);
micSensitivity(3); // a quiet or far-away microphone
}
function draw() {
background(20);
fill(255);
if (!micIsOn) text('Allow the microphone, then make a sound', 20, 30);
rect(20, height - 40, micLevel * (width - 40), 20);
}To be confirmed
On openprocessing.org the pasted sketch runs, loads oav-p5 and asks for the microphone, but the sound itself was not tried there: the browser used for the check blocks the microphone, so the allow-and-listen step is still unconfirmed on that site.
Related
bassHow much of the microphone's sound is low (bass), middle (mid) or high (treble), each from 0 to 1.beatTrue for one frame each time the microphone (or the drum machine) hears a beat.micIsOnWhether the microphone is running right now.micSensitivity()Makes the microphone more or less sensitive:micSensitivity(2)is twice as sensitive,micSensitivity()says what it is now.startMic()Turns the microphone on and returns a promise that says whether it worked.lag()Followsvaluesmoothly instead of jumping: up inupseconds, down indownseconds (TouchDesigner's Lag CHOP).