p5.js-sound
p5.js-sound copied to clipboard
getLevel() seems broken in Firefox
As mentioned in the Processing forum, Firefox is returning a strange error while using latest 0.3.12 of p5.sound (Safari + Chrome have no issue).
I think it's connected to getLevel()
(atleast that's where I found an issue) which spits out the following in the console while failing quietly:
TypeError: arraySequence[0] is undefined
d61d3f9d-b5ac-454b-8467-3a64cd0eac11:75:28
push blob:http://localhost:5000/d61d3f9d-b5ac-454b-8467-3a64cd0eac11:75
process blob:http://localhost:5000/d61d3f9d-b5ac-454b-8467-3a64cd0eac11:193
TypeError: arraySequence[0] is undefined58fd29c4-ce33-1b40-928b-80e670217935:75:28
push blob:http://localhost:5000/58fd29c4-ce33-1b40-928b-80e670217935:75
process blob:http://localhost:5000/58fd29c4-ce33-1b40-928b-80e670217935:170
Here's a quick sketch to test it. Loading the latest version of p5.sound, which if switched back to CDN of 0.3.11 has no issue.
I think this is an issue with the mic input.
I'm currently using the getLevel
method of p5.Amplitude for getting the level of a SoundFile
and it's working fine.
You can see it working here: https://editor.p5js.org/6160/sketches/1bN8O4gl0
BTW i've tried on an old version of FF and it was working but don't know which version, it autoupdates itself before i was able to check!
I believe the issue ultimately lies with the three classes implementing AudioWorkletProcessor
, and in particular AmplitudeProcessor
. That class is required for p5.Amplitude
to work properly, hence the error.
More precisely, the problem is that the process
method in these three classes assumes that inputs[0]
is not empty, but in fact inputs[0]
can be empty if there are no "actively processing AudioNodes" (see https://webaudio.github.io/web-audio-api/#dom-audioworkletprocessor-process-inputs-outputs-parameters-inputs). I did not read on what the condition means, why it changed between Firefox versions, and whether the old or new implementation was correct.
A way to fix the issue (maybe not the best) is to add a check if (input.length == 0) return false;
near the top of each of the three process
functions. (Note this is input, not inputs).
@6160 Have you tried your code on a standalone webpage with the latest p5.sound?
@marcvinyals oh my bad, you're right! i was using 0.3.11 for my current project and there's no issue with that version. i thought i was on 0.3.12
I have a very similar issue, now reproducing on Edge Dev and Chrome
Microsoft Edge | 86.0.601.1 (Official build) dev (64-bit)
https://github.com/processing/p5.js-sound/blob/f62093213536851cc9554ddf2ef6eec5f0ddeb19/src/audioWorklet/ringBuffer.js#L66 I have arraySequence being undefined
This is on the last 1.1.9 version
I haven't tried it with microphone but when i had same issue with the song (play song from user input), based on what marcvinyals said, i've create instance of 'p5.Amplitude()' after song was already playing, instead of putting it after loadSound function. It seemed to solve the problem in that case and getLevel() started to work properly. Sorry if it's not helpfull in your case.
The issue still remains :(
Hi, I'm getting the same issue on Firefox and Chrome.
I tried to follow @GrindSC 's suggestion but still wouldn't work for me.
Minimal example here. Code is largely the same as the example p5.Amplitude example (which doesn't work for me on these browsers either anymore).
Error still exists :(
I'm experience the same issue in Firefox with getLevel(): TypeError: arraySequence[0] is undefined Here's a code example: https://codepen.io/selohrmann/pen/zYKQZyQ
Also having an issue with this where getLevel() always returns zero in Firefox. The example code on the reference page (https://p5js.org/reference/#/p5.Amplitude/getLevel) doesn't work. Seems to work fine in Chrome.
Interestingly on firefox it doesn't work, and while chrome outputs the same undefined
error, it still processes the data and returns desired output (tested on windows 10)
It seems to work fine with my local server without throwing any errors.
Just bumped into this issue - same one @mastrolinux described, but on Firefox as per OP.
Ran into this issue as well in Firefox 96. I have a demo that I was updating the p5 dependencies on and after some trial and error I found that the latest version of p5 that actually works is 0.10.2, which is the release just before 1.0.0.