mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-17 07:50:04 +00:00
LibAudio: Manage channelCountMode 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:
parent
ed658154d2
commit
f2ed59879f
Notes:
github-actions[bot]
2024-10-29 13:32:57 +00:00
Author: https://github.com/shlyakpavel
Commit: f2ed59879f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1735
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/gmta
Reviewed-by: https://github.com/shannonbooth
6 changed files with 100 additions and 5 deletions
|
@ -0,0 +1,6 @@
|
|||
clamped-max
|
||||
explicit
|
||||
NotSupportedError
|
||||
clamped-max
|
||||
explicit
|
||||
NotSupportedError
|
|
@ -0,0 +1,36 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const context = new (window.AudioContext || window.webkitAudioContext)();
|
||||
const validModes = ['clamped-max', 'explicit'];
|
||||
const invalidMode = 'max';
|
||||
|
||||
// Test valid channelCountMode values via constructor
|
||||
validModes.forEach(mode => {
|
||||
const node = new DynamicsCompressorNode(context, { channelCountMode: mode });
|
||||
println(node.channelCountMode);
|
||||
});
|
||||
|
||||
// Test invalid channelCountMode via constructor
|
||||
try {
|
||||
new DynamicsCompressorNode(context, { channelCountMode: invalidMode });
|
||||
} catch (error) {
|
||||
println(error.name);
|
||||
}
|
||||
|
||||
// Test valid channelCountMode values via setter
|
||||
validModes.forEach(mode => {
|
||||
const node = new DynamicsCompressorNode(context);
|
||||
node.channelCountMode = mode;
|
||||
println(node.channelCountMode);
|
||||
});
|
||||
|
||||
// Test invalid channelCountMode via setter
|
||||
try {
|
||||
const node = new DynamicsCompressorNode(context);
|
||||
node.channelCountMode = invalidMode;
|
||||
} catch (error) {
|
||||
println(error.name);
|
||||
}
|
||||
});
|
||||
</script>
|
|
@ -21,6 +21,32 @@ AudioNode::AudioNode(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> contex
|
|||
|
||||
AudioNode::~AudioNode() = default;
|
||||
|
||||
WebIDL::ExceptionOr<void> AudioNode::initialize_audio_node_options(JS::NonnullGCPtr<BaseAudioContext> context, AudioNodeOptions const& given_options, AudioNodeOptions 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()));
|
||||
}
|
||||
|
||||
// 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()));
|
||||
}
|
||||
|
||||
// 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));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-connect
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioNode>> AudioNode::connect(JS::NonnullGCPtr<AudioNode> destination_node, WebIDL::UnsignedLong output, WebIDL::UnsignedLong input)
|
||||
{
|
||||
|
|
|
@ -18,8 +18,8 @@ namespace Web::WebAudio {
|
|||
// https://webaudio.github.io/web-audio-api/#AudioNodeOptions
|
||||
struct AudioNodeOptions {
|
||||
Optional<WebIDL::UnsignedLong> channel_count;
|
||||
Bindings::ChannelCountMode channel_count_mode;
|
||||
Bindings::ChannelInterpretation channel_interpretation;
|
||||
Optional<Bindings::ChannelCountMode> channel_count_mode;
|
||||
Optional<Bindings::ChannelInterpretation> channel_interpretation;
|
||||
};
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#AudioNode
|
||||
|
@ -57,11 +57,13 @@ public:
|
|||
virtual WebIDL::ExceptionOr<void> set_channel_count(WebIDL::UnsignedLong);
|
||||
virtual WebIDL::UnsignedLong channel_count() const { return m_channel_count; }
|
||||
|
||||
WebIDL::ExceptionOr<void> set_channel_count_mode(Bindings::ChannelCountMode);
|
||||
virtual WebIDL::ExceptionOr<void> set_channel_count_mode(Bindings::ChannelCountMode);
|
||||
Bindings::ChannelCountMode channel_count_mode();
|
||||
WebIDL::ExceptionOr<void> set_channel_interpretation(Bindings::ChannelInterpretation);
|
||||
Bindings::ChannelInterpretation channel_interpretation();
|
||||
|
||||
WebIDL::ExceptionOr<void> initialize_audio_node_options(JS::NonnullGCPtr<BaseAudioContext> context, AudioNodeOptions const& given_options, AudioNodeOptions const& default_options);
|
||||
|
||||
protected:
|
||||
AudioNode(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>);
|
||||
|
||||
|
|
|
@ -23,10 +23,21 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DynamicsCompressorNode>> DynamicsCompressor
|
|||
// https://webaudio.github.io/web-audio-api/#dom-dynamicscompressornode-dynamicscompressornode
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DynamicsCompressorNode>> DynamicsCompressorNode::construct_impl(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, DynamicsCompressorOptions const& options)
|
||||
{
|
||||
// FIXME: Invoke "Initialize the AudioNode" steps.
|
||||
return realm.vm().heap().allocate<DynamicsCompressorNode>(realm, realm, context, options);
|
||||
// Create the node and allocate memory
|
||||
auto node = realm.vm().heap().allocate<DynamicsCompressorNode>(realm, realm, context, options);
|
||||
|
||||
// Default options for channel count and interpretation
|
||||
AudioNodeOptions default_options;
|
||||
default_options.channel_count_mode = Bindings::ChannelCountMode::ClampedMax;
|
||||
default_options.channel_interpretation = Bindings::ChannelInterpretation::Speakers;
|
||||
|
||||
// Initialize the AudioNode with the given options, default options, and context
|
||||
TRY(node->initialize_audio_node_options(context, 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))
|
||||
|
@ -53,4 +64,16 @@ void DynamicsCompressorNode::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_release);
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcountmode
|
||||
WebIDL::ExceptionOr<void> DynamicsCompressorNode::set_channel_count_mode(Bindings::ChannelCountMode mode)
|
||||
{
|
||||
if (mode == Bindings::ChannelCountMode::Max) {
|
||||
// Return a NotSupportedError if 'max' is used
|
||||
return WebIDL::NotSupportedError::create(realm(), "DynamicsCompressorNode does not support 'max' as channelCountMode."_string);
|
||||
}
|
||||
|
||||
// If the mode is valid, call the base class implementation
|
||||
return AudioNode::set_channel_count_mode(mode);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ public:
|
|||
JS::NonnullGCPtr<AudioParam const> release() const { return m_release; }
|
||||
float reduction() const { return m_reduction; }
|
||||
|
||||
WebIDL::ExceptionOr<void> set_channel_count_mode(Bindings::ChannelCountMode) override;
|
||||
|
||||
protected:
|
||||
DynamicsCompressorNode(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, DynamicsCompressorOptions const& = {});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue