From 6633d535f44667aa710b5c273c8df0c1655d5dca Mon Sep 17 00:00:00 2001 From: Peter Kagstrom Date: Mon, 30 Dec 2024 08:34:53 -0500 Subject: [PATCH] Added button to start audio Needed due to audio context requiring interaction before browser will let audio pass --- src/sketch.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/sketch.js b/src/sketch.js index 696348e..ded06ee 100644 --- a/src/sketch.js +++ b/src/sketch.js @@ -15,8 +15,11 @@ function setup() { createCanvas(windowWidth, windowHeight); fft = new p5.FFT(); mic = new p5.AudioIn(); - mic.start() - mic.connect(fft); + + // Create a button and attach an event listener + let startButton = createButton('Start Audio'); + startButton.position(10, 10); + startButton.mousePressed(startAudio); textAlign(CENTER); @@ -107,6 +110,11 @@ function setup() { } +function startAudio() { + mic.start(); + mic.connect(fft); +} + function draw() { background(0);