No this is not related at all. Starting the oscillator based on a user action is a behaviour that you the programmer you are defining.
This function is just starting the oscillator and setting a boolean variable to true
. But those were defined in the code by Cassie and are not mandatory to start playing the sound.
For example this code works just fine without having to use an additional variable :
let osc;
function setup() {
createCanvas(400, 400);
osc = new p5.Oscillator("sawtooth");
osc.start();
}
function draw() {
background(600);
osc.freq(500);
osc.amp(0.5);
}
And I could define the user activation as follows :
Start playing the sound when the mouse is on the second half part of the canvas on the X direction
Which translates to this :
let osc;
function setup() {
createCanvas(400, 400);
osc = new p5.Oscillator("sawtooth");
osc.start();
}
function draw() {
background(600);
fill(0);
rect(0, 0, width / 2, height);
fill(255, 0, 0);
textSize(40);
if (mouseX > width / 2) {
text("Playing!!", 50, 50);
osc.freq(500);
osc.amp(0.5);
} else {
text("Not playing", 50, 50);
osc.amp(0);
}
}
Here I defined the condition I needed to play the oscillator based on some user input but you can change it to whatever you want : in your case when the distance between two points on the mouth is greater than some value
Is it more clear?