mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-12 19:19:30 +00:00
LibWeb: Implement AudioNode.channelCount
This commit is contained in:
parent
7b4f0d13ee
commit
cb21201550
Notes:
github-actions[bot]
2024-10-08 14:35:10 +00:00
Author: https://github.com/gmta
Commit: cb21201550
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1679
4 changed files with 35 additions and 10 deletions
|
@ -7,9 +7,11 @@
|
|||
|
||||
#include <LibWeb/Bindings/AudioDestinationNodePrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/WebAudio/AudioContext.h>
|
||||
#include <LibWeb/WebAudio/AudioDestinationNode.h>
|
||||
#include <LibWeb/WebAudio/AudioNode.h>
|
||||
#include <LibWeb/WebAudio/BaseAudioContext.h>
|
||||
#include <LibWeb/WebAudio/OfflineAudioContext.h>
|
||||
|
||||
namespace Web::WebAudio {
|
||||
|
||||
|
@ -45,4 +47,25 @@ void AudioDestinationNode::visit_edges(Cell::Visitor& visitor)
|
|||
Base::visit_edges(visitor);
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcount
|
||||
WebIDL::ExceptionOr<void> AudioDestinationNode::set_channel_count(WebIDL::UnsignedLong channel_count)
|
||||
{
|
||||
// The behavior depends on whether the destination node is the destination of an AudioContext
|
||||
// or OfflineAudioContext:
|
||||
|
||||
// AudioContext: The channel count MUST be between 1 and maxChannelCount. An IndexSizeError
|
||||
// exception MUST be thrown for any attempt to set the count outside this range.
|
||||
if (is<AudioContext>(*context())) {
|
||||
if (channel_count < 1 || channel_count > max_channel_count())
|
||||
return WebIDL::IndexSizeError::create(realm(), "Channel index is out of range"_fly_string);
|
||||
}
|
||||
|
||||
// OfflineAudioContext: The channel count cannot be changed. An InvalidStateError exception MUST
|
||||
// be thrown for any attempt to change the value.
|
||||
if (is<OfflineAudioContext>(*context()))
|
||||
return WebIDL::InvalidStateError::create(realm(), "Cannot change channel count in an OfflineAudioContext"_fly_string);
|
||||
|
||||
return AudioNode::set_channel_count(channel_count);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue