Coverage Report

Created: 2025-03-04 07:22

/src/serenity/Userland/Libraries/LibWeb/WebAudio/GainNode.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include <LibWeb/Bindings/Intrinsics.h>
8
#include <LibWeb/WebAudio/AudioNode.h>
9
#include <LibWeb/WebAudio/AudioParam.h>
10
#include <LibWeb/WebAudio/BaseAudioContext.h>
11
#include <LibWeb/WebAudio/GainNode.h>
12
13
namespace Web::WebAudio {
14
15
JS_DEFINE_ALLOCATOR(GainNode);
16
17
0
GainNode::~GainNode() = default;
18
19
WebIDL::ExceptionOr<JS::NonnullGCPtr<GainNode>> GainNode::create(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, GainOptions const& options)
20
0
{
21
0
    return construct_impl(realm, context, options);
22
0
}
23
24
// https://webaudio.github.io/web-audio-api/#dom-gainnode-gainnode
25
WebIDL::ExceptionOr<JS::NonnullGCPtr<GainNode>> GainNode::construct_impl(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, GainOptions const& options)
26
0
{
27
    // Create the node and allocate memory
28
0
    auto node = realm.vm().heap().allocate<GainNode>(realm, realm, context, options);
29
30
    // Default options for channel count and interpretation
31
    // https://webaudio.github.io/web-audio-api/#GainNode
32
0
    AudioNodeDefaultOptions default_options;
33
0
    default_options.channel_count_mode = Bindings::ChannelCountMode::Max;
34
0
    default_options.channel_interpretation = Bindings::ChannelInterpretation::Speakers;
35
0
    default_options.channel_count = 2;
36
    // FIXME: Set tail-time to no
37
38
0
    TRY(node->initialize_audio_node_options(options, default_options));
39
0
    return node;
40
0
}
41
42
GainNode::GainNode(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, GainOptions const& options)
43
0
    : AudioNode(realm, context)
44
0
    , m_gain(AudioParam::create(realm, options.gain, NumericLimits<float>::lowest(), NumericLimits<float>::max(), Bindings::AutomationRate::ARate))
45
0
{
46
0
}
47
48
void GainNode::initialize(JS::Realm& realm)
49
0
{
50
0
    Base::initialize(realm);
51
0
    WEB_SET_PROTOTYPE_FOR_INTERFACE(GainNode);
52
0
}
53
54
void GainNode::visit_edges(Cell::Visitor& visitor)
55
0
{
56
0
    Base::visit_edges(visitor);
57
0
    visitor.visit(m_gain);
58
0
}
59
60
}