Bug 229251 - [WebAudio/WebM] Incorrect number of frames returned if decoding frame rate doesn't match original
Summary: [WebAudio/WebM] Incorrect number of frames returned if decoding frame rate do...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Audio (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jean-Yves Avenard [:jya]
URL:
Keywords: InRadar
Depends on:
Blocks: 227111
  Show dependency treegraph
 
Reported: 2021-08-18 14:56 PDT by Jean-Yves Avenard [:jya]
Modified: 2021-09-09 00:02 PDT (History)
8 users (show)

See Also:


Attachments
Patch (8.95 KB, patch)
2021-09-08 03:40 PDT, Jean-Yves Avenard [:jya]
no flags Details | Formatted Diff | Diff
Patch (9.74 KB, patch)
2021-09-08 19:34 PDT, Jean-Yves Avenard [:jya]
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Yves Avenard [:jya] 2021-08-18 14:56:04 PDT
When calling decodeAudioData with a context where a sampling rate set is different to the original content, the number of frames returned may be incorrect

STR:
1- Open https://jyavenard.github.io/htmltests/tests/webaudio/decodeAudioData.html
2- Select opus.webm as the file to use
3- Set the sampling rate to 44100
4- Press play

The numbers showing are 88254 frames 2.001224489795918
which indicates that we've returned 88254 frames and that the length of the blob decoded is over 2s

This file is originally encoded at 48kHz and is exactly 2s long. When forcing the content to be decoded at 44.1kHz we should be getting 88200 frames and a 2s duration.

Something is wrong in the resampling and the trimming.
Comment 1 Radar WebKit Bug Importer 2021-08-18 14:56:31 PDT
<rdar://problem/82095650>
Comment 2 Jean-Yves Avenard [:jya] 2021-09-08 03:40:10 PDT
Created attachment 437617 [details]
Patch
Comment 3 Eric Carlson 2021-09-08 15:19:30 PDT
Comment on attachment 437617 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=437617&action=review

> Source/WebCore/platform/audio/cocoa/AudioFileReaderCocoa.cpp:339
> +    uint32_t leadingTrim = m_webmData->m_track->codecDelay().value_or(MediaTime()).toDouble() * outFormat.mSampleRate;

`MediaTime::zeroTime()` should be cheaper than `MediaTime()`

> Source/WebCore/platform/audio/cocoa/AudioFileReaderCocoa.cpp:341
> +    uint32_t trailingTrim = (m_webmData->m_track->codecDelay().value_or(MediaTime()) + m_webmData->m_track->discardPadding().value_or(MediaTime())).toDouble() * outFormat.mSampleRate - leadingTrim + 0.5;

Ditto
Comment 4 Jean-Yves Avenard [:jya] 2021-09-08 19:34:27 PDT
Created attachment 437698 [details]
Patch
Comment 5 EWS 2021-09-09 00:02:29 PDT
Committed r282196 (241483@main): <https://commits.webkit.org/241483@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 437698 [details].