mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-20 01:11:07 +00:00
LibWeb: Add ConstantSourceNode
interface
This commit is contained in:
parent
ccb543ebb8
commit
1b160044c4
Notes:
github-actions[bot]
2025-01-03 10:14:30 +00:00
Author: https://github.com/tcl3
Commit: 1b160044c4
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3102
Reviewed-by: https://github.com/shannonbooth
8 changed files with 188 additions and 0 deletions
47
Libraries/LibWeb/WebAudio/ConstantSourceNode.cpp
Normal file
47
Libraries/LibWeb/WebAudio/ConstantSourceNode.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Tim Ledbetter <tim.ledbetter@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/NumericLimits.h>
|
||||
#include <LibWeb/Bindings/ConstantSourceNodePrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/WebAudio/BaseAudioContext.h>
|
||||
#include <LibWeb/WebAudio/ConstantSourceNode.h>
|
||||
|
||||
namespace Web::WebAudio {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(ConstantSourceNode);
|
||||
|
||||
ConstantSourceNode::ConstantSourceNode(JS::Realm& realm, GC::Ref<BaseAudioContext> context, ConstantSourceOptions const& options)
|
||||
: AudioScheduledSourceNode(realm, context)
|
||||
, m_offset(AudioParam::create(realm, options.offset, NumericLimits<float>::lowest(), NumericLimits<float>::max(), Bindings::AutomationRate::ARate))
|
||||
{
|
||||
}
|
||||
|
||||
ConstantSourceNode::~ConstantSourceNode() = default;
|
||||
|
||||
WebIDL::ExceptionOr<GC::Ref<ConstantSourceNode>> ConstantSourceNode::create(JS::Realm& realm, GC::Ref<BaseAudioContext> context, ConstantSourceOptions const& options)
|
||||
{
|
||||
return construct_impl(realm, context, options);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<GC::Ref<ConstantSourceNode>> ConstantSourceNode::construct_impl(JS::Realm& realm, GC::Ref<BaseAudioContext> context, ConstantSourceOptions const& options)
|
||||
{
|
||||
return realm.create<ConstantSourceNode>(realm, context, options);
|
||||
}
|
||||
|
||||
void ConstantSourceNode::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(ConstantSourceNode);
|
||||
}
|
||||
|
||||
void ConstantSourceNode::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_offset);
|
||||
}
|
||||
|
||||
}
|
44
Libraries/LibWeb/WebAudio/ConstantSourceNode.h
Normal file
44
Libraries/LibWeb/WebAudio/ConstantSourceNode.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Tim Ledbetter <tim.ledbetter@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/WebAudio/AudioScheduledSourceNode.h>
|
||||
|
||||
namespace Web::WebAudio {
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#ChannelMergerOptions
|
||||
struct ConstantSourceOptions : AudioNodeOptions {
|
||||
float offset { 1.0f };
|
||||
};
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#ChannelMergerNode
|
||||
class ConstantSourceNode final : public AudioScheduledSourceNode {
|
||||
WEB_PLATFORM_OBJECT(ConstantSourceNode, AudioScheduledSourceNode);
|
||||
GC_DECLARE_ALLOCATOR(ConstantSourceNode);
|
||||
|
||||
public:
|
||||
virtual ~ConstantSourceNode() override;
|
||||
|
||||
static WebIDL::ExceptionOr<GC::Ref<ConstantSourceNode>> create(JS::Realm&, GC::Ref<BaseAudioContext>, ConstantSourceOptions const& = {});
|
||||
static WebIDL::ExceptionOr<GC::Ref<ConstantSourceNode>> construct_impl(JS::Realm&, GC::Ref<BaseAudioContext>, ConstantSourceOptions const& = {});
|
||||
|
||||
virtual WebIDL::UnsignedLong number_of_inputs() override { return 0; }
|
||||
virtual WebIDL::UnsignedLong number_of_outputs() override { return 1; }
|
||||
|
||||
GC::Ref<AudioParam const> offset() const { return m_offset; }
|
||||
|
||||
private:
|
||||
ConstantSourceNode(JS::Realm&, GC::Ref<BaseAudioContext>, ConstantSourceOptions const&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-constantsourcenode-offset
|
||||
GC::Ref<AudioParam> m_offset;
|
||||
};
|
||||
|
||||
}
|
15
Libraries/LibWeb/WebAudio/ConstantSourceNode.idl
Normal file
15
Libraries/LibWeb/WebAudio/ConstantSourceNode.idl
Normal file
|
@ -0,0 +1,15 @@
|
|||
#import <WebAudio/AudioNode.idl>
|
||||
#import <WebAudio/AudioParam.idl>
|
||||
#import <WebAudio/BaseAudioContext.idl>
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#ConstantSourceOptions
|
||||
dictionary ConstantSourceOptions {
|
||||
float offset = 1;
|
||||
};
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#ConstantSourceNode
|
||||
[Exposed=Window]
|
||||
interface ConstantSourceNode : AudioScheduledSourceNode {
|
||||
constructor (BaseAudioContext context, optional ConstantSourceOptions options = {});
|
||||
readonly attribute AudioParam offset;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue