open-audiovisual
Search GitHub

oav-p5 reference · Microphone and audio analysis

OAVp5.mic#

objectoav-p5
OAVp5.mic

The microphone under the plain names: its state, the numbers of micLevel and bass that never turn it on when read, the raw loudness, start, stop and events.

Everything the microphone names (micLevel, bass, micIsOn, startMic() …) read from here. The difference is that reading OAVp5.mic.level never asks for the microphone: the plain micLevel does, the first time. So OAVp5.mic is for code that must look without waking anything: a status line, a library, a sketch with ?oav_mic=click.

The members: state, error, sensitivity (also gain), level, bass (also mid, treble), rms, db, floor, analyzer, start(), stop() and on().

Notes

  • This is advanced. For most sketches the plain names are all you need.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
}

function mousePressed() {
  if (OAVp5.mic.state === 'on') OAVp5.mic.stop(); else OAVp5.mic.start();
}

function draw() {
  background(20);
  fill(255);
  text('microphone: ' + OAVp5.mic.state + ' (click the canvas to switch it)', 20, 30);   // reading this asks for nothing
  circle(width / 2, height / 2, 50 + OAVp5.mic.level * 300);
}
A circle that follows the microphone, which only starts when you click: reading OAVp5.mic never turns it on by itself. Asks for the microphone

Related

  • micLevel How loud the microphone hears things, from 0 (a quiet room) to 1 (shouting).
  • bass How much of the microphone's sound is low (bass), middle (mid) or high (treble), each from 0 to 1.
  • micIsOn Whether the microphone is running right now.
  • startMic() Turns the microphone on and returns a promise that says whether it worked.
  • stopMic() Turns the microphone off and sets every microphone value back to 0.
  • mic Who may turn the microphone on: auto (the first read of micLevel and friends), click (only 🎤 or startMic()) or off (nobody).

p5/oav-p5.js, line 910

↑ Back to top · All names