open-audiovisual
Search GitHub

oav-p5 reference · Loading options

mic#

optionoav-p5
?oav_mic=auto | click | off

Who may turn the microphone on: auto (the first read of micLevel and friends), click (only 🎤 or startMic()) or off (nobody).

With auto, the first time a sketch reads micLevel, bass, mid, treble or beat, oav-p5 asks the browser for the microphone. With click, reading them does nothing: the microphone starts only when someone presses 🎤 in the 🎹 panel or the sketch calls startMic(), so the permission prompt arrives when you choose. With off, nothing opens the microphone, not even startMic(), which resolves false.

off is a promise to the page: a gallery piece that must never listen can say so. click is for pieces where a permission prompt out of nowhere would be rude, or where the sound only matters after an intro. The values of the microphone stay 0 while it is off.

Type
String
Values
auto | click | off
default
auto

Anything else means auto.

Notes

  • Set it before oav-p5 loads. window.OAV_P5 = { mic: … }; above the loader line wins, then ?oav_mic=… on the page address, then ?mic=… on the script's own URL. Values in window.OAV_P5 are turned into text, so write 'off', not false. On OpenProcessing the page address takes ?sketch_oav_mic=… (the project's README says OpenProcessing forwards it to the sketch).

Examples

jsOpenProcessing ↗
window.OAV_P5 = { mic: 'click' };

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

function mousePressed() {
  startMic();   // now the browser asks
}

function draw() {
  background(20);
  circle(width / 2, height / 2, 50 + micLevel * 300);   // reading micLevel no longer asks
  fill(255);
  text('microphone: ' + OAVp5.mic.state + ' (click the canvas to start it)', 20, 30);
}
Reading micLevel does not ask for the microphone: the state stays "off" and the circle stays small. Click the canvas and the browser asks. Asks for the microphone
jsOpenProcessing ↗
window.OAV_P5 = { mic: 'off' };

let answer = 'click the canvas to try';

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

function mousePressed() {
  startMic().then((ok) => { answer = 'startMic() resolved ' + ok; });
}

function draw() {
  background(20);
  fill(255);
  text('microphone: ' + OAVp5.mic.state, 20, 30);
  text(answer, 20, 60);   // startMic() resolved false
}
Nothing can open the microphone: the state stays "off" and startMic() resolves false.

To be confirmed

Not tried on openprocessing.org itself: that ?sketch_oav_mic=click on the page address reaches the sketch.

Related

  • micLevel How loud the microphone hears things, from 0 (a quiet room) to 1 (shouting).
  • 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.
  • OAVp5.mic.state Where the microphone is: 'off', 'asking', 'on', 'denied' or 'unavailable'.
  • micIsOn Whether the microphone is running right now.

p5/oav-p5.js, line 128

↑ Back to top · All names