tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

OscillatorNode.h (2921B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef OscillatorNode_h_
      8 #define OscillatorNode_h_
      9 
     10 #include "AudioParam.h"
     11 #include "AudioScheduledSourceNode.h"
     12 #include "PeriodicWave.h"
     13 #include "mozilla/dom/OscillatorNodeBinding.h"
     14 
     15 namespace mozilla::dom {
     16 
     17 class AudioContext;
     18 struct OscillatorOptions;
     19 
     20 class OscillatorNode final : public AudioScheduledSourceNode,
     21                             public MainThreadMediaTrackListener {
     22 public:
     23  static already_AddRefed<OscillatorNode> Create(
     24      AudioContext& aAudioContext, const OscillatorOptions& aOptions,
     25      ErrorResult& aRv);
     26 
     27  NS_DECL_ISUPPORTS_INHERITED
     28  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(OscillatorNode,
     29                                           AudioScheduledSourceNode)
     30 
     31  static already_AddRefed<OscillatorNode> Constructor(
     32      const GlobalObject& aGlobal, AudioContext& aAudioContext,
     33      const OscillatorOptions& aOptions, ErrorResult& aRv) {
     34    return Create(aAudioContext, aOptions, aRv);
     35  }
     36 
     37  JSObject* WrapObject(JSContext* aCx,
     38                       JS::Handle<JSObject*> aGivenProto) override;
     39 
     40  void DestroyMediaTrack() override;
     41 
     42  uint16_t NumberOfInputs() const final { return 0; }
     43 
     44  OscillatorType Type() const { return mType; }
     45  void SetType(OscillatorType aType, ErrorResult& aRv) {
     46    if (aType == OscillatorType::Custom) {
     47      // ::Custom can only be set by setPeriodicWave().
     48      // https://github.com/WebAudio/web-audio-api/issues/105 for exception.
     49      aRv.ThrowInvalidStateError("Can't set type to \"custom\"");
     50      return;
     51    }
     52    mType = aType;
     53    SendTypeToTrack();
     54  }
     55 
     56  AudioParam* Frequency() const { return mFrequency; }
     57  AudioParam* Detune() const { return mDetune; }
     58 
     59  void Start(double aWhen, ErrorResult& aRv) override;
     60  void Stop(double aWhen, ErrorResult& aRv) override;
     61 
     62  void SetPeriodicWave(PeriodicWave& aPeriodicWave) {
     63    mPeriodicWave = &aPeriodicWave;
     64    // SendTypeToTrack will call SendPeriodicWaveToTrack for us.
     65    mType = OscillatorType::Custom;
     66    SendTypeToTrack();
     67  }
     68 
     69  void NotifyMainThreadTrackEnded() override;
     70 
     71  const char* NodeType() const override { return "OscillatorNode"; }
     72 
     73  size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
     74  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
     75 
     76 private:
     77  explicit OscillatorNode(AudioContext* aContext);
     78  ~OscillatorNode() = default;
     79 
     80  void SendTypeToTrack();
     81  void SendPeriodicWaveToTrack();
     82 
     83  OscillatorType mType;
     84  RefPtr<PeriodicWave> mPeriodicWave;
     85  RefPtr<AudioParam> mFrequency;
     86  RefPtr<AudioParam> mDetune;
     87  bool mStartCalled;
     88 };
     89 
     90 }  // namespace mozilla::dom
     91 
     92 #endif