WebAudio: BiquadFilterNode: Implement AudioParams and stub rest

This commit is contained in:
bbb651 2024-07-27 14:01:13 +03:00 committed by Andreas Kling
parent 6d33cc2b3a
commit 150cef62a0
Notes: github-actions[bot] 2024-07-28 19:42:21 +00:00
3 changed files with 80 additions and 7 deletions

View file

@ -4,22 +4,75 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/AudioParamPrototype.h>
#include <LibWeb/Bindings/BiquadFilterNodePrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/WebAudio/AudioNode.h>
#include <LibWeb/WebAudio/AudioParam.h>
#include <LibWeb/WebAudio/BiquadFilterNode.h>
namespace Web::WebAudio {
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)
, 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;
// 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)
{
return construct_impl(realm, context, options);
@ -44,6 +97,10 @@ void BiquadFilterNode::initialize(JS::Realm& realm)
void BiquadFilterNode::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_frequency);
visitor.visit(m_detune);
visitor.visit(m_q);
visitor.visit(m_gain);
}
}

View file

@ -8,6 +8,7 @@
#include <LibWeb/Bindings/BiquadFilterNodePrototype.h>
#include <LibWeb/WebAudio/AudioNode.h>
#include <LibWeb/WebAudio/AudioParam.h>
namespace Web::WebAudio {
@ -28,6 +29,14 @@ class BiquadFilterNode : public AudioNode {
public:
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>> construct_impl(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, BiquadFilterOptions const& = {});
@ -36,6 +45,13 @@ protected:
virtual void initialize(JS::Realm&) 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;
};
}

View file

@ -24,10 +24,10 @@ dictionary BiquadFilterOptions : AudioNodeOptions {
[Exposed=Window]
interface BiquadFilterNode : AudioNode {
constructor (BaseAudioContext context, optional BiquadFilterOptions options = {});
[FIXME] attribute BiquadFilterType type;
[FIXME] readonly attribute AudioParam frequency;
[FIXME] readonly attribute AudioParam detune;
[FIXME] readonly attribute AudioParam Q;
[FIXME] readonly attribute AudioParam gain;
[FIXME] undefined getFrequencyResponse (Float32Array frequencyHz, Float32Array magResponse, Float32Array phaseResponse);
attribute BiquadFilterType type;
readonly attribute AudioParam frequency;
readonly attribute AudioParam detune;
readonly attribute AudioParam Q;
readonly attribute AudioParam gain;
undefined getFrequencyResponse (Float32Array frequencyHz, Float32Array magResponse, Float32Array phaseResponse);
};