2013-04-01 03:41:14 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef AnalyserNode_h_
|
|
|
|
#define AnalyserNode_h_
|
|
|
|
|
|
|
|
#include "AudioNode.h"
|
2013-06-10 20:08:21 +00:00
|
|
|
#include "FFTBlock.h"
|
2013-11-13 03:07:31 +00:00
|
|
|
#include "AlignedTArray.h"
|
2013-04-01 03:41:14 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class AudioContext;
|
2016-12-15 18:24:41 +00:00
|
|
|
struct AnalyserOptions;
|
2013-04-01 03:41:14 +00:00
|
|
|
|
2015-04-28 06:42:00 +00:00
|
|
|
class AnalyserNode final : public AudioNode
|
2013-04-01 03:41:14 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-12-15 18:24:41 +00:00
|
|
|
static already_AddRefed<AnalyserNode>
|
|
|
|
Create(AudioContext& aAudioContext, const AnalyserOptions& aOptions,
|
|
|
|
ErrorResult& aRv);
|
2013-04-01 03:41:14 +00:00
|
|
|
|
2018-02-12 20:44:40 +00:00
|
|
|
NS_INLINE_DECL_REFCOUNTING_INHERITED(AnalyserNode, AudioNode)
|
2013-04-01 03:41:14 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-04-01 03:41:14 +00:00
|
|
|
|
2016-12-15 18:24:41 +00:00
|
|
|
static already_AddRefed<AnalyserNode>
|
|
|
|
Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext,
|
|
|
|
const AnalyserOptions& aOptions, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
return Create(aAudioContext, aOptions, aRv);
|
|
|
|
}
|
|
|
|
|
2013-08-05 17:40:01 +00:00
|
|
|
void GetFloatFrequencyData(const Float32Array& aArray);
|
|
|
|
void GetByteFrequencyData(const Uint8Array& aArray);
|
2014-02-25 10:30:48 +00:00
|
|
|
void GetFloatTimeDomainData(const Float32Array& aArray);
|
2013-08-05 17:40:01 +00:00
|
|
|
void GetByteTimeDomainData(const Uint8Array& aArray);
|
2013-04-01 03:41:14 +00:00
|
|
|
uint32_t FftSize() const
|
|
|
|
{
|
2013-06-10 20:08:21 +00:00
|
|
|
return mAnalysisBlock.FFTSize();
|
2013-04-01 03:41:14 +00:00
|
|
|
}
|
|
|
|
void SetFftSize(uint32_t aValue, ErrorResult& aRv);
|
|
|
|
uint32_t FrequencyBinCount() const
|
|
|
|
{
|
|
|
|
return FftSize() / 2;
|
|
|
|
}
|
|
|
|
double MinDecibels() const
|
|
|
|
{
|
|
|
|
return mMinDecibels;
|
|
|
|
}
|
|
|
|
void SetMinDecibels(double aValue, ErrorResult& aRv);
|
|
|
|
double MaxDecibels() const
|
|
|
|
{
|
|
|
|
return mMaxDecibels;
|
|
|
|
}
|
|
|
|
void SetMaxDecibels(double aValue, ErrorResult& aRv);
|
|
|
|
double SmoothingTimeConstant() const
|
|
|
|
{
|
|
|
|
return mSmoothingTimeConstant;
|
|
|
|
}
|
|
|
|
void SetSmoothingTimeConstant(double aValue, ErrorResult& aRv);
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual const char* NodeType() const override
|
2014-04-13 18:08:10 +00:00
|
|
|
{
|
|
|
|
return "AnalyserNode";
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
|
|
|
|
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
|
2014-04-13 18:08:10 +00:00
|
|
|
|
2018-04-26 14:32:52 +00:00
|
|
|
void SetMinAndMaxDecibels(double aMinValue, double aMaxValue, ErrorResult& aRv);
|
|
|
|
|
2013-04-01 21:35:18 +00:00
|
|
|
private:
|
2016-12-15 18:24:41 +00:00
|
|
|
~AnalyserNode() = default;
|
|
|
|
|
2013-04-01 21:35:18 +00:00
|
|
|
friend class AnalyserNodeEngine;
|
|
|
|
void AppendChunk(const AudioChunk& aChunk);
|
|
|
|
bool AllocateBuffer();
|
2013-04-01 23:26:17 +00:00
|
|
|
bool FFTAnalysis();
|
|
|
|
void ApplyBlackmanWindow(float* aBuffer, uint32_t aSize);
|
2015-07-22 07:50:37 +00:00
|
|
|
void GetTimeDomainData(float* aData, size_t aLength);
|
2013-04-01 21:35:18 +00:00
|
|
|
|
2013-04-01 03:41:14 +00:00
|
|
|
private:
|
2016-12-15 18:24:41 +00:00
|
|
|
explicit AnalyserNode(AudioContext* aContext);
|
|
|
|
|
2013-06-10 20:08:21 +00:00
|
|
|
FFTBlock mAnalysisBlock;
|
2015-07-22 07:50:37 +00:00
|
|
|
nsTArray<AudioChunk> mChunks;
|
2013-04-01 03:41:14 +00:00
|
|
|
double mMinDecibels;
|
|
|
|
double mMaxDecibels;
|
|
|
|
double mSmoothingTimeConstant;
|
2015-07-22 07:50:37 +00:00
|
|
|
size_t mCurrentChunk = 0;
|
2015-07-15 19:58:18 +00:00
|
|
|
AlignedTArray<float> mOutputBuffer;
|
2013-04-01 03:41:14 +00:00
|
|
|
};
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-04-01 03:41:14 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|