Skip to content

Instantly share code, notes, and snippets.

@NHQ
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save NHQ/4c066eafdcfad55acf8a to your computer and use it in GitHub Desktop.

Select an option

Save NHQ/4c066eafdcfad55acf8a to your computer and use it in GitHub Desktop.
jsynth zerone syncopation module
master = new AudioContext
jsynth = require('jsynth')
nvelope = require('nvelope')
jigger = require('jigger')
generator = new jigger()
oscillators = require('oscillators');
sync = require('jsynth-zerone') // jsynth-zerone
bpm = 72
f = 399
timer = sync(bpm, master.sampleRate)
generators = [];
beatmath = require('beatmath')
onbeat = beatmath(4, [7, 8])
unswing = false
t0 = timer.on(1/2, [,[,,1,,],[,,,,,,,,,,1],[,,,,1],[,,,,],0,[1,0,0,,,,],], function(ti, b, off, swing){
console.log('major beat is %d', b)
if(unswing){
swing(0)
}
var x = onbeat(b)
if(x)
{
swing(4/5)
unswing = true
}
var attack = [[0,0], [0,1], [1,1]]
var release = [[0,1], [0,0], [1, 0]]
var y = b % 2 == 1 ? 1 : 1/2
var durations = [.02, bpm / 60 * y ]
var amod = {}
amod.curves = [attack, release];
amod.durations = durations;
var mod = nvelope(amod.curves, amod.durations);
var synth = function(t){
return oscillators.sine(t, f*2*(y)) * mod(t - ti)
}
generator.set(ti, synth, amod)
})
synth = function(t, s, i){
timer.tick.call(timer, t)
return generator.tick(t, s, i)
}
dsp = jsynth(master, synth)
dsp.connect(master.destination)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment