syncopator for audio scripting
see also the example
The constructor requires beatsPerMinute and SampleRate values.
var sync = require'jsynth-sync';var timer = sync72 8000 // 72 bpm, samplRate 8000 (8k samples per second)var t = timeron1// do something every beatvar i = timeron1/2// do something every half beattimertickapplytimer arguments;
timer will call fn every beatValue. the return of sync.on() is a function which clears fn from being called any more. Your function will be called with the actual clock time of the call, a count for the beatValue, and a function you can call to clear the current call for good.
var quarter = syncon1/4// do something every quarter-beat// beatCount is the # of times this beatValue has been called.ifbeatCount % 4 == 0 // only do something every 4th quarter beatifforSomeReason clear // clear the timer//new!// the siwng function allows you to have the next beat (or all beats)// changed to a new intervaliftrue swingintervalelse iftrue swing0 // you must set it back manuallysetTimeoutquarter // clears it4000
###timer.tick() Timer tick does not require any arguments, but will pass them on to your function. Simply call it for every sample.
###timer.clearAll() clear all the timered functions