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 ConvolverNode_h_ 8 #define ConvolverNode_h_ 9 10 #include "AudioNode.h" 11 #include "AudioBuffer.h" 12 #include "nsPrintfCString.h" 13 14 namespace mozilla { 15 namespace dom { 16 17 class AudioContext; 18 struct ConvolverOptions; 19 20 class ConvolverNode final : public AudioNode { 21 public: 22 static already_AddRefed<ConvolverNode> Create( 23 JSContext* aCx, AudioContext& aAudioContext, 24 const ConvolverOptions& aOptions, ErrorResult& aRv); 25 26 NS_DECL_ISUPPORTS_INHERITED 27 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ConvolverNode, AudioNode); 28 Constructor(const GlobalObject & aGlobal,AudioContext & aAudioContext,const ConvolverOptions & aOptions,ErrorResult & aRv)29 static already_AddRefed<ConvolverNode> Constructor( 30 const GlobalObject& aGlobal, AudioContext& aAudioContext, 31 const ConvolverOptions& aOptions, ErrorResult& aRv) { 32 return Create(aGlobal.Context(), aAudioContext, aOptions, aRv); 33 } 34 35 JSObject* WrapObject(JSContext* aCx, 36 JS::Handle<JSObject*> aGivenProto) override; 37 GetBuffer(JSContext * aCx)38 AudioBuffer* GetBuffer(JSContext* aCx) const { return mBuffer; } 39 40 void SetBuffer(JSContext* aCx, AudioBuffer* aBuffer, ErrorResult& aRv); 41 Normalize()42 bool Normalize() const { return mNormalize; } 43 44 void SetNormalize(bool aNormal); 45 SetChannelCount(uint32_t aChannelCount,ErrorResult & aRv)46 void SetChannelCount(uint32_t aChannelCount, ErrorResult& aRv) override { 47 if (aChannelCount > 2) { 48 aRv.ThrowNotSupportedError( 49 nsPrintfCString("%u is greater than 2", aChannelCount)); 50 return; 51 } 52 AudioNode::SetChannelCount(aChannelCount, aRv); 53 } SetChannelCountModeValue(ChannelCountMode aMode,ErrorResult & aRv)54 void SetChannelCountModeValue(ChannelCountMode aMode, 55 ErrorResult& aRv) override { 56 if (aMode == ChannelCountMode::Max) { 57 aRv.ThrowNotSupportedError("Cannot set channel count mode to \"max\""); 58 return; 59 } 60 AudioNode::SetChannelCountModeValue(aMode, aRv); 61 } 62 NodeType()63 const char* NodeType() const override { return "ConvolverNode"; } 64 65 size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override; 66 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override; 67 68 private: 69 explicit ConvolverNode(AudioContext* aContext); 70 ~ConvolverNode() = default; 71 72 RefPtr<AudioBuffer> mBuffer; 73 bool mNormalize; 74 }; 75 76 } // end namespace dom 77 } // end namespace mozilla 78 79 #endif 80