xxxxxxxxxx
36
let startButton;
let stopButton;
const synth = new Tone.Synth().toDestination();
synth.oscillator.type = "sawtooth";
// Create a filter and set cutoff frequency and filter type
const filter = new Tone.Filter(500, "lowpass")
// Pass our synth into the filter
synth.chain(filter);
// Connect the filter to the output
filter.toDestination();
function setup() {
createCanvas(400, 400);
startButton = createButton("make noise!");
stopButton = createButton("stop noise!");
startButton.mousePressed(makeNoise);
stopButton.mousePressed(stopNoise);
textSize(24);
}
function draw() {
background('coral');
strokeWeight(2);
drawAmplitude();
}
function makeNoise() {
Tone.start();
synth.triggerAttack("C4", "8n");
}
function stopNoise(){
synth.triggerRelease()
}