wa-metro
Simple event scheduler for Web Audio API.
This library is based on Chris Wilson's scheduling method used in his metronome example.
Installation
You can install wa-metro
from npm.
npm install wa-metro
Or grab the latest version from build folder and include it in your html.
Example Usage
var context = ;var { //schedule audio events with time and step number};var metro = context callback;metrostart;
Callback
The callback function will have time
, step
and timeFromScheduled
parameters. You can use these values to create dynamic loops and animations.
Callback Parameters
time
- the audio time for the step which can be used to schedule audio events.step
- the number of the scheduled step.timeFromScheduled
- the time (in seconds) that the event will be triggered from the schedule event (time - context.currentTime
). This time can be used to schedule animations and other events as shown in the example below.
var metro = context callback; { var osc = context; osc; ifstep === 1 oscfrequencyvalue = 880; oscstarttime; osc; ;}
Methods
var metro = context callback;metrostart; // starts the clock and schedules eventsmetro; // stops the clock and resets the step to 1metro; // pauses the clock and keeps the current step number
Configuration
var metro = context callback;metrotempo = 100; // in BPM, defaults to 120metrosteps = 8; // number of steps in a bar. defaults to 16metrolook_ahead = 05; // look ahead time in Seconds. defaults to 1.0metro{}; // change the callback