Created
March 29, 2014 20:42
-
-
Save coleww/9862589 to your computer and use it in GitHub Desktop.
probabilistic web audio drum machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var samples = { | |
kick: new Wad({source: '/samples/kick.wav'}), | |
chh: new Wad({source: '/samples/chh.wav'}), | |
snare: new Wad({source: '/samples/snare.wav'}), | |
ohh: new Wad({source: '/samples/ohh.wav'}), | |
cym: new Wad({source: '/samples/cym.wav'}), | |
shkr: new Wad({source: '/samples/shkr.wav'}), | |
ltom: new Wad({source: '/samples/ltom.wav'}), | |
mtom: new Wad({source: '/samples/mtom.wav'}), | |
htom: new Wad({source: '/samples/htom.wav'}), | |
clap: new Wad({source: '/samples/clap.wav'}) | |
}; | |
var drums = { | |
kick: [1, 0.3, 0.3, 0.1, 1, 0.3, 0.3, 0.1, 1, 0.3, 0.3, 0.1, 1, 0.3, 0.5, 0.3], | |
chh: [0.5, 0.5, 0.3, 0.5, 0.5, 0.5, 0.3, 0.5, 0.5, 0.5, 0.3, 0.5, 0.5, 0.5, 0.3, 0.5], | |
snare: [0.1, 0.1, 0.3, 0.1, 0.7, 0.1, 0.3, 0.1, 0.1, 0.1, 0.3, 0.1, 0.7, 0.1, 0.3, 0.1], | |
ohh: [0.1, 0.1, 0.5, 0.1, 0.1, 0.1, 0.5, 0.1, 0.1, 0.1, 0.5, 0.1, 0.1, 0.1, 0.5, 0.1], | |
cym: [0.3, 0.1, 0.2, 0.1, 0.1, 0.1, 0.3, 0.1, 0.2, 0.1, 0.3, 0.1, 0.3, 0.3, 0.3, 0.3], | |
shkr: [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3], | |
ltom: [0.2, 0.2, 0.1, 0.1, 0.2, 0.2, 0.1, 0.1, 0.3, 0.2, 0.1, 0.1, 0.3, 0.5, 0.3, 0.1], | |
mtom: [0.1, 0.1, 0.2, 0.2, 0.1, 0.2, 0.1, 0.2, 0.1, 0.3, 0.2, 0.3, 0.5, 0.3, 0.1, 0.1], | |
htom: [0.1, 0.2, 0.2, 0.1, 0.2, 0.1, 0.2, 0.1, 0.2, 0.1, 0.3, 0.2, 0.3, 0.3, 0.5, 0.3], | |
clap: [0.1, 0.1, 0.3, 0.1, 0.5, 0.1, 0.3, 0.1, 0.1, 0.1, 0.3, 0.1, 0.5, 0.1, 0.3, 0.1] | |
}; | |
var bpm = 140; | |
var intervalTime = 60000.0 / bpm; | |
var position = 0; | |
window.setInterval(function(){ | |
for(var drum in drums){ | |
if(Math.random() < drums[drum][position]){ | |
samples[drum].play(); | |
} | |
} | |
position++; | |
if(position >= 16) position = 0; | |
}, intervalTime); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uses WAD to load and play samples cuz I aint about to touch an audio context. https://github.com/rserota/wad | |
on each beat, the computer iterates over the drums, generates a random number, compares it to that drums probability for that beat, and plays the drum if it matches. | |
TODO: | |
teach computer how to generate new probabilities, perhaps by markov chaining MIDI files, or by hand writing a bunch and setting an algorithm loose on them. | |
figure out how to generate sick acid bass lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment