/* * 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 }; GC::Ptr periodic_wave; }; // https://webaudio.github.io/web-audio-api/#OscillatorNode class OscillatorNode : public AudioScheduledSourceNode { WEB_PLATFORM_OBJECT(OscillatorNode, AudioScheduledSourceNode); GC_DECLARE_ALLOCATOR(OscillatorNode); public: virtual ~OscillatorNode() override; static WebIDL::ExceptionOr> create(JS::Realm&, GC::Ref, OscillatorOptions const& = {}); static WebIDL::ExceptionOr> construct_impl(JS::Realm&, GC::Ref, OscillatorOptions const& = {}); Bindings::OscillatorType type() const; WebIDL::ExceptionOr set_type(Bindings::OscillatorType); void set_periodic_wave(GC::Ptr); GC::Ref frequency() const { return m_frequency; } GC::Ref detune() const { return m_detune; } WebIDL::UnsignedLong number_of_inputs() override { return 0; } WebIDL::UnsignedLong number_of_outputs() override { return 1; } protected: OscillatorNode(JS::Realm&, GC::Ref, OscillatorOptions const& = {}); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; private: // 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 GC::Ref m_frequency; // https://webaudio.github.io/web-audio-api/#dom-oscillatornode-detune GC::Ref m_detune; GC::Ptr m_periodic_wave; }; }