<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />
</head>
<body>
<div id="target"></div>
<!-- <script src="sketch.js"></script> -->
</body>
</html>
html, body {
margin: 0;
padding: 0;
}
/* PDM Course: Sound Unit
Remake Tone.NoiseSynth
see: https://tonejs.github.io/docs/r13/NoiseSynth
*/
let synth;
let delay;
let totalTime = 2;
let pitchShift;
let event;
let button;
// TODO: make this cooler
function setup() {
instrument = make_Instrument();
synth = instrument.instrument;
pitchShift = instrument.effect1;
event = new Tone.ToneEvent(
(time, note) => {
pitchShift.wet.rampTo(1, totalTime);
// pitchShift.feedback.setValueCurveAtTime([0.2,0.5,0.1, 0.01, 0.6],Tone.now(), totalTime )
pitchShift.windowSize = random(0.01, 0.5);
synth.envelope.attack = random(0.001, 0.01);
synth.envelope.release = random(0.1, 0.3);
synth.triggerAttackRelease(totalTime);
}
);
//loop it every measure for 8 measures
event.loop = 16;
event.loopEnd = totalTime;
event.playbackRate = 3;
event.probability = 0.7;
console.log(delay);
button = createButton("start");
button.position(20, 20);
button.mousePressed(() => event.start());
Tone.Transport.start();
}
function draw() {}
function make_Instrument() {
// create synth
var instrument = new Tone.NoiseSynth();
var synthJSON = {
noise: {
type: "white",
playbackRate: 5
},
envelope: {
attack: 0.001,
decay: 0.3,
sustain: 0,
release: 0.3
}
};
instrument.set(synthJSON);
var effect1, effect2, effect3;
// create effects
var effect1 = new Tone.PitchShift();
effect1JSON = {
pitch: 7,
windowSize: 0.5,
delayTime: 0.2,
feedback: 0.5,
wet: 0.5
};
effect1.set(effect1JSON);
// make connections
instrument.connect(effect1);
effect1.connect(Tone.Destination);
// define deep dispose function
function deep_dispose() {
if (effect1 != undefined && effect1 != null) {
effect1.dispose();
effect1 = null;
}
if (effect2 != undefined && effect2 != null) {
effect2.dispose();
effect2 = null;
}
if (effect3 != undefined && effect3 != null) {
effect3.dispose();
effect3 = null;
}
if (instrument != undefined && instrument != null) {
instrument.dispose();
instrument = null;
}
}
return {
instrument: instrument,
effect1,
deep_dispose: deep_dispose
};
}
This Pen doesn't use any external CSS resources.