Bug 214990 - Added AudioBuffer Constructor
Summary: Added AudioBuffer Constructor
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Audio (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Clark Wang
URL:
Keywords: InRadar
Depends on:
Blocks: 212611
  Show dependency treegraph
 
Reported: 2020-07-30 15:11 PDT by Clark Wang
Modified: 2020-08-03 13:39 PDT (History)
14 users (show)

See Also:


Attachments
Patch (57.91 KB, patch)
2020-07-30 15:19 PDT, Clark Wang
no flags Details | Formatted Diff | Diff
Patch (57.13 KB, patch)
2020-07-30 16:41 PDT, Clark Wang
no flags Details | Formatted Diff | Diff
Patch (58.21 KB, patch)
2020-07-31 07:29 PDT, Clark Wang
no flags Details | Formatted Diff | Diff
Patch (58.21 KB, patch)
2020-07-31 07:41 PDT, Clark Wang
no flags Details | Formatted Diff | Diff
Patch (58.11 KB, patch)
2020-07-31 09:21 PDT, Clark Wang
no flags Details | Formatted Diff | Diff
Patch (58.12 KB, patch)
2020-07-31 10:28 PDT, Clark Wang
no flags Details | Formatted Diff | Diff
Patch (57.48 KB, patch)
2020-08-03 08:56 PDT, Clark Wang
no flags Details | Formatted Diff | Diff
Patch (57.38 KB, patch)
2020-08-03 10:05 PDT, Clark Wang
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Clark Wang 2020-07-30 15:11:10 PDT
Added AudioBuffer constructor according to: https://www.w3.org/TR/webaudio/#AudioBuffer-constructors. Added in AudioBufferOptions files as well.
Comment 1 Clark Wang 2020-07-30 15:19:35 PDT
Created attachment 405628 [details]
Patch
Comment 2 Chris Dumez 2020-07-30 15:28:53 PDT
Comment on attachment 405628 [details]
Patch

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

> Source/WebCore/Modules/webaudio/AudioBuffer.cpp:55
> +ExceptionOr<Ref<AudioBuffer>> AudioBuffer::create(const AudioBufferOptions&& options)

no const.

> Source/WebCore/Modules/webaudio/AudioBuffer.cpp:67
> +    if (!buffer->m_length)

I'd rather we use the length() getter.

> Source/WebCore/Modules/webaudio/AudioBuffer.h:45
> +    static ExceptionOr<Ref<AudioBuffer>> create(const AudioBufferOptions&& = { });

no const

> Source/WebCore/Modules/webaudio/AudioBufferOptions.h:33
> +    unsigned numberOfChannels;

Please provide default values for these. Otherwise, when you used AudioBufferOptions { } earlier in your patch as default parameter value, it constructed a struct with uninitialized members.

> Source/WebCore/Modules/webaudio/AudioBufferOptions.h:34
> +    size_t length;

unsigned

> Source/WebCore/Modules/webaudio/OfflineAudioContextOptions.idl:25
> + 

Unnecessary change.

> LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/audiobuffersource-channels-expected.txt:9
> +FAIL X source.buffer = new buffer did not throw an exception. assert_true: expected true got false

This seems bad?

> LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/audiobuffersource-channels-expected.txt:11
> +FAIL X source.buffer = buffer again did not throw an exception. assert_true: expected true got false

how about this?
Comment 3 Clark Wang 2020-07-30 16:19:18 PDT
(In reply to Chris Dumez from comment #2)
> Comment on attachment 405628 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=405628&action=review
> 
> > Source/WebCore/Modules/webaudio/AudioBuffer.cpp:55
> > +ExceptionOr<Ref<AudioBuffer>> AudioBuffer::create(const AudioBufferOptions&& options)
> 
> no const.
> 
> > Source/WebCore/Modules/webaudio/AudioBuffer.cpp:67
> > +    if (!buffer->m_length)
> 
> I'd rather we use the length() getter.
> 
> > Source/WebCore/Modules/webaudio/AudioBuffer.h:45
> > +    static ExceptionOr<Ref<AudioBuffer>> create(const AudioBufferOptions&& = { });
> 
> no const
> 
> > Source/WebCore/Modules/webaudio/AudioBufferOptions.h:33
> > +    unsigned numberOfChannels;
> 
> Please provide default values for these. Otherwise, when you used
> AudioBufferOptions { } earlier in your patch as default parameter value, it
> constructed a struct with uninitialized members.
> 
> > Source/WebCore/Modules/webaudio/AudioBufferOptions.h:34
> > +    size_t length;
> 
> unsigned
> 
> > Source/WebCore/Modules/webaudio/OfflineAudioContextOptions.idl:25
> > + 
> 
> Unnecessary change.
> 
> > LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/audiobuffersource-channels-expected.txt:9
> > +FAIL X source.buffer = new buffer did not throw an exception. assert_true: expected true got false
> 
> This seems bad?

I think this is testing AudioBufferSourceNode::setBuffer() method, which will be fixed in a future patch.

> 
> > LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/audiobuffersource-channels-expected.txt:11
> > +FAIL X source.buffer = buffer again did not throw an exception. assert_true: expected true got false
> 
> how about this?

Ditto above
Comment 4 Clark Wang 2020-07-30 16:41:23 PDT
Created attachment 405635 [details]
Patch
Comment 5 youenn fablet 2020-07-31 03:10:38 PDT
Comment on attachment 405635 [details]
Patch

LGTM but some related tests are failing in EWS.

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

> Source/WebCore/Modules/webaudio/AudioBuffer.idl:36
>      readonly attribute long length; // in sample-frames

Seems strange that we pass an unsigned long length in AudioBufferOptions but (probably) add a getter for the same value as long.
Probably we want it to be unsigned long as well given its name.

> Source/WebCore/Modules/webaudio/AudioBufferOptions.h:34
> +    unsigned length;

We are using unsigned here, as per WebIDL I believe, but size_t at some point for instance in AudioBuffer::create.
This is probably fine for this patch but I wonder whether we should try to be more consistent in the type used for length.

> Source/WebCore/Modules/webaudio/BaseAudioContext.cpp:395
> +    return AudioBuffer::create(WTFMove(options));

No need to move options

> LayoutTests/imported/w3c/ChangeLog:19
> +        * web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/osc-basic-waveform-expected.txt:

Nice to see all these newly passing tests.
Comment 6 Clark Wang 2020-07-31 07:22:33 PDT
(In reply to youenn fablet from comment #5)
> Comment on attachment 405635 [details]
> Patch
> 
> LGTM but some related tests are failing in EWS.
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=405635&action=review
> 
> > Source/WebCore/Modules/webaudio/AudioBuffer.idl:36
> >      readonly attribute long length; // in sample-frames
> 
> Seems strange that we pass an unsigned long length in AudioBufferOptions but
> (probably) add a getter for the same value as long.
> Probably we want it to be unsigned long as well given its name.
> 

Yup, and according to spec it should be unsigned long as well, doesn't hurt to add in this patch I guess.

> > Source/WebCore/Modules/webaudio/AudioBufferOptions.h:34
> > +    unsigned length;
> 
> We are using unsigned here, as per WebIDL I believe, but size_t at some
> point for instance in AudioBuffer::create.
> This is probably fine for this patch but I wonder whether we should try to
> be more consistent in the type used for length.
> 

Right, should agree on something.

> > Source/WebCore/Modules/webaudio/BaseAudioContext.cpp:395
> > +    return AudioBuffer::create(WTFMove(options));
> 
> No need to move options

Got it.

> 
> > LayoutTests/imported/w3c/ChangeLog:19
> > +        * web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/osc-basic-waveform-expected.txt:
> 
> Nice to see all these newly passing tests.

Just from a simple constructor :)
Comment 7 Clark Wang 2020-07-31 07:29:47 PDT
Created attachment 405691 [details]
Patch
Comment 8 Clark Wang 2020-07-31 07:41:11 PDT
Created attachment 405693 [details]
Patch
Comment 9 Clark Wang 2020-07-31 07:42:02 PDT
Resubmitted because old patch accidentally capitalized imported in LayoutTests/TestExpectations
Comment 10 youenn fablet 2020-07-31 08:22:20 PDT
Comment on attachment 405693 [details]
Patch

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

> Source/WebCore/Modules/webaudio/AudioBuffer.cpp:55
> +ExceptionOr<Ref<AudioBuffer>> AudioBuffer::create(const AudioBufferOptions& options)

We should try to remove the other AudioBuffer::create and just use this new one as a follow-up patch.
That will remove some potentially duplicated code.

> Source/WebCore/Modules/webaudio/BaseAudioContext.cpp:395
> +    return AudioBuffer::create(options);

This could probably be made as a one-liner.
Comment 11 Clark Wang 2020-07-31 09:21:19 PDT
Created attachment 405698 [details]
Patch
Comment 12 Clark Wang 2020-07-31 09:22:27 PDT
(In reply to youenn fablet from comment #10)
> Comment on attachment 405693 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=405693&action=review
> 
> > Source/WebCore/Modules/webaudio/AudioBuffer.cpp:55
> > +ExceptionOr<Ref<AudioBuffer>> AudioBuffer::create(const AudioBufferOptions& options)
> 
> We should try to remove the other AudioBuffer::create and just use this new
> one as a follow-up patch.
> That will remove some potentially duplicated code.

Got it, there are some dependencies in files such as ScriptProcessorNode.

> 
> > Source/WebCore/Modules/webaudio/BaseAudioContext.cpp:395
> > +    return AudioBuffer::create(options);
> 
> This could probably be made as a one-liner.

Updated this, also changed length in AudioBufferOptions.h back to size_t to support this change.
Comment 13 Chris Dumez 2020-07-31 09:24:18 PDT
(In reply to Clark Wang from comment #12)
> (In reply to youenn fablet from comment #10)
> > Comment on attachment 405693 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=405693&action=review
> > 
> > > Source/WebCore/Modules/webaudio/AudioBuffer.cpp:55
> > > +ExceptionOr<Ref<AudioBuffer>> AudioBuffer::create(const AudioBufferOptions& options)
> > 
> > We should try to remove the other AudioBuffer::create and just use this new
> > one as a follow-up patch.
> > That will remove some potentially duplicated code.
> 
> Got it, there are some dependencies in files such as ScriptProcessorNode.
> 
> > 
> > > Source/WebCore/Modules/webaudio/BaseAudioContext.cpp:395
> > > +    return AudioBuffer::create(options);
> > 
> > This could probably be made as a one-liner.
> 
> Updated this, also changed length in AudioBufferOptions.h back to size_t to
> support this change.

If you want to align one way, align to unsigned, not size_t.
Comment 14 Clark Wang 2020-07-31 10:28:12 PDT
Created attachment 405704 [details]
Patch
Comment 15 Clark Wang 2020-07-31 10:28:58 PDT
(In reply to Chris Dumez from comment #13)
> (In reply to Clark Wang from comment #12)
> > (In reply to youenn fablet from comment #10)
> > > Comment on attachment 405693 [details]
> > > Patch
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=405693&action=review
> > > 
> > > > Source/WebCore/Modules/webaudio/AudioBuffer.cpp:55
> > > > +ExceptionOr<Ref<AudioBuffer>> AudioBuffer::create(const AudioBufferOptions& options)
> > > 
> > > We should try to remove the other AudioBuffer::create and just use this new
> > > one as a follow-up patch.
> > > That will remove some potentially duplicated code.
> > 
> > Got it, there are some dependencies in files such as ScriptProcessorNode.
> > 
> > > 
> > > > Source/WebCore/Modules/webaudio/BaseAudioContext.cpp:395
> > > > +    return AudioBuffer::create(options);
> > > 
> > > This could probably be made as a one-liner.
> > 
> > Updated this, also changed length in AudioBufferOptions.h back to size_t to
> > support this change.
> 
> If you want to align one way, align to unsigned, not size_t.


Modified the code to align to unsigned.
Comment 16 Chris Dumez 2020-07-31 13:36:52 PDT
Comment on attachment 405704 [details]
Patch

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

> Source/WebCore/Modules/webaudio/AudioBufferOptions.h:34
> +    unsigned length;

Needs an initializer

> Source/WebCore/Modules/webaudio/AudioBufferOptions.h:35
> +    float sampleRate;

Needs an initializer
Comment 17 Clark Wang 2020-08-03 08:56:50 PDT
Created attachment 405833 [details]
Patch
Comment 18 Clark Wang 2020-08-03 08:57:59 PDT
(In reply to Chris Dumez from comment #16)
> Comment on attachment 405704 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=405704&action=review
> 
> > Source/WebCore/Modules/webaudio/AudioBufferOptions.h:34
> > +    unsigned length;
> 
> Needs an initializer
> 
> > Source/WebCore/Modules/webaudio/AudioBufferOptions.h:35
> > +    float sampleRate;
> 
> Needs an initializer

Initialized these two members to the smallest values that are supported. Also made AudioBufferOptions a non-optional parameter in AudioBuffer to properly match spec.
Comment 19 Clark Wang 2020-08-03 10:05:00 PDT
Created attachment 405846 [details]
Patch
Comment 20 Clark Wang 2020-08-03 10:05:39 PDT
(In reply to Clark Wang from comment #19)
> Created attachment 405846 [details]
> Patch

Rebased, hopefully builds now.
Comment 21 EWS 2020-08-03 12:23:03 PDT
Committed r265210: <https://trac.webkit.org/changeset/265210>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 405846 [details].
Comment 22 Radar WebKit Bug Importer 2020-08-03 13:39:00 PDT
<rdar://problem/66489353>