mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
WebAudio: Stub remainder of AudioBufferSourceNode
This commit is contained in:
parent
779e3072f9
commit
014a069157
Notes:
github-actions[bot]
2024-07-28 19:42:06 +00:00
Author: https://github.com/bbb651 Commit: https://github.com/LadybirdBrowser/ladybird/commit/014a069157d Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/867
3 changed files with 116 additions and 8 deletions
|
@ -6,20 +6,102 @@
|
|||
|
||||
#include <LibWeb/Bindings/AudioScheduledSourceNodePrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/WebAudio/AudioBuffer.h>
|
||||
#include <LibWeb/WebAudio/AudioBufferSourceNode.h>
|
||||
#include <LibWeb/WebAudio/AudioParam.h>
|
||||
#include <LibWeb/WebAudio/AudioScheduledSourceNode.h>
|
||||
|
||||
namespace Web::WebAudio {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(AudioBufferSourceNode);
|
||||
|
||||
AudioBufferSourceNode::AudioBufferSourceNode(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, AudioBufferSourceOptions const&)
|
||||
AudioBufferSourceNode::AudioBufferSourceNode(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, AudioBufferSourceOptions const& options)
|
||||
: AudioScheduledSourceNode(realm, context)
|
||||
, m_buffer(options.buffer)
|
||||
, m_playback_rate(AudioParam::create(realm, options.playback_rate, NumericLimits<float>::lowest(), NumericLimits<float>::max(), Bindings::AutomationRate::ARate))
|
||||
, m_detune(AudioParam::create(realm, options.detune, NumericLimits<float>::lowest(), NumericLimits<float>::max(), Bindings::AutomationRate::ARate))
|
||||
, m_loop(options.loop)
|
||||
, m_loop_start(options.loop_start)
|
||||
, m_loop_end(options.loop_end)
|
||||
{
|
||||
}
|
||||
|
||||
AudioBufferSourceNode::~AudioBufferSourceNode() = default;
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-buffer
|
||||
WebIDL::ExceptionOr<void> AudioBufferSourceNode::set_buffer(JS::GCPtr<AudioBuffer> buffer)
|
||||
{
|
||||
m_buffer = buffer;
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-buffer
|
||||
JS::GCPtr<AudioBuffer> AudioBufferSourceNode::buffer() const
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-playbackrate
|
||||
JS::NonnullGCPtr<AudioParam> AudioBufferSourceNode::playback_rate() const
|
||||
{
|
||||
return m_playback_rate;
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-detune
|
||||
JS::NonnullGCPtr<AudioParam> AudioBufferSourceNode::detune() const
|
||||
{
|
||||
return m_detune;
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loop
|
||||
WebIDL::ExceptionOr<void> AudioBufferSourceNode::set_loop(bool loop)
|
||||
{
|
||||
m_loop = loop;
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loop
|
||||
bool AudioBufferSourceNode::loop() const
|
||||
{
|
||||
return m_loop;
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopstart
|
||||
WebIDL::ExceptionOr<void> AudioBufferSourceNode::set_loop_start(double loop_start)
|
||||
{
|
||||
m_loop_start = loop_start;
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopstart
|
||||
double AudioBufferSourceNode::loop_start() const
|
||||
{
|
||||
return m_loop_start;
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopend
|
||||
WebIDL::ExceptionOr<void> AudioBufferSourceNode::set_loop_end(double loop_end)
|
||||
{
|
||||
m_loop_end = loop_end;
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopend
|
||||
double AudioBufferSourceNode::loop_end() const
|
||||
{
|
||||
return m_loop_end;
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-start`
|
||||
WebIDL::ExceptionOr<void> AudioBufferSourceNode::start(Optional<double> when, Optional<double> offset, Optional<double> duration)
|
||||
{
|
||||
(void)when;
|
||||
(void)offset;
|
||||
(void)duration;
|
||||
dbgln("FIXME: Implement AudioBufferSourceNode::start(when, offset, duration)");
|
||||
return {};
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioBufferSourceNode>> AudioBufferSourceNode::create(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, AudioBufferSourceOptions const& options)
|
||||
{
|
||||
return construct_impl(realm, context, options);
|
||||
|
@ -44,6 +126,9 @@ void AudioBufferSourceNode::initialize(JS::Realm& realm)
|
|||
void AudioBufferSourceNode::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_buffer);
|
||||
visitor.visit(m_playback_rate);
|
||||
visitor.visit(m_detune);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/AudioBufferSourceNodePrototype.h>
|
||||
#include <LibWeb/WebAudio/AudioBuffer.h>
|
||||
#include <LibWeb/WebAudio/AudioParam.h>
|
||||
#include <LibWeb/WebAudio/AudioScheduledSourceNode.h>
|
||||
|
||||
namespace Web::WebAudio {
|
||||
|
@ -29,6 +31,19 @@ class AudioBufferSourceNode : public AudioScheduledSourceNode {
|
|||
public:
|
||||
virtual ~AudioBufferSourceNode() override;
|
||||
|
||||
WebIDL::ExceptionOr<void> set_buffer(JS::GCPtr<AudioBuffer>);
|
||||
JS::GCPtr<AudioBuffer> buffer() const;
|
||||
JS::NonnullGCPtr<AudioParam> playback_rate() const;
|
||||
JS::NonnullGCPtr<AudioParam> detune() const;
|
||||
WebIDL::ExceptionOr<void> set_loop(bool);
|
||||
bool loop() const;
|
||||
WebIDL::ExceptionOr<void> set_loop_start(double);
|
||||
double loop_start() const;
|
||||
WebIDL::ExceptionOr<void> set_loop_end(double);
|
||||
double loop_end() const;
|
||||
|
||||
WebIDL::ExceptionOr<void> start(Optional<double>, Optional<double>, Optional<double>);
|
||||
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioBufferSourceNode>> create(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, AudioBufferSourceOptions const& = {});
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioBufferSourceNode>> construct_impl(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, AudioBufferSourceOptions const& = {});
|
||||
|
||||
|
@ -37,6 +52,14 @@ protected:
|
|||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
private:
|
||||
JS::GCPtr<AudioBuffer> m_buffer;
|
||||
JS::NonnullGCPtr<AudioParam> m_playback_rate;
|
||||
JS::NonnullGCPtr<AudioParam> m_detune;
|
||||
bool m_loop { false };
|
||||
double m_loop_start { 0.0 };
|
||||
double m_loop_end { 0.0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@ dictionary AudioBufferSourceOptions {
|
|||
[Exposed=Window]
|
||||
interface AudioBufferSourceNode : AudioScheduledSourceNode {
|
||||
constructor(BaseAudioContext context, optional AudioBufferSourceOptions options = {});
|
||||
[FIXME] attribute AudioBuffer? buffer;
|
||||
[FIXME] readonly attribute AudioParam playbackRate;
|
||||
[FIXME] readonly attribute AudioParam detune;
|
||||
[FIXME] attribute boolean loop;
|
||||
[FIXME] attribute double loopStart;
|
||||
[FIXME] attribute double loopEnd;
|
||||
[FIXME] undefined start(optional double when = 0, optional double offset, optional double duration);
|
||||
attribute AudioBuffer? buffer;
|
||||
readonly attribute AudioParam playbackRate;
|
||||
readonly attribute AudioParam detune;
|
||||
attribute boolean loop;
|
||||
attribute double loopStart;
|
||||
attribute double loopEnd;
|
||||
undefined start(optional double when = 0, optional double offset, optional double duration);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue