xxxxxxxxxx
43
// Create a Player object and load the "kick.mp3" file
var kick = new Tone.Player("samples/505/kick.mp3");
// Connect the player output to the computer's audio output
kick.toMaster();
// Set the tempo / speed, which is measured in 'beats per minute', or bpm.
// Try setting the bpm to different values
Tone.Transport.bpm.value = 120;
// Our speed is now 120 beats per minute = 2 beats per second.
// --> each beat lasts 0.5 seconds.
// --> quarter note duration is set to 0.5 seconds
// (by default, Tone sets the time signature to be 4/4.
// the denominator says that the duration of the beat is the duration of a quarter note)
// Create a loop: call the function playBeat every quarter note
// "4n" stands for quarter note. Try replacing "4n" with "2n", "8n", "16n"
Tone.Transport.scheduleRepeat(playBeat, "4n");
// See documentation here: https://github.com/Tonejs/Tone.js/wiki/Time
function setup() {
}
function draw() {
}
// Audio playback loop
function playBeat(){
// Play sound file
kick.start();
}
// Once all audio files have been loaded, start the Tone playhead
Tone.Buffer.on('load', start);
function start() {
Tone.Transport.start();
}