Random Thresh
Trigger some noise when the probability is below some threshold
by Eve Weinberg
HTML
<script src="https://tonejs.github.io/CDN/r6/Tone.min.js"></script>
<script src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
<button>HI
</button>
JavaScript
var delay = new Tone.FeedbackDelay(0.045, 0.8).toMaster();
var env = new Tone.AmplitudeEnvelope(0.001, 0.02, 0.0);
var noise = new Tone.Noise("pink").chain(env, delay).start(0);
var startTime = 3;
//returns a num btwn 0 and 1
//schedules them all right away, then it uses the first parameter for timing
for (var i = 0; i < 200; i++){
//ramp it up over time
if (Math.random() < i/200){
env.triggerAttack(i * 0.08+ startTime);
}
}
//or give it a 2nd parameter
//env.triggerAttack(x,Math.random()*0.5+0.5);
//start the noise right away and then the envelope is triggered
$("button").on('click', function(){
//var now = Tone.context
//time since reloading the page
var now = delay.now();
if (Math.random() < i/200){
//velocity is the 2nd parameter, and it scales everything, if velocity is .5 and sustain is .5, then sustain becomes .25
env.triggerAttack(i * 0.08+ now,Math.random()*0.5+0.5);
}
});