diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp b/Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp index 199b1cd1295..a19104e4832 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp +++ b/Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp @@ -21,28 +21,28 @@ AudioNode::AudioNode(JS::Realm& realm, JS::NonnullGCPtr contex AudioNode::~AudioNode() = default; -WebIDL::ExceptionOr AudioNode::initialize_audio_node_options(JS::NonnullGCPtr context, AudioNodeOptions const& given_options, AudioNodeOptions const& default_options) +WebIDL::ExceptionOr AudioNode::initialize_audio_node_options(AudioNodeOptions const& given_options, AudioNodeDefaultOptions const& default_options) { - // FIXME: Context will be used in the future implementation. - (void)context; // Cast to void to avoid unused parameter warning. - // Set channel count, fallback to default if not provided if (given_options.channel_count.has_value()) { TRY(set_channel_count(given_options.channel_count.value())); - } else if (default_options.channel_count.has_value()) { - TRY(set_channel_count(default_options.channel_count.value())); + } else { + TRY(set_channel_count(default_options.channel_count)); } // Set channel count mode, fallback to default if not provided if (given_options.channel_count_mode.has_value()) { TRY(set_channel_count_mode(given_options.channel_count_mode.value())); - } else if (default_options.channel_count_mode.has_value()) { - TRY(set_channel_count_mode(default_options.channel_count_mode.value())); + } else { + TRY(set_channel_count_mode(default_options.channel_count_mode)); } // Set channel interpretation, fallback to default if not provided - Bindings::ChannelInterpretation channel_interpretation_to_set = given_options.channel_interpretation.value_or(default_options.channel_interpretation.value_or(Bindings::ChannelInterpretation::Speakers)); - TRY(set_channel_interpretation(channel_interpretation_to_set)); + if (given_options.channel_interpretation.has_value()) { + TRY(set_channel_interpretation(given_options.channel_interpretation.value())); + } else { + TRY(set_channel_interpretation(default_options.channel_interpretation)); + } return {}; } diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioNode.h b/Userland/Libraries/LibWeb/WebAudio/AudioNode.h index 9a863532bc5..fa63a679351 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioNode.h +++ b/Userland/Libraries/LibWeb/WebAudio/AudioNode.h @@ -22,6 +22,12 @@ struct AudioNodeOptions { Optional channel_interpretation; }; +struct AudioNodeDefaultOptions { + WebIDL::UnsignedLong channel_count; + Bindings::ChannelCountMode channel_count_mode; + Bindings::ChannelInterpretation channel_interpretation; +}; + // https://webaudio.github.io/web-audio-api/#AudioNode class AudioNode : public DOM::EventTarget { WEB_PLATFORM_OBJECT(AudioNode, DOM::EventTarget); @@ -62,7 +68,7 @@ public: WebIDL::ExceptionOr set_channel_interpretation(Bindings::ChannelInterpretation); Bindings::ChannelInterpretation channel_interpretation(); - WebIDL::ExceptionOr initialize_audio_node_options(JS::NonnullGCPtr context, AudioNodeOptions const& given_options, AudioNodeOptions const& default_options); + WebIDL::ExceptionOr initialize_audio_node_options(AudioNodeOptions const& given_options, AudioNodeDefaultOptions const& default_options); protected: AudioNode(JS::Realm&, JS::NonnullGCPtr); diff --git a/Userland/Libraries/LibWeb/WebAudio/DynamicsCompressorNode.cpp b/Userland/Libraries/LibWeb/WebAudio/DynamicsCompressorNode.cpp index d93b29dac3d..9812065b712 100644 --- a/Userland/Libraries/LibWeb/WebAudio/DynamicsCompressorNode.cpp +++ b/Userland/Libraries/LibWeb/WebAudio/DynamicsCompressorNode.cpp @@ -27,17 +27,18 @@ WebIDL::ExceptionOr> DynamicsCompressor auto node = realm.vm().heap().allocate(realm, realm, context, options); // Default options for channel count and interpretation - AudioNodeOptions default_options; + // https://webaudio.github.io/web-audio-api/#DynamicsCompressorNode + AudioNodeDefaultOptions default_options; default_options.channel_count_mode = Bindings::ChannelCountMode::ClampedMax; default_options.channel_interpretation = Bindings::ChannelInterpretation::Speakers; + default_options.channel_count = 2; + // FIXME: Set tail-time to yes - // Initialize the AudioNode with the given options, default options, and context - TRY(node->initialize_audio_node_options(context, options, default_options)); + TRY(node->initialize_audio_node_options(options, default_options)); return node; } - DynamicsCompressorNode::DynamicsCompressorNode(JS::Realm& realm, JS::NonnullGCPtr context, DynamicsCompressorOptions const& options) : AudioNode(realm, context) , m_threshold(AudioParam::create(realm, options.threshold, -100, 0, Bindings::AutomationRate::KRate)) @@ -76,4 +77,16 @@ WebIDL::ExceptionOr DynamicsCompressorNode::set_channel_count_mode(Binding return AudioNode::set_channel_count_mode(mode); } +// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcount +WebIDL::ExceptionOr DynamicsCompressorNode::set_channel_count(WebIDL::UnsignedLong channel_count) +{ + if (channel_count > 2) { + // Return a NotSupportedError if 'max' is used + return WebIDL::NotSupportedError::create(realm(), "DynamicsCompressorNode does not support channel count greater than 2"_string); + } + + // If the mode is valid, call the base class implementation + return AudioNode::set_channel_count(channel_count); +} + } diff --git a/Userland/Libraries/LibWeb/WebAudio/DynamicsCompressorNode.h b/Userland/Libraries/LibWeb/WebAudio/DynamicsCompressorNode.h index 25aa3166433..30fad47a799 100644 --- a/Userland/Libraries/LibWeb/WebAudio/DynamicsCompressorNode.h +++ b/Userland/Libraries/LibWeb/WebAudio/DynamicsCompressorNode.h @@ -41,6 +41,7 @@ public: float reduction() const { return m_reduction; } WebIDL::ExceptionOr set_channel_count_mode(Bindings::ChannelCountMode) override; + WebIDL::ExceptionOr set_channel_count(WebIDL::UnsignedLong) override; protected: DynamicsCompressorNode(JS::Realm&, JS::NonnullGCPtr, DynamicsCompressorOptions const& = {});