using while with sound library (micLevel) causes baffling freezes

This code freezes/crashes every time I run it & make a loud sound. In my sound environment, micLevel is returning values around .01 most of the time, so the while condition should return FALSE most of the time. Is this a bug? Or some audio issue? Or am I obliviously doing something dumb? Thanks for any help!

var mic; var micLevel;

function setup() { createCanvas(500,500); mic = new p5.AudioIn() mic.start(); }

function draw() { background(127); micLevel = mic.getLevel(); text(micLevel, 10, 20); while (micLevel > .1) { micLevel = mic.getLevel(); //this line doesn't seem to update micLevel variable. text(micLevel, 10, 20); } }


    • In JS, most programs run under 1 thread only. :-B
    • It means if the end of draw() is never reached, p5.AudioIn::getLevel() won't get updated! :-&
    • And your while () loop is gonna get stuck "forever"! :-SS
Sign In or Register to comment.