LibAudio: Manage channelCount in DynamicsCompressorNode

That helps to pass more WPT tests
under /webaudio/the-audio-api/the-dynamicscompressornode-interface/ctor-dynamicscompressor.html
This commit is contained in:
Pavel Shliak 2024-10-20 03:28:48 +04:00 committed by Tim Ledbetter
commit 8ac60273a6
Notes: github-actions[bot] 2024-10-29 13:32:50 +00:00
4 changed files with 35 additions and 15 deletions

View file

@ -27,17 +27,18 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DynamicsCompressorNode>> DynamicsCompressor
auto node = realm.vm().heap().allocate<DynamicsCompressorNode>(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<BaseAudioContext> 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<void> 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<void> 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);
}
}