xxxxxxxxxx
83
let ready = false;
//------------------------------------------------------------
// Setup function
function setup() {
// Create a new canvas to match the browser size
createCanvas(windowWidth, windowHeight);
// Creating our sound
osc = new Tone.Oscillator()
// Connecting it to master out
osc.toDestination()
osc2 = new Tone.Oscillator()
osc2.frequency.value = 220
osc2.toDestination();
lfo = new Tone.LFO("0.1hz", 210, 230)
lfo.connect(osc.frequency)
Tone.Master.volume.value = -6
}
//------------------------------------------------------------
// On window resize, update the canvas size
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
//------------------------------------------------------------
// Main render loop
function draw() {
background(0);
// If the thing is ready
if (!ready) {
fill(255);
noStroke();
textAlign(CENTER, CENTER);
text("CLICK TO START", width / 2, height / 2);
}
}
//------------------------------------------------------------
// When mouse is pressed
function mousePressed() {
if (!ready) {
ready = true;
startAudio();
} else {
ready = false;
stopAudio();
}
}
//------------------------------------------------------------
// Audio functions
function startAudio() {
console.log("let's do this!")
// Start the oscillator
osc.start();
osc2.start();
lfo.start() // in startAudio()
}
function stopAudio() {
console.log("ok, stopping")
// Stop the oscillator
osc.stop()
osc2.stop()
lfo.stop()
}