xxxxxxxxxx
41
// Play a three-over-two cross-rhythm
// Create a Players object and load the "kick.mp3" and "snare.mp3" files
var kit = new Tone.Players({
"kick": "samples/505/kick.mp3",
"snare": "samples/505/snare.mp3"
});
// Connect the player output to the computer's audio output
kit.toMaster();
// Set the tempo
Tone.Transport.bpm.value = 60;
// Create two loops for a three over two cross-rhythm
Tone.Transport.scheduleRepeat(playRhythm1, 1 / 3);
Tone.Transport.scheduleRepeat(playRhythm2, 1 / 2);
function playRhythm1() {
kit.get("kick").start();
}
function playRhythm2() {
kit.get("snare").start();
}
// Once all audio files have been loaded, start the Tone playhead
Tone.Buffer.on('load', start);
function start() {
Tone.Transport.start();
}
function setup() {
}
function draw() {
}