/src/serenity/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibWeb/Bindings/OscillatorNodePrototype.h> |
10 | | #include <LibWeb/WebAudio/AudioScheduledSourceNode.h> |
11 | | |
12 | | namespace Web::WebAudio { |
13 | | |
14 | | // https://webaudio.github.io/web-audio-api/#OscillatorOptions |
15 | | struct OscillatorOptions : AudioNodeOptions { |
16 | | Bindings::OscillatorType type { Bindings::OscillatorType::Sine }; |
17 | | float frequency { 440 }; |
18 | | float detune { 0 }; |
19 | | JS::GCPtr<PeriodicWave> periodic_wave; |
20 | | }; |
21 | | |
22 | | // https://webaudio.github.io/web-audio-api/#OscillatorNode |
23 | | class OscillatorNode : public AudioScheduledSourceNode { |
24 | | WEB_PLATFORM_OBJECT(OscillatorNode, AudioScheduledSourceNode); |
25 | | JS_DECLARE_ALLOCATOR(OscillatorNode); |
26 | | |
27 | | public: |
28 | | virtual ~OscillatorNode() override; |
29 | | |
30 | | static WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> create(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, OscillatorOptions const& = {}); |
31 | | static WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> construct_impl(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, OscillatorOptions const& = {}); |
32 | | |
33 | | Bindings::OscillatorType type() const; |
34 | | WebIDL::ExceptionOr<void> set_type(Bindings::OscillatorType); |
35 | | |
36 | 0 | JS::NonnullGCPtr<AudioParam const> frequency() const { return m_frequency; } |
37 | 0 | WebIDL::UnsignedLong number_of_inputs() override { return 0; } |
38 | 0 | WebIDL::UnsignedLong number_of_outputs() override { return 1; } |
39 | | |
40 | | protected: |
41 | | OscillatorNode(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, OscillatorOptions const& = {}); |
42 | | |
43 | | virtual void initialize(JS::Realm&) override; |
44 | | virtual void visit_edges(Cell::Visitor&) override; |
45 | | |
46 | | private: |
47 | | static WebIDL::ExceptionOr<void> verify_valid_type(JS::Realm&, Bindings::OscillatorType); |
48 | | |
49 | | // https://webaudio.github.io/web-audio-api/#dom-oscillatornode-type |
50 | | Bindings::OscillatorType m_type { Bindings::OscillatorType::Sine }; |
51 | | |
52 | | // https://webaudio.github.io/web-audio-api/#dom-oscillatornode-frequency |
53 | | JS::NonnullGCPtr<AudioParam> m_frequency; |
54 | | }; |
55 | | |
56 | | } |