OscillatorNode.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Bindings/OscillatorNodePrototype.h>
  8. #include <LibWeb/WebAudio/AudioScheduledSourceNode.h>
  9. namespace Web::WebAudio {
  10. // https://webaudio.github.io/web-audio-api/#OscillatorOptions
  11. struct OscillatorOptions : AudioNodeOptions {
  12. Bindings::OscillatorType type { Bindings::OscillatorType::Sine };
  13. float frequency { 440 };
  14. float detune { 0 };
  15. JS::GCPtr<PeriodicWave> periodic_wave;
  16. };
  17. // https://webaudio.github.io/web-audio-api/#OscillatorNode
  18. class OscillatorNode : public AudioScheduledSourceNode {
  19. WEB_PLATFORM_OBJECT(OscillatorNode, AudioScheduledSourceNode);
  20. JS_DECLARE_ALLOCATOR(OscillatorNode);
  21. public:
  22. virtual ~OscillatorNode() override;
  23. static WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> create(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, OscillatorOptions const& = {});
  24. static WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> construct_impl(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, OscillatorOptions const& = {});
  25. Bindings::OscillatorType type() const;
  26. WebIDL::ExceptionOr<void> set_type(Bindings::OscillatorType);
  27. protected:
  28. OscillatorNode(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, OscillatorOptions const& = {});
  29. virtual void initialize(JS::Realm&) override;
  30. virtual void visit_edges(Cell::Visitor&) override;
  31. private:
  32. static WebIDL::ExceptionOr<void> verify_valid_type(JS::Realm&, Bindings::OscillatorType);
  33. // https://webaudio.github.io/web-audio-api/#dom-oscillatornode-type
  34. Bindings::OscillatorType m_type { Bindings::OscillatorType::Sine };
  35. };
  36. }