From 4998385c7aeae21939f4ea24bb4f8c6eb477840b Mon Sep 17 00:00:00 2001 From: Pavel Shliak Date: Tue, 29 Oct 2024 22:57:13 +0400 Subject: [PATCH] LibAudio: Initialize GainNode properly That helps to pass WPT tests under /webaudio/the-audio-api/the-gainnode-interface/ctor-gain.html --- .../LibWeb/WebAudio/BaseAudioContext.cpp | 2 +- .../LibWeb/WebAudio/BaseAudioContext.h | 2 +- .../Libraries/LibWeb/WebAudio/GainNode.cpp | 19 +++++++++++++++---- Userland/Libraries/LibWeb/WebAudio/GainNode.h | 4 ++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp index 587791596cb..f1dc22884e7 100644 --- a/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp +++ b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp @@ -95,7 +95,7 @@ WebIDL::ExceptionOr> BaseAudioContext:: } // https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-creategain -JS::NonnullGCPtr BaseAudioContext::create_gain() +WebIDL::ExceptionOr> BaseAudioContext::create_gain() { // Factory method for GainNode. return GainNode::create(realm(), *this); diff --git a/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.h b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.h index 597435e81bf..4b8b14862db 100644 --- a/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.h +++ b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.h @@ -59,7 +59,7 @@ public: WebIDL::ExceptionOr> create_buffer_source(); WebIDL::ExceptionOr> create_oscillator(); WebIDL::ExceptionOr> create_dynamics_compressor(); - JS::NonnullGCPtr create_gain(); + WebIDL::ExceptionOr> create_gain(); JS::NonnullGCPtr decode_audio_data(JS::Handle, JS::GCPtr, JS::GCPtr); diff --git a/Userland/Libraries/LibWeb/WebAudio/GainNode.cpp b/Userland/Libraries/LibWeb/WebAudio/GainNode.cpp index 5c7bdebdb10..ffa435746b1 100644 --- a/Userland/Libraries/LibWeb/WebAudio/GainNode.cpp +++ b/Userland/Libraries/LibWeb/WebAudio/GainNode.cpp @@ -16,16 +16,27 @@ JS_DEFINE_ALLOCATOR(GainNode); GainNode::~GainNode() = default; -JS::NonnullGCPtr GainNode::create(JS::Realm& realm, JS::NonnullGCPtr context, GainOptions const& options) +WebIDL::ExceptionOr> GainNode::create(JS::Realm& realm, JS::NonnullGCPtr context, GainOptions const& options) { return construct_impl(realm, context, options); } // https://webaudio.github.io/web-audio-api/#dom-gainnode-gainnode -JS::NonnullGCPtr GainNode::construct_impl(JS::Realm& realm, JS::NonnullGCPtr context, GainOptions const& options) +WebIDL::ExceptionOr> GainNode::construct_impl(JS::Realm& realm, JS::NonnullGCPtr context, GainOptions const& options) { - // FIXME: Invoke "Initialize the AudioNode" steps. - return realm.vm().heap().allocate(realm, realm, context, options); + // Create the node and allocate memory + auto node = realm.vm().heap().allocate(realm, realm, context, options); + + // Default options for channel count and interpretation + // https://webaudio.github.io/web-audio-api/#GainNode + AudioNodeDefaultOptions default_options; + default_options.channel_count_mode = Bindings::ChannelCountMode::Max; + default_options.channel_interpretation = Bindings::ChannelInterpretation::Speakers; + default_options.channel_count = 2; + // FIXME: Set tail-time to no + + TRY(node->initialize_audio_node_options(options, default_options)); + return node; } GainNode::GainNode(JS::Realm& realm, JS::NonnullGCPtr context, GainOptions const& options) diff --git a/Userland/Libraries/LibWeb/WebAudio/GainNode.h b/Userland/Libraries/LibWeb/WebAudio/GainNode.h index 2e28cbc059d..1e1020a435d 100644 --- a/Userland/Libraries/LibWeb/WebAudio/GainNode.h +++ b/Userland/Libraries/LibWeb/WebAudio/GainNode.h @@ -24,8 +24,8 @@ class GainNode : public AudioNode { public: virtual ~GainNode() override; - static JS::NonnullGCPtr create(JS::Realm&, JS::NonnullGCPtr, GainOptions const& = {}); - static JS::NonnullGCPtr construct_impl(JS::Realm&, JS::NonnullGCPtr, GainOptions const& = {}); + static WebIDL::ExceptionOr> create(JS::Realm&, JS::NonnullGCPtr, GainOptions const& = {}); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, JS::NonnullGCPtr, GainOptions const& = {}); WebIDL::UnsignedLong number_of_inputs() override { return 1; } WebIDL::UnsignedLong number_of_outputs() override { return 1; }