From 6466fca20a23b09fd554a1a53575e0c26b58e936 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Tue, 28 May 2024 15:48:10 +1200 Subject: [PATCH] LibWeb: Implement BaseAudioContext.createGain --- .../Text/expected/WebAudio/GainNode.txt | 5 ++++ .../LibWeb/Text/input/WebAudio/GainNode.html | 23 +++++++++++++++++++ .../LibWeb/WebAudio/BaseAudioContext.cpp | 8 +++++++ .../LibWeb/WebAudio/BaseAudioContext.h | 1 + .../LibWeb/WebAudio/BaseAudioContext.idl | 3 ++- 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/WebAudio/GainNode.txt create mode 100644 Tests/LibWeb/Text/input/WebAudio/GainNode.html diff --git a/Tests/LibWeb/Text/expected/WebAudio/GainNode.txt b/Tests/LibWeb/Text/expected/WebAudio/GainNode.txt new file mode 100644 index 00000000000..753e15b8064 --- /dev/null +++ b/Tests/LibWeb/Text/expected/WebAudio/GainNode.txt @@ -0,0 +1,5 @@ +GainNode +AudioNode +EventTarget +Object +[object AudioParam] current: 1, default: 1, min: -3.4028234663852886e+38, max: 3.4028234663852886e+38, rate: a-rate diff --git a/Tests/LibWeb/Text/input/WebAudio/GainNode.html b/Tests/LibWeb/Text/input/WebAudio/GainNode.html new file mode 100644 index 00000000000..5570980b7da --- /dev/null +++ b/Tests/LibWeb/Text/input/WebAudio/GainNode.html @@ -0,0 +1,23 @@ + + diff --git a/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp index 28bb2f4f45e..6bd67d0fa23 100644 --- a/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp +++ b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace Web::WebAudio { @@ -61,6 +62,13 @@ WebIDL::ExceptionOr> BaseAudioContext:: return DynamicsCompressorNode::create(realm(), *this); } +// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-creategain +JS::NonnullGCPtr BaseAudioContext::create_gain() +{ + // Factory method for GainNode. + return GainNode::create(realm(), *this); +} + // https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer WebIDL::ExceptionOr BaseAudioContext::verify_audio_options_inside_nominal_range(JS::Realm& realm, WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate) { diff --git a/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.h b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.h index 7cf74f96d6a..687deec85fb 100644 --- a/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.h +++ b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.h @@ -50,6 +50,7 @@ public: WebIDL::ExceptionOr> create_buffer(WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate); WebIDL::ExceptionOr> create_oscillator(); WebIDL::ExceptionOr> create_dynamics_compressor(); + JS::NonnullGCPtr create_gain(); protected: explicit BaseAudioContext(JS::Realm&, float m_sample_rate = 0); diff --git a/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.idl b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.idl index 2b34e10fdb3..5a2132d68b8 100644 --- a/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.idl +++ b/Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.idl @@ -2,6 +2,7 @@ #import #import #import +#import #import // https://www.w3.org/TR/webaudio/#enumdef-audiocontextstate @@ -33,7 +34,7 @@ interface BaseAudioContext : EventTarget { [FIXME] ConvolverNode createConvolver (); [FIXME] DelayNode createDelay (optional double maxDelayTime = 1.0); DynamicsCompressorNode createDynamicsCompressor(); - [FIXME] GainNode createGain (); + GainNode createGain(); [FIXME] IIRFilterNode createIIRFilter (sequence feedforward, sequence feedback); OscillatorNode createOscillator(); [FIXME] PannerNode createPanner ();