tor-browser

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

ConvolverNode.h (2428B)


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