p5.js-sound icon indicating copy to clipboard operation
p5.js-sound copied to clipboard

getLevel() seems broken in Firefox

Open ffd8 opened this issue 4 years ago • 14 comments

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.

ffd8 avatar Jul 02 '20 21:07 ffd8

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!

6160 avatar Jul 03 '20 09:07 6160

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 avatar Jul 03 '20 10:07 marcvinyals

@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

6160 avatar Jul 03 '20 10:07 6160

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

image

This is on the last 1.1.9 version

mastrolinux avatar Aug 14 '20 13:08 mastrolinux

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.

GrindSC avatar Oct 28 '20 23:10 GrindSC

The issue still remains :(

lorforlinux avatar Dec 03 '20 20:12 lorforlinux

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).

lee2sman avatar Dec 10 '20 20:12 lee2sman

Error still exists :(

polyclick avatar Feb 03 '21 10:02 polyclick

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

seloman avatar Feb 05 '21 14:02 seloman

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.

xxristoskk avatar Mar 20 '21 19:03 xxristoskk

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)

micuat avatar Apr 14 '21 17:04 micuat

It seems to work fine with my local server without throwing any errors.

Ajaya1000 avatar May 08 '21 05:05 Ajaya1000

Just bumped into this issue - same one @mastrolinux described, but on Firefox as per OP.

Spaxe avatar Jun 24 '21 00:06 Spaxe

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.

markhillard avatar Dec 15 '21 05:12 markhillard