mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
WebAudio: BiquadFilterNode
: Implement AudioParam
s and stub rest
(cherry picked from commit 150cef62a05b5eb028626352b54eb092cd7f2eef)
This commit is contained in:
parent
e4959ef9f3
commit
1e66ec24fa
3 changed files with 80 additions and 7 deletions
|
@ -4,22 +4,75 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/Bindings/AudioParamPrototype.h>
|
||||||
#include <LibWeb/Bindings/BiquadFilterNodePrototype.h>
|
#include <LibWeb/Bindings/BiquadFilterNodePrototype.h>
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
#include <LibWeb/WebAudio/AudioNode.h>
|
#include <LibWeb/WebAudio/AudioNode.h>
|
||||||
|
#include <LibWeb/WebAudio/AudioParam.h>
|
||||||
#include <LibWeb/WebAudio/BiquadFilterNode.h>
|
#include <LibWeb/WebAudio/BiquadFilterNode.h>
|
||||||
|
|
||||||
namespace Web::WebAudio {
|
namespace Web::WebAudio {
|
||||||
|
|
||||||
JS_DEFINE_ALLOCATOR(BiquadFilterNode);
|
JS_DEFINE_ALLOCATOR(BiquadFilterNode);
|
||||||
|
|
||||||
BiquadFilterNode::BiquadFilterNode(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, BiquadFilterOptions const&)
|
BiquadFilterNode::BiquadFilterNode(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, BiquadFilterOptions const& options)
|
||||||
: AudioNode(realm, context)
|
: AudioNode(realm, context)
|
||||||
|
, m_frequency(AudioParam::create(realm, options.frequency, 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_q(AudioParam::create(realm, options.q, NumericLimits<float>::lowest(), NumericLimits<float>::max(), Bindings::AutomationRate::ARate))
|
||||||
|
, m_gain(AudioParam::create(realm, options.gain, NumericLimits<float>::lowest(), NumericLimits<float>::max(), Bindings::AutomationRate::ARate))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
BiquadFilterNode::~BiquadFilterNode() = default;
|
BiquadFilterNode::~BiquadFilterNode() = default;
|
||||||
|
|
||||||
|
// https://webaudio.github.io/web-audio-api/#dom-biquadfilternode-type
|
||||||
|
WebIDL::ExceptionOr<void> BiquadFilterNode::set_type(Bindings::BiquadFilterType type)
|
||||||
|
{
|
||||||
|
m_type = type;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://webaudio.github.io/web-audio-api/#dom-biquadfilternode-type
|
||||||
|
Bindings::BiquadFilterType BiquadFilterNode::type() const
|
||||||
|
{
|
||||||
|
return m_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://webaudio.github.io/web-audio-api/#dom-biquadfilternode-frequency
|
||||||
|
JS::NonnullGCPtr<AudioParam> BiquadFilterNode::frequency() const
|
||||||
|
{
|
||||||
|
return m_frequency;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://webaudio.github.io/web-audio-api/#dom-biquadfilternode-detune
|
||||||
|
JS::NonnullGCPtr<AudioParam> BiquadFilterNode::detune() const
|
||||||
|
{
|
||||||
|
return m_detune;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://webaudio.github.io/web-audio-api/#dom-biquadfilternode-q
|
||||||
|
JS::NonnullGCPtr<AudioParam> BiquadFilterNode::q() const
|
||||||
|
{
|
||||||
|
return m_q;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://webaudio.github.io/web-audio-api/#dom-biquadfilternode-gain
|
||||||
|
JS::NonnullGCPtr<AudioParam> BiquadFilterNode::gain() const
|
||||||
|
{
|
||||||
|
return m_gain;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://webaudio.github.io/web-audio-api/#dom-biquadfilternode-getfrequencyresponse
|
||||||
|
WebIDL::ExceptionOr<void> BiquadFilterNode::get_frequency_response(JS::Handle<WebIDL::BufferSource> const& frequency_hz, JS::Handle<WebIDL::BufferSource> const& mag_response, JS::Handle<WebIDL::BufferSource> const& phase_response)
|
||||||
|
{
|
||||||
|
(void)frequency_hz;
|
||||||
|
(void)mag_response;
|
||||||
|
(void)phase_response;
|
||||||
|
dbgln("FIXME: Implement BiquadFilterNode::get_frequency_response(Float32Array, Float32Array, Float32Array)");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<BiquadFilterNode>> BiquadFilterNode::create(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, BiquadFilterOptions const& options)
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<BiquadFilterNode>> BiquadFilterNode::create(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context, BiquadFilterOptions const& options)
|
||||||
{
|
{
|
||||||
return construct_impl(realm, context, options);
|
return construct_impl(realm, context, options);
|
||||||
|
@ -44,6 +97,10 @@ void BiquadFilterNode::initialize(JS::Realm& realm)
|
||||||
void BiquadFilterNode::visit_edges(Cell::Visitor& visitor)
|
void BiquadFilterNode::visit_edges(Cell::Visitor& visitor)
|
||||||
{
|
{
|
||||||
Base::visit_edges(visitor);
|
Base::visit_edges(visitor);
|
||||||
|
visitor.visit(m_frequency);
|
||||||
|
visitor.visit(m_detune);
|
||||||
|
visitor.visit(m_q);
|
||||||
|
visitor.visit(m_gain);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <LibWeb/Bindings/BiquadFilterNodePrototype.h>
|
#include <LibWeb/Bindings/BiquadFilterNodePrototype.h>
|
||||||
#include <LibWeb/WebAudio/AudioNode.h>
|
#include <LibWeb/WebAudio/AudioNode.h>
|
||||||
|
#include <LibWeb/WebAudio/AudioParam.h>
|
||||||
|
|
||||||
namespace Web::WebAudio {
|
namespace Web::WebAudio {
|
||||||
|
|
||||||
|
@ -28,6 +29,14 @@ class BiquadFilterNode : public AudioNode {
|
||||||
public:
|
public:
|
||||||
virtual ~BiquadFilterNode() override;
|
virtual ~BiquadFilterNode() override;
|
||||||
|
|
||||||
|
WebIDL::ExceptionOr<void> set_type(Bindings::BiquadFilterType);
|
||||||
|
Bindings::BiquadFilterType type() const;
|
||||||
|
JS::NonnullGCPtr<AudioParam> frequency() const;
|
||||||
|
JS::NonnullGCPtr<AudioParam> detune() const;
|
||||||
|
JS::NonnullGCPtr<AudioParam> q() const;
|
||||||
|
JS::NonnullGCPtr<AudioParam> gain() const;
|
||||||
|
WebIDL::ExceptionOr<void> get_frequency_response(JS::Handle<WebIDL::BufferSource> const&, JS::Handle<WebIDL::BufferSource> const&, JS::Handle<WebIDL::BufferSource> const&);
|
||||||
|
|
||||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<BiquadFilterNode>> create(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, BiquadFilterOptions const& = {});
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<BiquadFilterNode>> create(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, BiquadFilterOptions const& = {});
|
||||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<BiquadFilterNode>> construct_impl(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, BiquadFilterOptions const& = {});
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<BiquadFilterNode>> construct_impl(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, BiquadFilterOptions const& = {});
|
||||||
|
|
||||||
|
@ -36,6 +45,13 @@ protected:
|
||||||
|
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
virtual void visit_edges(Cell::Visitor&) override;
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Bindings::BiquadFilterType m_type { Bindings::BiquadFilterType::Lowpass };
|
||||||
|
JS::NonnullGCPtr<AudioParam> m_frequency;
|
||||||
|
JS::NonnullGCPtr<AudioParam> m_detune;
|
||||||
|
JS::NonnullGCPtr<AudioParam> m_q;
|
||||||
|
JS::NonnullGCPtr<AudioParam> m_gain;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,10 @@ dictionary BiquadFilterOptions : AudioNodeOptions {
|
||||||
[Exposed=Window]
|
[Exposed=Window]
|
||||||
interface BiquadFilterNode : AudioNode {
|
interface BiquadFilterNode : AudioNode {
|
||||||
constructor (BaseAudioContext context, optional BiquadFilterOptions options = {});
|
constructor (BaseAudioContext context, optional BiquadFilterOptions options = {});
|
||||||
[FIXME] attribute BiquadFilterType type;
|
attribute BiquadFilterType type;
|
||||||
[FIXME] readonly attribute AudioParam frequency;
|
readonly attribute AudioParam frequency;
|
||||||
[FIXME] readonly attribute AudioParam detune;
|
readonly attribute AudioParam detune;
|
||||||
[FIXME] readonly attribute AudioParam Q;
|
readonly attribute AudioParam Q;
|
||||||
[FIXME] readonly attribute AudioParam gain;
|
readonly attribute AudioParam gain;
|
||||||
[FIXME] undefined getFrequencyResponse (Float32Array frequencyHz, Float32Array magResponse, Float32Array phaseResponse);
|
undefined getFrequencyResponse (Float32Array frequencyHz, Float32Array magResponse, Float32Array phaseResponse);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue