content/media/webaudio/AnalyserNode.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     7 #ifndef AnalyserNode_h_
     8 #define AnalyserNode_h_
    10 #include "AudioNode.h"
    11 #include "FFTBlock.h"
    13 namespace mozilla {
    14 namespace dom {
    16 class AudioContext;
    18 class AnalyserNode : public AudioNode
    19 {
    20 public:
    21   explicit AnalyserNode(AudioContext* aContext);
    23   NS_DECL_ISUPPORTS_INHERITED
    25   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    27   void GetFloatFrequencyData(const Float32Array& aArray);
    28   void GetByteFrequencyData(const Uint8Array& aArray);
    29   void GetFloatTimeDomainData(const Float32Array& aArray);
    30   void GetByteTimeDomainData(const Uint8Array& aArray);
    31   uint32_t FftSize() const
    32   {
    33     return mAnalysisBlock.FFTSize();
    34   }
    35   void SetFftSize(uint32_t aValue, ErrorResult& aRv);
    36   uint32_t FrequencyBinCount() const
    37   {
    38     return FftSize() / 2;
    39   }
    40   double MinDecibels() const
    41   {
    42     return mMinDecibels;
    43   }
    44   void SetMinDecibels(double aValue, ErrorResult& aRv);
    45   double MaxDecibels() const
    46   {
    47     return mMaxDecibels;
    48   }
    49   void SetMaxDecibels(double aValue, ErrorResult& aRv);
    50   double SmoothingTimeConstant() const
    51   {
    52     return mSmoothingTimeConstant;
    53   }
    54   void SetSmoothingTimeConstant(double aValue, ErrorResult& aRv);
    56   virtual const char* NodeType() const
    57   {
    58     return "AnalyserNode";
    59   }
    61   virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
    62   virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
    64 private:
    65   friend class AnalyserNodeEngine;
    66   void AppendChunk(const AudioChunk& aChunk);
    67   bool AllocateBuffer();
    68   bool FFTAnalysis();
    69   void ApplyBlackmanWindow(float* aBuffer, uint32_t aSize);
    71 private:
    72   FFTBlock mAnalysisBlock;
    73   double mMinDecibels;
    74   double mMaxDecibels;
    75   double mSmoothingTimeConstant;
    76   uint32_t mWriteIndex;
    77   FallibleTArray<float> mBuffer;
    78   FallibleTArray<float> mOutputBuffer;
    79 };
    81 }
    82 }
    84 #endif

mercurial