|
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 |
|
13 namespace mozilla { |
|
14 namespace dom { |
|
15 |
|
16 class AudioContext; |
|
17 |
|
18 class AnalyserNode : public AudioNode |
|
19 { |
|
20 public: |
|
21 explicit AnalyserNode(AudioContext* aContext); |
|
22 |
|
23 NS_DECL_ISUPPORTS_INHERITED |
|
24 |
|
25 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
26 |
|
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); |
|
55 |
|
56 virtual const char* NodeType() const |
|
57 { |
|
58 return "AnalyserNode"; |
|
59 } |
|
60 |
|
61 virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE; |
|
62 virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE; |
|
63 |
|
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); |
|
70 |
|
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 }; |
|
80 |
|
81 } |
|
82 } |
|
83 |
|
84 #endif |
|
85 |