Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/AnalyserNode.h
Line
Count
Source (jump to first uncovered line)
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 AnalyserNode_h_
8
#define AnalyserNode_h_
9
10
#include "AudioNode.h"
11
#include "FFTBlock.h"
12
#include "AlignedTArray.h"
13
14
namespace mozilla {
15
namespace dom {
16
17
class AudioContext;
18
struct AnalyserOptions;
19
20
class AnalyserNode final : public AudioNode
21
{
22
public:
23
  static already_AddRefed<AnalyserNode>
24
  Create(AudioContext& aAudioContext, const AnalyserOptions& aOptions,
25
         ErrorResult& aRv);
26
27
  NS_INLINE_DECL_REFCOUNTING_INHERITED(AnalyserNode, AudioNode)
28
29
  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
30
31
  static already_AddRefed<AnalyserNode>
32
  Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext,
33
              const AnalyserOptions& aOptions, ErrorResult& aRv)
34
0
  {
35
0
    return Create(aAudioContext, aOptions, aRv);
36
0
  }
37
38
  void GetFloatFrequencyData(const Float32Array& aArray);
39
  void GetByteFrequencyData(const Uint8Array& aArray);
40
  void GetFloatTimeDomainData(const Float32Array& aArray);
41
  void GetByteTimeDomainData(const Uint8Array& aArray);
42
  uint32_t FftSize() const
43
0
  {
44
0
    return mAnalysisBlock.FFTSize();
45
0
  }
46
  void SetFftSize(uint32_t aValue, ErrorResult& aRv);
47
  uint32_t FrequencyBinCount() const
48
0
  {
49
0
    return FftSize() / 2;
50
0
  }
51
  double MinDecibels() const
52
0
  {
53
0
    return mMinDecibels;
54
0
  }
55
  void SetMinDecibels(double aValue, ErrorResult& aRv);
56
  double MaxDecibels() const
57
0
  {
58
0
    return mMaxDecibels;
59
0
  }
60
  void SetMaxDecibels(double aValue, ErrorResult& aRv);
61
  double SmoothingTimeConstant() const
62
0
  {
63
0
    return mSmoothingTimeConstant;
64
0
  }
65
  void SetSmoothingTimeConstant(double aValue, ErrorResult& aRv);
66
67
  virtual const char* NodeType() const override
68
0
  {
69
0
    return "AnalyserNode";
70
0
  }
71
72
  virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
73
  virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
74
75
  void SetMinAndMaxDecibels(double aMinValue, double aMaxValue, ErrorResult& aRv);
76
77
private:
78
0
  ~AnalyserNode() = default;
79
80
  friend class AnalyserNodeEngine;
81
  void AppendChunk(const AudioChunk& aChunk);
82
  bool AllocateBuffer();
83
  bool FFTAnalysis();
84
  void ApplyBlackmanWindow(float* aBuffer, uint32_t aSize);
85
  void GetTimeDomainData(float* aData, size_t aLength);
86
87
private:
88
  explicit AnalyserNode(AudioContext* aContext);
89
90
  FFTBlock mAnalysisBlock;
91
  nsTArray<AudioChunk> mChunks;
92
  double mMinDecibels;
93
  double mMaxDecibels;
94
  double mSmoothingTimeConstant;
95
  size_t mCurrentChunk = 0;
96
  AlignedTArray<float> mOutputBuffer;
97
};
98
99
} // namespace dom
100
} // namespace mozilla
101
102
#endif
103