xxxxxxxxxx
52
var synth;
var synthScale;
synth = new Tone.PolySynth({
"volume": -10,
"envelope": {
"attack": 0.1,
"decay": 0.3,
"release": 2,
}
}).toMaster();
synthScale = ["C2", "E2", "G2", "A2",
"C3", "D3", "E3", "G3", "A3", "B3",
"C4", "D4", "E4", "G4", "A4", "B4", "C5"
];
Tone.Transport.bpm.value = 40;
var synthLoop = new Tone.Event(loopCallback, "16n");
synthLoop.loop = true;
synthLoop.loopEnd = "16n";
function loopCallback(time) {
// Drone
synth.triggerAttackRelease("C2", "4n", time, 0.7);
// Upper melody
// Pick a random note from the scale
var pos = floor(random(0, synthScale.length));
var currentNote = synthScale[pos];
var velocity = 0.4 + Math.random() * 0.5;
var probability = 0.9;
if (random() < probability) { // Stay silent sometimes
synth.triggerAttackRelease(currentNote, "16n", time, velocity);
}
}
function setup() {
synthLoop.start(0);
//synthLoop.start("2n");
Tone.Transport.start();
}
function draw() {
}