Skip to content

Commit

Permalink
LibWeb: Implement BaseAudioContext.createOscillator
Browse files Browse the repository at this point in the history
Which currently will always throw an exception as it is unimplemented
under the hood - but this gives all of the plumbing we need in order to
create a oscillator node as used in the reduced turnstyle testcase.
  • Loading branch information
shannonbooth committed Apr 28, 2024
1 parent 1f54b0c commit 15ed75e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/WebAudio/BaseAudioContext.h>
#include <LibWeb/WebAudio/OscillatorNode.h>

namespace Web::WebAudio {

Expand All @@ -35,6 +36,13 @@ WebIDL::CallbackType* BaseAudioContext::onstatechange()
return event_handler_attribute(HTML::EventNames::statechange);
}

// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createoscillator
WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> BaseAudioContext::create_oscillator()
{
// Factory method for an OscillatorNode.
return OscillatorNode::create(realm(), *this);
}

// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffer
WebIDL::ExceptionOr<void> BaseAudioContext::verify_audio_options_inside_nominal_range(JS::Realm& realm, WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate)
{
Expand Down
2 changes: 2 additions & 0 deletions Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class BaseAudioContext : public DOM::EventTarget {

static WebIDL::ExceptionOr<void> verify_audio_options_inside_nominal_range(JS::Realm&, WebIDL::UnsignedLong number_of_channels, WebIDL::UnsignedLong length, float sample_rate);

WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> create_oscillator();

protected:
explicit BaseAudioContext(JS::Realm&);

Expand Down
3 changes: 2 additions & 1 deletion Userland/Libraries/LibWeb/WebAudio/BaseAudioContext.idl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import <DOM/EventTarget.idl>
#import <DOM/EventHandler.idl>
#import <WebAudio/OscillatorNode.idl>

// https://www.w3.org/TR/webaudio/#enumdef-audiocontextstate
enum AudioContextState { "suspended", "running", "closed" };
Expand Down Expand Up @@ -32,7 +33,7 @@ interface BaseAudioContext : EventTarget {
// FIXME: DynamicsCompressorNode createDynamicsCompressor ();
// FIXME: GainNode createGain ();
// FIXME: IIRFilterNode createIIRFilter (sequence<double> feedforward, sequence<double> feedback);
// FIXME: OscillatorNode createOscillator ();
OscillatorNode createOscillator();
// FIXME: PannerNode createPanner ();
// FIXME: PeriodicWave createPeriodicWave (sequence<float> real, sequence<float> imag, optional PeriodicWaveConstraints constraints = {});
// FIXME: ScriptProcessorNode createScriptProcessor(optional unsigned long bufferSize = 0, optional unsigned long numberOfInputChannels = 2, optional unsigned long numberOfOutputChannels = 2);
Expand Down

0 comments on commit 15ed75e

Please sign in to comment.