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