kickDetected()#
eventoav-p5function kickDetected(level) {}Also: snareDetected hatDetected
You define these; oav-p5 calls them when the microphone (or the drum machine) hears a kick, a snare or a hat.
The microphone splits what it hears into three drum-like bands and calls the matching function when each band jumps: 20–120 Hz for the kick, 150–800 Hz for the snare, 6–14 kHz for the hat. There is no machine learning in it, just a transient in a frequency band, so a bass voice can trigger a kick.
When the drum machine plays, each of its hits calls the same functions: kick for the kick, snare for a snare, clap or rim, hat for a closed, open or pedal hat. A sketch written for the microphone therefore works with startDrums() unchanged.
While the drum machine plays, only its hits call these functions (from oav-p5 0.8.1). A microphone that is on at the same time mostly hears the drums coming out of the speakers, so its hits would call the same function twice and hear a kick as a snare. micLevel, bass, mid and treble still follow the microphone; the microphone's hits come back when the drums stop.
Before it has a value
Defining one of them is not enough to open the microphone once the drum machine has started; reading micLevel (or calling startMic()) is. Without the drum machine, a sketch that defines any of them and reads nothing starts the microphone on the first click or key.
Parameters
| Name | Type | Description |
|---|---|---|
level | Number | How strong the hit was, 0..1 (for the drum machine, its velocity). |
Examples
let kick = 0, snare = 0;
function setup() {
createCanvas(400, 300);
noStroke();
}
function kickDetected(level) { kick = level; }
function snareDetected(level) { snare = level; }
function draw() {
background(20);
fill(255, 90, 31);
circle(120, 150, 40 + kick * 160);
fill(120, 190, 255);
circle(280, 150, 40 + snare * 160);
kick *= 0.9;
snare *= 0.9;
}Related
beatDetected()You define this function; oav-p5 calls it each time the microphone (or the drum machine) hears a beat.beatTrue for one frame each time the microphone (or the drum machine) hears a beat.bassHow much of the microphone's sound is low (bass), middle (mid) or high (treble), each from 0 to 1.startDrums()Starts a drum machine: a 16-step grid on the page that plays a preset, your own grid or one line of rhythm, and counts the bars for your sketch.