Web Audio API decodeAudioData causes short playback freeze
Categories
(Core :: Web Audio, defect)
Tracking
()
People
(Reporter: maxligtenberg, Assigned: padenot)
References
Details
Attachments
(2 files)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36
Steps to reproduce:
On macOS:
- Create a Web Audio API context.
- Make an XMLHTTPRequest to retrieve an MP3-file.
- Use Web Audio API's decodeAudioData to convert data.
- Put the (converted) data in a BufferSourceNode and play buffer.
Loop steps 2 - 4.
Online example:
https://www.evdh.net/DAD_investigations-master/
Example code:
https://github.com/sevdh/DAD_investigations
Actual results:
Occasionally the playback audibly freezes / glitches for a few ms. If a glitch occurs it is mostly during a decodeAudioData-process but can also happen during an XMLHTTPRequest.
See https://youtu.be/Aj1k9YdvD_Q for examples. Timecodes are in the description of the video. A zip-file is attached with a screenshot of an Audacity recording (audio recorded via SoundFlower) that shows the temporary freeze.
Expected results:
I expect that the playback does not hiccup and plays continuously.
Comment 1•3 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::Audio/Video: Playback' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.
Reporter | ||
Updated•3 years ago
|
Comment 2•3 years ago
|
||
Hi Max, thanks for the report. Can this be reproduced when the audio is in a different format? Or it only happens when using mp3 ?
Reporter | ||
Comment 3•3 years ago
|
||
Hi Chang,
Thanks for your reply. I've tested .flac, .m4a (aac) and .ogg-files and they all have the same problem. Glitches / hiccups occur every once in a while mainly during decodeAudioData en sometimes during XHR.
Reporter | ||
Comment 4•3 years ago
|
||
Additional information:
We've tested it on Firefox on Windows and the problem does not occur on that platform.
Comment 5•3 years ago
|
||
Hi Max, Would you mind testing this on a Linux machine?
Comment 6•3 years ago
|
||
Paul, do you have an idea where we should start looking at it? The issue seems different from the bug 1731813 since it happens on all formats.
Assignee | ||
Comment 7•3 years ago
|
||
Reporter, please try to reproduce while taking a performance profile with the Firefox profiler with the "Media" preset, as shown in this video: https://blog.paul.cx/post/profiling-firefox-media-workloads/#the-media-preset (there are written instructions below the video as well).
You can then either upload the profile and give us the link (button on the top-right), or send it to me at <padenot@mozilla.com> (there is an option to save locally). Please have the checkbox "Include hidden threads" checked, so we can understand what's up.
The "raw data" from about:support
can be useful to us as well, if you can attach that here.
Thanks!
Reporter | ||
Comment 8•3 years ago
|
||
Reporter | ||
Comment 9•3 years ago
|
||
Performance profile:
https://share.firefox.dev/2YjyqFC
The "raw data" has been added as attachment.
Reporter | ||
Comment 10•3 years ago
|
||
And I'm not able to test it on a Linux machine unfortunately.
Assignee | ||
Comment 11•3 years ago
|
||
This works as intended, no performance issue there.
The code as it is cannot be made to work: it's relying on setTimeout
, that doesn't have any scheduling guarantees. If you instead use the parameters of the start
method on AudioBufferSourceNode
, you will be able to achieve perfect playback. https://www.html5rocks.com/en/tutorials/audio/scheduling/ is a good introduction on the subject.
Comment 12•3 years ago
|
||
Dear Paul, we are aware that setTimeout is not accurate but that is not what's causing the problem in this context.
Did you have a look at the above referenced YouTube video that demonstrates the problem? (the link is given again at the bottom of this post)
The example code alternates between the playback of two sound files that overlap. For each sound an XHR and decodeAudioData are being executed.
The problem is that the playback of one buffer gets now and then interrupted by the decodeAudioData (and sometimes even the XHR) of a next buffer that is being prepared for playback.
The YouTube video that demonstrates the problem:
-> see https://youtu.be/Aj1k9YdvD_Q for examples. Timecodes are in the description of the video.
Working online example:
-> https://www.evdh.net/DAD_investigations-master/
Example code:
-> https://github.com/sevdh/DAD_investigations
Reporter | ||
Updated•3 years ago
|
Comment 13•3 years ago
|
||
Dear Paul, we are aware that setTimeout is not accurate but that is not related to the bug we are reporting.
The example code alternates between the playback of two sound files that partially overlap with each other. For each sound an XHR and a decodeAudioData are being executed.
The problem is that the playback of one buffer gets, (only) now and then, interrupted by the decodeAudioData (and sometimes even the XHR) of a the buffer that is being prepared for playback.
Please have a look at the video that demonstrates the problem (timecodes at which the hiccups occur are in the description of the video):
-> https://youtu.be/Aj1k9YdvD_Q
Working online example:
-> https://www.evdh.net/DAD_investigations-master/
(it sometimes takes some time a hiccup to occur).
Example code:
-> https://github.com/sevdh/DAD_investigations
Assignee | ||
Comment 14•3 years ago
|
||
I had a look, something strange is going on and I'm going to have a closer look.
Comment 15•3 years ago
|
||
Very happy to hear that!
I would guess that (aspects of) the decodeAudioData (and also the XHR) execution block either the 'regular audio generation process' of Firefox or the passing of audio from Firefox to the system. If so, it might be a threading or thread priority issue.
Let us know if and how we can help.
Comment 16•3 years ago
|
||
The severity field is not set for this bug.
:padenot, could you have a look please?
For more information, please visit auto_nag documentation.
Assignee | ||
Comment 17•3 years ago
|
||
We're re-architecturing how real-time audio threads are in Firefox at the moment. I'll try again after this, as one of the goal of this re-architecturing is to reduce the number of context switches.
Comment 18•3 years ago
|
||
Very nice to hear this follow up!
Please let us know when it's time to help testing from our side.
Updated•3 years ago
|
Description
•