Skip to content

Commit

Permalink
Added button to start audio
Browse files Browse the repository at this point in the history
Needed due to audio context requiring interaction before browser will let audio pass
  • Loading branch information
subcontrabass committed Dec 30, 2024
1 parent d8ff7f7 commit 6633d53
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -107,6 +110,11 @@ function setup() {

}

function startAudio() {
mic.start();
mic.connect(fft);
}

function draw() {
background(0);

Expand Down

0 comments on commit 6633d53

Please sign in to comment.