AudioBufferSourceNodes scheduled in a sequence aren't seamless even when their sample rate matches context

RESOLVED FIXED in mozilla30

Status

()

Core
Web Audio
P1
normal
RESOLVED FIXED
4 years ago
4 years ago

People

(Reporter: karlt, Assigned: karlt)

Tracking

28 Branch
mozilla30
x86_64
Linux
Points:
---
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(6 attachments, 1 obsolete attachment)

(Assignee)

Description

4 years ago
It is expected that AudioBufferSourceNodes having sample rates matching that
of the AudioContext and scheduled in sequence with start times differing by
the buffer duration will play seamlessly.

However, the double parameter representing start time in seconds is rounded
to MediaTime values before rounding to the nearest tick.
This means that the nearest tick rounding is not necessarily the nearest tick.
MediaTime is in seconds with 20 fractional bits providing a resolution of
about 22 parts per 48kHz sample interval.
For an arbitrary starting time, there is about a 1/22 chance of it leading to
adjacent buffers being rounded in different directions.

double variables don't have infinite precision, but even after an AudioContext
has been running for a day, a double seconds parameter still has a resolution
of 2^53/48000/60/60/24 ≅ two million fractional parts per 48kHz sample
interval.
(Assignee)

Comment 1

4 years ago
Created attachment 8375960 [details]
testcase

This schedules 1-sample buffers in sequence at an offset to generate the problem.

Expected result: a horizontal line.
Actual: the graph oscillates up and down as buffers interfere.
(Assignee)

Comment 2

4 years ago
Created attachment 8375999 [details] [diff] [review]
move stream time methods from WebAudioUtils to AudioNodeStream

Trying to clear up which stream parameter is which.
Attachment #8375999 - Flags: review?(paul)
(Assignee)

Comment 3

4 years ago
Created attachment 8376002 [details] [diff] [review]
round double times to ticks consistently and round to nearest

RoundUp came from 
http://hg.mozilla.org/mozilla-central/rev/ba325c53d773
but we're asking for this problem to happen if we round points infinitesimal distances from one tick to another tick.
Attachment #8376002 - Flags: review?(paul)
(Assignee)

Comment 4

4 years ago
Created attachment 8376005 [details]
modified testcase showing remaining issue

It is still possible to generate the same problem if aiming for the rounding cliff, but now the timing needs to be within the precision of doubles to do so.

Nodes will usually be scheduled on times offset from zero, or from times provided by WebAudio such as currentTime.  currentTime should be near a tick, so rounding to nearest should work well.

There is still a chance of falling mid-way between ticks if an offset from zero is an odd multiple of 5ms on a 44100 Hz context.  Perhaps we could add a tiny irrational offset to the rounding to avoid problems in this situation.
(Assignee)

Comment 5

4 years ago
Created attachment 8376009 [details]
testcase for comparison with blink

I don't know why Chromium doesn't support buffers of length 1.

The changes here mean Gecko now generates the same results as Chromium 33.0.1750.46 for this testcase.

Updated

4 years ago
Attachment #8375999 - Flags: review?(paul) → review+

Updated

4 years ago
Attachment #8376002 - Flags: review?(paul) → review+
(Assignee)

Comment 6

4 years ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/49f896f22641
https://hg.mozilla.org/integration/mozilla-inbound/rev/085ca09d085e
Flags: in-testsuite?
https://hg.mozilla.org/mozilla-central/rev/49f896f22641
https://hg.mozilla.org/mozilla-central/rev/085ca09d085e
Status: ASSIGNED → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla30

Comment 8

4 years ago
Created attachment 8378731 [details]
test_bug972678.html

Here is a Mochitest test case for checking if buffers interfere with each other -- it generates a signal with alternating amplitudes of 1 and -1 every sample. It schedules 2-sample-sized buffers in sequence, and asserts this against a directly generated buffer.

Comment 9

4 years ago
Created attachment 8378791 [details]
test_bug972678.html

This updated version of the test case tests against multiple offsets. It also, instead of using an expected buffer containing a generated version of the scheduled samples, plays the generated buffer with its phase inverted and asserts it against a buffer of zero amplitude throughout.
Attachment #8378731 - Attachment is obsolete: true
(Assignee)

Comment 10

4 years ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/ffab287900cb
Flags: in-testsuite? → in-testsuite+
https://hg.mozilla.org/mozilla-central/rev/ffab287900cb
You need to log in before you can comment on or make changes to this bug.