WebAudio: Stub/implement more of AudioNode

This commit is contained in:
bbb651 2024-07-27 12:36:14 +03:00 committed by Andreas Kling
commit 6d33cc2b3a
Notes: github-actions[bot] 2024-07-28 19:42:25 +00:00
3 changed files with 82 additions and 9 deletions

View file

@ -24,18 +24,26 @@ AudioNode::~AudioNode() = default;
// https://webaudio.github.io/web-audio-api/#dom-audionode-connect // 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) WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioNode>> AudioNode::connect(JS::NonnullGCPtr<AudioNode> destination_node, WebIDL::UnsignedLong output, WebIDL::UnsignedLong input)
{ {
// There can only be one connection between a given output of one specific node and a given input of another specific node.
// Multiple connections with the same termini are ignored.
// If the destination parameter is an AudioNode that has been created using another AudioContext, an InvalidAccessError MUST be thrown.
if (m_context != destination_node->m_context) {
return WebIDL::InvalidAccessError::create(realm(), "Cannot connect to an AudioNode in a different AudioContext"_fly_string);
}
(void)output; (void)output;
(void)input; (void)input;
dbgln("FIXME: Implement AudioNode::connect (AudioNode)"); dbgln("FIXME: Implement Audio::connect(AudioNode)");
return destination_node; return destination_node;
} }
// https://webaudio.github.io/web-audio-api/#dom-audionode-connect-destinationparam-output // https://webaudio.github.io/web-audio-api/#dom-audionode-connect-destinationparam-output
WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioNode>> AudioNode::connect(JS::NonnullGCPtr<AudioParam> destination_param, WebIDL::UnsignedLong output) void AudioNode::connect(JS::NonnullGCPtr<AudioParam> destination_param, WebIDL::UnsignedLong output)
{ {
(void)destination_param; (void)destination_param;
(void)output; (void)output;
return WebIDL::NotSupportedError::create(realm(), "FIXME: Implement AudioNode::connect (AudioParam)"_fly_string); dbgln("FIXME: Implement AudioNode::connect(AudioParam)");
} }
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect // https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect
@ -90,6 +98,60 @@ void AudioNode::disconnect(JS::NonnullGCPtr<AudioParam> destination_param, WebID
dbgln("FIXME: Implement AudioNode::disconnect(destination_param, output)"); dbgln("FIXME: Implement AudioNode::disconnect(destination_param, output)");
} }
// https://webaudio.github.io/web-audio-api/#dom-audionode-numberofinputs
WebIDL::UnsignedLong AudioNode::number_of_inputs()
{
dbgln("FIXME: Implement AudioNode::number_of_inputs()");
return 0;
}
// https://webaudio.github.io/web-audio-api/#dom-audionode-numberofoutputs
WebIDL::UnsignedLong AudioNode::number_of_outputs()
{
dbgln("FIXME: Implement AudioNode::number_of_outputs()");
return 0;
}
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcount
WebIDL::ExceptionOr<void> AudioNode::set_channel_count(WebIDL::UnsignedLong channel_count)
{
(void)channel_count;
return WebIDL::NotSupportedError::create(realm(), "FIXME: Implement AudioNode::set_channel_count(channel_count)"_fly_string);
}
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcount
WebIDL::UnsignedLong AudioNode::channel_count()
{
dbgln("FIXME: Implement AudioNode::channel_count()");
return 2;
}
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcountmode
WebIDL::ExceptionOr<void> AudioNode::set_channel_count_mode(Bindings::ChannelCountMode channel_count_mode)
{
m_channel_count_mode = channel_count_mode;
return {};
}
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcountmode
Bindings::ChannelCountMode AudioNode::channel_count_mode()
{
return m_channel_count_mode;
}
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelinterpretation
WebIDL::ExceptionOr<void> AudioNode::set_channel_interpretation(Bindings::ChannelInterpretation channel_interpretation)
{
m_channel_interpretation = channel_interpretation;
return {};
}
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelinterpretation
Bindings::ChannelInterpretation AudioNode::channel_interpretation()
{
return m_channel_interpretation;
}
void AudioNode::initialize(JS::Realm& realm) void AudioNode::initialize(JS::Realm& realm)
{ {
Base::initialize(realm); Base::initialize(realm);

View file

@ -31,7 +31,7 @@ public:
virtual ~AudioNode() override; virtual ~AudioNode() override;
WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioNode>> connect(JS::NonnullGCPtr<AudioNode> destination_node, WebIDL::UnsignedLong output = 0, WebIDL::UnsignedLong input = 0); WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioNode>> connect(JS::NonnullGCPtr<AudioNode> destination_node, WebIDL::UnsignedLong output = 0, WebIDL::UnsignedLong input = 0);
WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioNode>> connect(JS::NonnullGCPtr<AudioParam> destination_param, WebIDL::UnsignedLong output = 0); void connect(JS::NonnullGCPtr<AudioParam> destination_param, WebIDL::UnsignedLong output = 0);
void disconnect(); void disconnect();
void disconnect(WebIDL::UnsignedLong output); void disconnect(WebIDL::UnsignedLong output);
@ -48,6 +48,15 @@ public:
return m_context; return m_context;
} }
WebIDL::UnsignedLong number_of_inputs();
WebIDL::UnsignedLong number_of_outputs();
WebIDL::ExceptionOr<void> set_channel_count(WebIDL::UnsignedLong);
WebIDL::UnsignedLong channel_count();
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();
protected: protected:
AudioNode(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>); AudioNode(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>);
@ -56,6 +65,8 @@ protected:
private: private:
JS::NonnullGCPtr<BaseAudioContext> m_context; JS::NonnullGCPtr<BaseAudioContext> m_context;
Bindings::ChannelCountMode m_channel_count_mode { Bindings::ChannelCountMode::Max };
Bindings::ChannelInterpretation m_channel_interpretation { Bindings::ChannelInterpretation::Speakers };
}; };
} }

View file

@ -38,9 +38,9 @@ interface AudioNode : EventTarget {
undefined disconnect(AudioParam destinationParam); undefined disconnect(AudioParam destinationParam);
undefined disconnect(AudioParam destinationParam, unsigned long output); undefined disconnect(AudioParam destinationParam, unsigned long output);
readonly attribute BaseAudioContext context; readonly attribute BaseAudioContext context;
[FIXME] readonly attribute unsigned long numberOfInputs; readonly attribute unsigned long numberOfInputs;
[FIXME] readonly attribute unsigned long numberOfOutputs; readonly attribute unsigned long numberOfOutputs;
[FIXME] attribute unsigned long channelCount; attribute unsigned long channelCount;
[FIXME] attribute ChannelCountMode channelCountMode; attribute ChannelCountMode channelCountMode;
[FIXME] attribute ChannelInterpretation channelInterpretation; attribute ChannelInterpretation channelInterpretation;
}; };