<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />
<script src="sketch.js"></script>
</head>
<body>
</body>
</html>
html, body {
margin: 0;
padding: 0;
}
/* PDM Course: Sound Unit
Remake Tone.NoiseSynth
see: https://tonejs.github.io/docs/r13/NoiseSynth
*/
var synth;
var delay;
var totalTime = 7
var instrument;
function setup() {
instrument = make_Instrument()
synth = instrument.instrument;
delay = instrument.effect3;
console.log(delay)
button = createButton('start')
.mousePressed(() => {
delay.feedback.rampTo(0.99, totalTime)
synth.frequency.rampTo(40, totalTime)
synth.modulationIndex.setValueCurveAtTime([10, 40, 20, 4, 3],Tone.now(), totalTime )
synth.harmonicity.setValueCurveAtTime([3, 4, 5, 10, 20],Tone.now(), totalTime )
synth.triggerAttackRelease('c4', totalTime)
})
}
function draw() {
}
function make_Instrument() {
// create synth
var instrument = new Tone.FMSynth();
var synthJSON = {
"harmonicity": 0.5,
"modulationIndex": 1.2,
"oscillator": {
"type": "fmsawtooth",
"modulationType" : "sine",
"modulationIndex" : 20,
"harmonicity" : 3
},
"envelope": {
"attack": 0.05,
"decay": 0.3,
"sustain": 0.1,
"release": 1.2
},
"modulation" : {
"volume" : 0,
"type": "triangle"
},
"modulationEnvelope" : {
"attack": 0.35,
"decay": 0.1,
"sustain": 1,
"release": 0.01
}
};
instrument.set(synthJSON);
var effect1, effect2, effect3;
// create effects
var effect1 = new Tone.JCReverb();
effect1JSON = {
"roomSize" : 0.8,
"wet": 0.5
};
effect1.set(effect1JSON);
var effect3 = new Tone.FeedbackDelay();
effect3JSON = {
"delayTime" : "64n",
"feedback" : 0.7,
"wet": 0.5
};
effect3.set(effect3JSON);
// make connections
instrument.connect(effect1);
effect1.connect(effect3);
effect3.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,
effect3
};
}
This Pen doesn't use any external CSS resources.