Skip to content

Commit

Permalink
LibWeb: Use correct ranges for BiquadFilterNode parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
tcl3 committed Jan 4, 2025
1 parent c804d08 commit 6fc82e4
Show file tree
Hide file tree
Showing 4 changed files with 798 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Libraries/LibWeb/WebAudio/BiquadFilterNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <AK/Math.h>
#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/BaseAudioContext.h>
#include <LibWeb/WebAudio/BiquadFilterNode.h>

namespace Web::WebAudio {
Expand All @@ -18,10 +20,10 @@ GC_DEFINE_ALLOCATOR(BiquadFilterNode);
BiquadFilterNode::BiquadFilterNode(JS::Realm& realm, GC::Ref<BaseAudioContext> context, BiquadFilterOptions const& options)
: AudioNode(realm, context)
, m_type(options.type)
, 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_frequency(AudioParam::create(realm, options.frequency, 0, context->nyquist_frequency(), Bindings::AutomationRate::ARate))
, m_detune(AudioParam::create(realm, options.detune, -1200 * AK::log2(NumericLimits<float>::max()), 1200 * AK::log2(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))
, m_gain(AudioParam::create(realm, options.gain, NumericLimits<float>::lowest(), 40 * AK::log10(NumericLimits<float>::max()), Bindings::AutomationRate::ARate))
{
}

Expand Down
8 changes: 8 additions & 0 deletions Libraries/LibWeb/WebAudio/BiquadFilterNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,17 @@ class BiquadFilterNode : public AudioNode {

private:
Bindings::BiquadFilterType m_type { Bindings::BiquadFilterType::Lowpass };

// https://webaudio.github.io/web-audio-api/#dom-biquadfilternode-frequency
GC::Ref<AudioParam> m_frequency;

// https://webaudio.github.io/web-audio-api/#dom-biquadfilternode-detune
GC::Ref<AudioParam> m_detune;

// https://webaudio.github.io/web-audio-api/#dom-biquadfilternode-q
GC::Ref<AudioParam> m_q;

// https://webaudio.github.io/web-audio-api/#dom-biquadfilternode-gain
GC::Ref<AudioParam> m_gain;
};

Expand Down
Loading

0 comments on commit 6fc82e4

Please sign in to comment.