open-audiovisual
Search GitHub

oav-p5 reference · Loading options

drumlatency#

optionoav-p5
?oav_drumlatency=auto | 0 to 500 (milliseconds)

How long it takes a drum hit to be heard after oav-p5 hands it to the audio clock, so pictures land with the sound: auto or milliseconds.

The drum machine hands each hit to the audio clock slightly ahead of time, and tells the sketch (drumHit(), kickDetected(), env('kick')) when you will hear it, which is the scheduled moment plus the output latency. auto uses the latency the browser reports. If the browser's figure is smaller than what your output really takes, the picture runs ahead of the sound, and giving the number yourself fixes that. The project's README names a Bluetooth speaker as the case and suggests trying 200.

Type
String | Number
Values
auto | 0 to 500 (milliseconds)
default
auto

A number is held between 0 and 500. Anything that is not a number means auto. OAVp5.options.drumlatency reads back in seconds (0.2 for 200).

Notes

  • Only the default drum machine (drums=lookahead) uses it: the frame-driven one has nothing scheduled ahead.
  • Set it before oav-p5 loads. window.OAV_P5 = { drumlatency: … }; above the loader line wins, then ?oav_drumlatency=… on the page address, then ?drumlatency=… 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_drumlatency=… (the project's README says OpenProcessing forwards it to the sketch).

Examples

jsOpenProcessing ↗
window.OAV_P5 = { drumlatency: 200 };

function setup() {
  createCanvas(400, 300);
  startDrums('bd*4, [~ sd]*2, hh*8', 108);
}

function draw() {
  background(20);
  fill(255);
  text('drumlatency: ' + OAVp5.options.drumlatency + ' s', 20, 30);
  circle(width / 2, height / 2, 50 + env('kick', 0.01, 0.3) * 200);   // told 0.2 s after the hit is scheduled
}
The circle swells on each kick, told 200 milliseconds after the hit was handed to the audio clock, to match a speaker that is that late. Click the canvas once if you hear nothing.

To be confirmed

No Bluetooth speaker was tried: the suggested 200 comes from the project's README, not from a measurement made for this page.

Related

  • drums How the drum machine is clocked: lookahead (hits scheduled ahead on the audio clock) or frame (moved by animation frames, 0.5's way).
  • 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.
  • drumHit() An event you define: it is called for every hit of the drum machine, with the drum that sounded and how hard.
  • env() A 0..1 pulse that jumps up after each event (a kick, a beat, a key, a press) and then fades out: TouchDesigner's Trigger CHOP.

p5/oav-p5.js, line 135

↑ Back to top · All names