2024-05-28 15:42:07 +12:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2024-07-27 14:37:27 +03:00
|
|
|
#include <LibWeb/WebAudio/AudioNode.h>
|
2024-05-28 15:42:07 +12:00
|
|
|
#include <LibWeb/WebAudio/AudioParam.h>
|
|
|
|
#include <LibWeb/WebAudio/BaseAudioContext.h>
|
|
|
|
#include <LibWeb/WebAudio/GainNode.h>
|
|
|
|
|
|
|
|
namespace Web::WebAudio {
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(GainNode);
|
2024-05-28 15:42:07 +12:00
|
|
|
|
|
|
|
GainNode::~GainNode() = default;
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<GainNode>> GainNode::create(JS::Realm& realm, GC::Ref<BaseAudioContext> context, GainOptions const& options)
|
2024-05-28 15:42:07 +12:00
|
|
|
{
|
|
|
|
return construct_impl(realm, context, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://webaudio.github.io/web-audio-api/#dom-gainnode-gainnode
|
2024-11-15 04:01:23 +13:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<GainNode>> GainNode::construct_impl(JS::Realm& realm, GC::Ref<BaseAudioContext> context, GainOptions const& options)
|
2024-05-28 15:42:07 +12:00
|
|
|
{
|
2024-10-29 22:57:13 +04:00
|
|
|
// Create the node and allocate memory
|
2024-11-14 05:50:17 +13:00
|
|
|
auto node = realm.create<GainNode>(realm, context, options);
|
2024-10-29 22:57:13 +04:00
|
|
|
|
|
|
|
// Default options for channel count and interpretation
|
|
|
|
// https://webaudio.github.io/web-audio-api/#GainNode
|
|
|
|
AudioNodeDefaultOptions default_options;
|
|
|
|
default_options.channel_count_mode = Bindings::ChannelCountMode::Max;
|
|
|
|
default_options.channel_interpretation = Bindings::ChannelInterpretation::Speakers;
|
|
|
|
default_options.channel_count = 2;
|
|
|
|
// FIXME: Set tail-time to no
|
|
|
|
|
|
|
|
TRY(node->initialize_audio_node_options(options, default_options));
|
|
|
|
return node;
|
2024-05-28 15:42:07 +12:00
|
|
|
}
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GainNode::GainNode(JS::Realm& realm, GC::Ref<BaseAudioContext> context, GainOptions const& options)
|
2024-05-28 15:42:07 +12:00
|
|
|
: AudioNode(realm, context)
|
2025-01-08 20:04:28 +00:00
|
|
|
, m_gain(AudioParam::create(realm, context, options.gain, NumericLimits<float>::lowest(), NumericLimits<float>::max(), Bindings::AutomationRate::ARate))
|
2024-05-28 15:42:07 +12:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GainNode::initialize(JS::Realm& realm)
|
|
|
|
{
|
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(GainNode);
|
2025-04-20 16:22:57 +02:00
|
|
|
Base::initialize(realm);
|
2024-05-28 15:42:07 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
void GainNode::visit_edges(Cell::Visitor& visitor)
|
|
|
|
{
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
visitor.visit(m_gain);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|