New issue
Advanced search Search tips

Issue 795318 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Jan 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux
Pri: 2
Type: Bug



Sign in to add a comment

Jagged time on AnalyserNode.getFloatTimeDomainData

Reported by mfc...@gmail.com, Dec 15 2017

Issue description

UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36

Steps to reproduce the problem:
1. Open jagged.html
2. Wait
3. Read the result

What is the expected behavior?
on 48000 Hz audio and 60 fps display, the result ideally should be:
delta sample = 800
delta sample = 800
delta sample = 800
delta sample = 800
...

What went wrong?
The result is jagged, updated only every 2048 samples:
delta sample = 2048
delta sample = 0
delta sample = 2048
delta sample = 0
delta sample = 0
delta sample = 2048
delta sample = 0
delta sample = 2048
delta sample = 0
delta sample = 0
delta sample = 2048
delta sample = 0
delta sample = 2048
delta sample = 0
delta sample = 0
delta sample = 2048
...

Did this work before? N/A 

Does this work in other browsers? N/A

Chrome version: 62.0.3202.94  Channel: n/a
OS Version: 
Flash Version: 

Firefox has better result, even it is still not ideal:
delta sample = 1024
delta sample = 896
delta sample = 1024
delta sample = 896
delta sample = 1024
delta sample = 0
...

This affects my audio visualization at https://mfcc64.github.io/html5-showcqtbar/

Thank's.
 
jagged.html
1.6 KB View Download

Comment 1 by rtoy@chromium.org, Dec 15 2017

I don't get this sequence of values. I see something like

delta sample = 768
delta sample 1024
delta sample 768
delta sample 768
delta sample 768
delta sample 768
delta sample 768
delta sample 768
delta sample 768
delta sample 1024

If you print out ctx.currentTime along with the delta values, you'll see that the the calls to render are usually 16 ms apart, but not always.  I see some that are 21.3 ms apart.

I think that is to be expected.  requestAnimationFrame doesn't guarantee that the calls are all exactly 16 ms apart.  They usually are, but not always.

And the delta value of 1024 at 48000 corresponds to 21.3 ms, as expected when the currentTime changes by 21.3 ms.

Comment 2 by mfc...@gmail.com, Dec 16 2017

I guess your chromium uses period_size 256, and mine uses 2048.
What OS/audio backend you use?

Note that I use alsa dmix output (with fixed audio period_size).
When I decrease period_size to 128 (previously it is 960). Here the result:
chromium:
delta sample = 2048
delta sample = 0
delta sample = 2048
delta sample = 0
delta sample = 0
delta sample = 2048
delta sample = 0
delta sample = 2048
...

firefox:
delta sample = 768
delta sample = 640
delta sample = 1024
delta sample = 768
delta sample = 768
delta sample = 896
...

Lowering period_size makes audio timing in firefox more accurate, but has no effect on my chrome (Seem that it uses fixed 2048 period_size).

Note that requestAnimationFrame is called nearly smooth at ~16ms (use performance.now())

So is it possible to decrease period_size?
Or better, is it possible that audio timing accuracy is not bound by period_size?

Thank's.

Labels: Needs-Milestone

Comment 4 by mfc...@gmail.com, Dec 17 2017

Audio buffer size is set to 2048 because of https://bugs.chromium.org/p/chromium/issues/detail?id=178626

Manually decreasing --audio-buffer-size makes delta samples more smooth.

--audio-buffer-size=2048
delta sample = 2048
delta sample = 0
delta sample = 0
delta sample = 2048
delta sample = 0
delta sample = 2048
delta sample = 0
delta sample = 0
delta sample = 2048
delta sample = 0

--audio-buffer-size=1024
delta sample = 1024
delta sample = 1024
delta sample = 1024
delta sample = 1024
delta sample = 0
delta sample = 1024
delta sample = 1024
delta sample = 1024
delta sample = 0

--audio-buffer-size=512
delta sample = 1024
delta sample = 1024
delta sample = 512
delta sample = 1024
delta sample = 512
delta sample = 1024
delta sample = 512
delta sample = 1024
delta sample = 512

--audio-buffer-size=256
delta sample = 1024
delta sample = 768
delta sample = 768
delta sample = 768
delta sample = 768
delta sample = 768
delta sample = 768
delta sample = 768
delta sample = 1024

--audio-buffer-size=128
delta sample = 896
delta sample = 768
delta sample = 768
delta sample = 768
delta sample = 896
delta sample = 768
delta sample = 768
delta sample = 768
delta sample = 896
delta sample = 768
delta sample = 768

Comment 5 by rtoy@chromium.org, Dec 18 2017

Status: Untriaged (was: Unconfirmed)
I was running the original tests on macos where the webaudio buffer size is 256.  On my Linux box (where the size is 512) I get:

delta sample = 0
delta sample = 511
delta sample = 512
delta sample = 1024
delta sample = 512
delta sample = 1024
delta sample = 512
delta sample = 512
delta sample = 1024
delta sample = 512
delta sample = 512
delta sample = 1024
delta sample = 1024
delta sample = 512

Better than what you see but similar to what you get with --audio-buffer-size=512.

Can I ask what the actual usecase is?  Are you really depending on the time data to be consistently increasing on each call?

I'm not sure if we can fix this completely since the animation clock and audio clock are almost always using different (unsynchronized) clocks which will drift.  This is what AudioContext.getOutputTimeStamp() is intended to solve.

Comment 6 by mfc...@gmail.com, Dec 19 2017

> Can I ask what the actual usecase is?

https://mfcc64.github.io/html5-showcqtbar/
With audio buffer size 2048, the animation looks jagged.

> Are you really depending on the time data to be consistently increasing on each call?

Not so. With audio buffer size 512, the animation looks smooth enough.
So, is it possible to decrease default audio buffer size to 256 or 512 (alsa)? Because it seems that https://bugs.chromium.org/p/chromium/issues/detail?id=178626 prohibited using small audio buffer.

>  This is what AudioContext.getOutputTimeStamp() is intended to solve.

Nice feature.
The result (w buffer size 2048):
delta sample = 792
delta sample = 815
delta sample = 796
delta sample = 822
delta sample = 791
delta sample = 797
delta sample = 757
delta sample = 796
delta sample = 839

but occasionally I get:
delta sample = 806
delta sample = 87
delta sample = 1533
delta sample = 803
delta sample = 799


jagged.html
1.8 KB View Download

Comment 7 by rtoy@chromium.org, Jan 5 2018

rAF operates at 16.6666 ms boundaries (probably alternates between 16.6 and 16.7 or so to average out to 16.6666...ms).  Let's assume we setup WebAudio to use 128 sample processing, the lowest possible.  Then each call to rAF is 2.1333... blocks.  Then the AnalyserNode will have either generated just 2 blocks usually or maybe 3 once in while.  The delta sample must vary; it can't be completely constant.

If you truly want consistency, you need to process "within" the audio graph, more or less.  This can be achieved using a ScriptProcessorNode or AudioWorkletNode where you can get the time domain data as it goes through the audio graph.  You'll have to synchronize this to rAF, but that is under your control, so you can do what's necessary.

I don't think you can do what you want with an AnalyserNode.  

Comment 8 by mfc...@gmail.com, Jan 8 2018

I don't need strict consistency. Lowering audio buffer is enough. Currently, I use alsa and set --audio-buffer-size=512. Audio works fine, I don't find audio clicking.

Comment 9 by rtoy@chromium.org, Jan 8 2018

I thought the default buffer size was already 512.

So everything is working ok?  (I'm not really sure what this bug is about anymore.)

Comment 10 by mfc...@gmail.com, Jan 8 2018

No, I use alsa without pulseaudio. The default buffer size is 2048. See  issue 178626 

Comment 11 by rtoy@chromium.org, Jan 8 2018

Cc: dalecur...@chromium.org
Hmm. I thought pulseaudio was a requirement, but perhaps not.

+dalecurtis for the definitive answer on that.
Pulse audio is not required, we will use ALSA w/o PulseAudio, but performance is generally quite bad (metrics show drastically increased glith counts), so the buffer size defaults to high.

Comment 13 by mfc...@gmail.com, Jan 9 2018

I don't hear glitch, even with --audio-buffer-size=128. Probably, performance of alsa now has been improved.  Issue 178626  was almost 4 years ago.

Comment 14 by rtoy@chromium.org, Jan 9 2018

I'll leave the buffer size issue for Alsa for dale to comment on.

But in this case, there's nothing really to be done here in terms of WebAudio, right?

Comment 15 by mfc...@gmail.com, Jan 10 2018

Right.

Comment 16 by rtoy@chromium.org, Jan 10 2018

Status: WontFix (was: Untriaged)
Filed  issue 800847  for the alsa buffer issue. I'll let Dale figure out what to do about that, if anything.

Based on c#15, closing this issue.

Sign in to add a comment