/* * Copyright (c) 2024, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include namespace Web::WebAudio { // https://webaudio.github.io/web-audio-api/#OscillatorOptions struct OscillatorOptions : AudioNodeOptions { Bindings::OscillatorType type { Bindings::OscillatorType::Sine }; float frequency { 440 }; float detune { 0 }; JS::GCPtr periodic_wave; }; // https://webaudio.github.io/web-audio-api/#OscillatorNode class OscillatorNode : public AudioScheduledSourceNode { WEB_PLATFORM_OBJECT(OscillatorNode, AudioScheduledSourceNode); JS_DECLARE_ALLOCATOR(OscillatorNode); public: virtual ~OscillatorNode() override; static WebIDL::ExceptionOr> create(JS::Realm&, JS::NonnullGCPtr, OscillatorOptions const& = {}); static WebIDL::ExceptionOr> construct_impl(JS::Realm&, JS::NonnullGCPtr, OscillatorOptions const& = {}); Bindings::OscillatorType type() const; WebIDL::ExceptionOr set_type(Bindings::OscillatorType); JS::NonnullGCPtr frequency() const { return m_frequency; } protected: OscillatorNode(JS::Realm&, JS::NonnullGCPtr, OscillatorOptions const& = {}); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; private: static WebIDL::ExceptionOr verify_valid_type(JS::Realm&, Bindings::OscillatorType); // https://webaudio.github.io/web-audio-api/#dom-oscillatornode-type Bindings::OscillatorType m_type { Bindings::OscillatorType::Sine }; // https://webaudio.github.io/web-audio-api/#dom-oscillatornode-frequency JS::NonnullGCPtr m_frequency; }; }