tor-browser

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

DynamicsCompressorNode.h (2856B)


      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 DynamicsCompressorNode_h_
      8 #define DynamicsCompressorNode_h_
      9 
     10 #include "AudioNode.h"
     11 #include "AudioParam.h"
     12 
     13 namespace mozilla::dom {
     14 
     15 class AudioContext;
     16 struct DynamicsCompressorOptions;
     17 
     18 class DynamicsCompressorNode final : public AudioNode {
     19 public:
     20  static already_AddRefed<DynamicsCompressorNode> Create(
     21      AudioContext& aAudioContext, const DynamicsCompressorOptions& aOptions,
     22      ErrorResult& aRv);
     23 
     24  NS_DECL_ISUPPORTS_INHERITED
     25  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DynamicsCompressorNode, AudioNode)
     26 
     27  static already_AddRefed<DynamicsCompressorNode> Constructor(
     28      const GlobalObject& aGlobal, AudioContext& aAudioContext,
     29      const DynamicsCompressorOptions& aOptions, ErrorResult& aRv) {
     30    return Create(aAudioContext, aOptions, aRv);
     31  }
     32 
     33  JSObject* WrapObject(JSContext* aCx,
     34                       JS::Handle<JSObject*> aGivenProto) override;
     35 
     36  AudioParam* Threshold() const { return mThreshold; }
     37 
     38  AudioParam* Knee() const { return mKnee; }
     39 
     40  AudioParam* Ratio() const { return mRatio; }
     41 
     42  AudioParam* Attack() const { return mAttack; }
     43 
     44  // Called GetRelease to prevent clashing with the nsISupports::Release name
     45  AudioParam* GetRelease() const { return mRelease; }
     46 
     47  float Reduction() const { return mReduction; }
     48 
     49  const char* NodeType() const override { return "DynamicsCompressorNode"; }
     50 
     51  size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
     52  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
     53 
     54  void SetReduction(float aReduction) {
     55    MOZ_ASSERT(NS_IsMainThread());
     56    mReduction = aReduction;
     57  }
     58 
     59  void SetChannelCountModeValue(ChannelCountMode aMode,
     60                                ErrorResult& aRv) override {
     61    if (aMode == ChannelCountMode::Max) {
     62      aRv.ThrowNotSupportedError("Cannot set channel count mode to \"max\"");
     63      return;
     64    }
     65    AudioNode::SetChannelCountModeValue(aMode, aRv);
     66  }
     67 
     68  void SetChannelCount(uint32_t aChannelCount, ErrorResult& aRv) override {
     69    if (aChannelCount > 2) {
     70      aRv.ThrowNotSupportedError(
     71          nsPrintfCString("%u is greater than 2", aChannelCount));
     72      return;
     73    }
     74    AudioNode::SetChannelCount(aChannelCount, aRv);
     75  }
     76 
     77 private:
     78  explicit DynamicsCompressorNode(AudioContext* aContext);
     79  ~DynamicsCompressorNode() = default;
     80 
     81  RefPtr<AudioParam> mThreshold;
     82  RefPtr<AudioParam> mKnee;
     83  RefPtr<AudioParam> mRatio;
     84  float mReduction;
     85  RefPtr<AudioParam> mAttack;
     86  RefPtr<AudioParam> mRelease;
     87 };
     88 
     89 }  // namespace mozilla::dom
     90 
     91 #endif