2012-11-05 18:14:13 -08: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 PannerNode_h_
|
|
|
|
#define PannerNode_h_
|
|
|
|
|
|
|
|
#include "AudioNode.h"
|
2013-03-11 16:09:27 -07:00
|
|
|
#include "mozilla/dom/PannerNodeBinding.h"
|
2012-11-05 18:14:13 -08:00
|
|
|
#include "ThreeDPoint.h"
|
2013-03-12 16:28:30 -07:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2013-06-23 16:22:10 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-03-20 17:12:07 -07:00
|
|
|
#include "WebAudioUtils.h"
|
2013-04-11 05:47:57 -07:00
|
|
|
#include <set>
|
2012-11-05 18:14:13 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class AudioContext;
|
2013-04-11 05:47:57 -07:00
|
|
|
class AudioBufferSourceNode;
|
2012-11-05 18:14:13 -08:00
|
|
|
|
2013-03-12 16:28:30 -07:00
|
|
|
class PannerNode : public AudioNode,
|
|
|
|
public SupportsWeakPtr<PannerNode>
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
|
|
|
public:
|
2014-02-20 18:33:49 -08:00
|
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(PannerNode)
|
2012-11-05 18:14:13 -08:00
|
|
|
explicit PannerNode(AudioContext* aContext);
|
2013-07-16 05:45:41 -07:00
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2012-11-05 18:14:13 -08:00
|
|
|
|
2013-07-16 05:45:41 -07:00
|
|
|
virtual void DestroyMediaStream() MOZ_OVERRIDE;
|
|
|
|
|
2013-09-04 12:44:35 -07:00
|
|
|
virtual void SetChannelCount(uint32_t aChannelCount, ErrorResult& aRv) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
if (aChannelCount > 2) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AudioNode::SetChannelCount(aChannelCount, aRv);
|
|
|
|
}
|
|
|
|
virtual void SetChannelCountModeValue(ChannelCountMode aMode, ErrorResult& aRv) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
if (aMode == ChannelCountMode::Max) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AudioNode::SetChannelCountModeValue(aMode, aRv);
|
|
|
|
}
|
|
|
|
|
2013-04-29 11:06:40 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PannerNode, AudioNode)
|
|
|
|
|
2013-03-11 16:09:27 -07:00
|
|
|
PanningModelType PanningModel() const
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
2013-03-11 16:09:27 -07:00
|
|
|
return mPanningModel;
|
2012-11-05 18:14:13 -08:00
|
|
|
}
|
2013-03-11 16:09:27 -07:00
|
|
|
void SetPanningModel(PanningModelType aPanningModel)
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
2013-03-11 16:09:27 -07:00
|
|
|
mPanningModel = aPanningModel;
|
2013-03-12 11:34:55 -07:00
|
|
|
SendInt32ParameterToStream(PANNING_MODEL, int32_t(mPanningModel));
|
2012-11-05 18:14:13 -08:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:09:27 -07:00
|
|
|
DistanceModelType DistanceModel() const
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
2013-03-11 16:09:27 -07:00
|
|
|
return mDistanceModel;
|
2012-11-05 18:14:13 -08:00
|
|
|
}
|
2013-03-11 16:09:27 -07:00
|
|
|
void SetDistanceModel(DistanceModelType aDistanceModel)
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
2013-03-11 16:09:27 -07:00
|
|
|
mDistanceModel = aDistanceModel;
|
2013-03-12 11:34:55 -07:00
|
|
|
SendInt32ParameterToStream(DISTANCE_MODEL, int32_t(mDistanceModel));
|
2012-11-05 18:14:13 -08:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:09:27 -07:00
|
|
|
void SetPosition(double aX, double aY, double aZ)
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
2013-03-20 17:12:07 -07:00
|
|
|
if (WebAudioUtils::FuzzyEqual(mPosition.x, aX) &&
|
|
|
|
WebAudioUtils::FuzzyEqual(mPosition.y, aY) &&
|
|
|
|
WebAudioUtils::FuzzyEqual(mPosition.z, aZ)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-05 18:14:13 -08:00
|
|
|
mPosition.x = aX;
|
|
|
|
mPosition.y = aY;
|
|
|
|
mPosition.z = aZ;
|
2013-03-12 11:34:55 -07:00
|
|
|
SendThreeDPointParameterToStream(POSITION, mPosition);
|
2012-11-05 18:14:13 -08:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:09:27 -07:00
|
|
|
void SetOrientation(double aX, double aY, double aZ)
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
2013-09-04 02:20:59 -07:00
|
|
|
ThreeDPoint orientation(aX, aY, aZ);
|
|
|
|
if (!orientation.IsZero()) {
|
|
|
|
orientation.Normalize();
|
|
|
|
}
|
|
|
|
if (mOrientation.FuzzyEqual(orientation)) {
|
2013-03-20 17:12:07 -07:00
|
|
|
return;
|
|
|
|
}
|
2013-09-04 02:20:59 -07:00
|
|
|
mOrientation = orientation;
|
2013-03-12 11:34:55 -07:00
|
|
|
SendThreeDPointParameterToStream(ORIENTATION, mOrientation);
|
2012-11-05 18:14:13 -08:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:09:27 -07:00
|
|
|
void SetVelocity(double aX, double aY, double aZ)
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
2013-03-20 17:12:07 -07:00
|
|
|
if (WebAudioUtils::FuzzyEqual(mVelocity.x, aX) &&
|
|
|
|
WebAudioUtils::FuzzyEqual(mVelocity.y, aY) &&
|
|
|
|
WebAudioUtils::FuzzyEqual(mVelocity.z, aZ)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-05 18:14:13 -08:00
|
|
|
mVelocity.x = aX;
|
|
|
|
mVelocity.y = aY;
|
|
|
|
mVelocity.z = aZ;
|
2013-03-12 11:34:55 -07:00
|
|
|
SendThreeDPointParameterToStream(VELOCITY, mVelocity);
|
2013-04-11 05:47:57 -07:00
|
|
|
SendDopplerToSourcesIfNeeded();
|
2012-11-05 18:14:13 -08:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:09:27 -07:00
|
|
|
double RefDistance() const
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
|
|
|
return mRefDistance;
|
|
|
|
}
|
2013-03-11 16:09:27 -07:00
|
|
|
void SetRefDistance(double aRefDistance)
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
2013-03-20 17:12:07 -07:00
|
|
|
if (WebAudioUtils::FuzzyEqual(mRefDistance, aRefDistance)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-05 18:14:13 -08:00
|
|
|
mRefDistance = aRefDistance;
|
2013-03-12 11:34:55 -07:00
|
|
|
SendDoubleParameterToStream(REF_DISTANCE, mRefDistance);
|
2012-11-05 18:14:13 -08:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:09:27 -07:00
|
|
|
double MaxDistance() const
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
|
|
|
return mMaxDistance;
|
|
|
|
}
|
2013-03-11 16:09:27 -07:00
|
|
|
void SetMaxDistance(double aMaxDistance)
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
2013-03-20 17:12:07 -07:00
|
|
|
if (WebAudioUtils::FuzzyEqual(mMaxDistance, aMaxDistance)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-05 18:14:13 -08:00
|
|
|
mMaxDistance = aMaxDistance;
|
2013-03-12 11:34:55 -07:00
|
|
|
SendDoubleParameterToStream(MAX_DISTANCE, mMaxDistance);
|
2012-11-05 18:14:13 -08:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:09:27 -07:00
|
|
|
double RolloffFactor() const
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
|
|
|
return mRolloffFactor;
|
|
|
|
}
|
2013-03-11 16:09:27 -07:00
|
|
|
void SetRolloffFactor(double aRolloffFactor)
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
2013-03-20 17:12:07 -07:00
|
|
|
if (WebAudioUtils::FuzzyEqual(mRolloffFactor, aRolloffFactor)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-05 18:14:13 -08:00
|
|
|
mRolloffFactor = aRolloffFactor;
|
2013-03-12 11:34:55 -07:00
|
|
|
SendDoubleParameterToStream(ROLLOFF_FACTOR, mRolloffFactor);
|
2012-11-05 18:14:13 -08:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:09:27 -07:00
|
|
|
double ConeInnerAngle() const
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
|
|
|
return mConeInnerAngle;
|
|
|
|
}
|
2013-03-11 16:09:27 -07:00
|
|
|
void SetConeInnerAngle(double aConeInnerAngle)
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
2013-03-20 17:12:07 -07:00
|
|
|
if (WebAudioUtils::FuzzyEqual(mConeInnerAngle, aConeInnerAngle)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-05 18:14:13 -08:00
|
|
|
mConeInnerAngle = aConeInnerAngle;
|
2013-03-12 11:34:55 -07:00
|
|
|
SendDoubleParameterToStream(CONE_INNER_ANGLE, mConeInnerAngle);
|
2012-11-05 18:14:13 -08:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:09:27 -07:00
|
|
|
double ConeOuterAngle() const
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
|
|
|
return mConeOuterAngle;
|
|
|
|
}
|
2013-03-11 16:09:27 -07:00
|
|
|
void SetConeOuterAngle(double aConeOuterAngle)
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
2013-03-20 17:12:07 -07:00
|
|
|
if (WebAudioUtils::FuzzyEqual(mConeOuterAngle, aConeOuterAngle)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-05 18:14:13 -08:00
|
|
|
mConeOuterAngle = aConeOuterAngle;
|
2013-03-12 11:34:55 -07:00
|
|
|
SendDoubleParameterToStream(CONE_OUTER_ANGLE, mConeOuterAngle);
|
2012-11-05 18:14:13 -08:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:09:27 -07:00
|
|
|
double ConeOuterGain() const
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
|
|
|
return mConeOuterGain;
|
|
|
|
}
|
2013-03-11 16:09:27 -07:00
|
|
|
void SetConeOuterGain(double aConeOuterGain)
|
2012-11-05 18:14:13 -08:00
|
|
|
{
|
2013-03-20 17:12:07 -07:00
|
|
|
if (WebAudioUtils::FuzzyEqual(mConeOuterGain, aConeOuterGain)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-05 18:14:13 -08:00
|
|
|
mConeOuterGain = aConeOuterGain;
|
2013-03-12 11:34:55 -07:00
|
|
|
SendDoubleParameterToStream(CONE_OUTER_GAIN, mConeOuterGain);
|
2012-11-05 18:14:13 -08:00
|
|
|
}
|
|
|
|
|
2013-04-11 05:47:57 -07:00
|
|
|
float ComputeDopplerShift();
|
|
|
|
void SendDopplerToSourcesIfNeeded();
|
|
|
|
void FindConnectedSources();
|
|
|
|
void FindConnectedSources(AudioNode* aNode, nsTArray<AudioBufferSourceNode*>& aSources, std::set<AudioNode*>& aSeenNodes);
|
|
|
|
|
2014-04-13 11:08:10 -07:00
|
|
|
virtual const char* NodeType() const
|
|
|
|
{
|
|
|
|
return "PannerNode";
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
|
|
|
|
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
|
|
|
|
|
2014-07-08 14:23:17 -07:00
|
|
|
protected:
|
|
|
|
virtual ~PannerNode();
|
|
|
|
|
2013-03-12 11:34:55 -07:00
|
|
|
private:
|
|
|
|
friend class AudioListener;
|
|
|
|
friend class PannerNodeEngine;
|
|
|
|
enum EngineParameters {
|
|
|
|
LISTENER_POSITION,
|
2013-09-04 02:20:59 -07:00
|
|
|
LISTENER_FRONT_VECTOR, // unit length
|
|
|
|
LISTENER_RIGHT_VECTOR, // unit length, orthogonal to LISTENER_FRONT_VECTOR
|
2013-03-12 11:34:55 -07:00
|
|
|
LISTENER_VELOCITY,
|
|
|
|
LISTENER_DOPPLER_FACTOR,
|
|
|
|
LISTENER_SPEED_OF_SOUND,
|
|
|
|
PANNING_MODEL,
|
|
|
|
DISTANCE_MODEL,
|
|
|
|
POSITION,
|
2013-09-04 02:20:59 -07:00
|
|
|
ORIENTATION, // unit length or zero
|
2013-03-12 11:34:55 -07:00
|
|
|
VELOCITY,
|
|
|
|
REF_DISTANCE,
|
|
|
|
MAX_DISTANCE,
|
|
|
|
ROLLOFF_FACTOR,
|
|
|
|
CONE_INNER_ANGLE,
|
|
|
|
CONE_OUTER_ANGLE,
|
|
|
|
CONE_OUTER_GAIN
|
|
|
|
};
|
|
|
|
|
2012-11-05 18:14:13 -08:00
|
|
|
private:
|
2013-03-11 16:09:27 -07:00
|
|
|
PanningModelType mPanningModel;
|
|
|
|
DistanceModelType mDistanceModel;
|
2012-11-05 18:14:13 -08:00
|
|
|
ThreeDPoint mPosition;
|
|
|
|
ThreeDPoint mOrientation;
|
|
|
|
ThreeDPoint mVelocity;
|
2013-03-11 16:09:27 -07:00
|
|
|
double mRefDistance;
|
|
|
|
double mMaxDistance;
|
|
|
|
double mRolloffFactor;
|
|
|
|
double mConeInnerAngle;
|
|
|
|
double mConeOuterAngle;
|
|
|
|
double mConeOuterGain;
|
2013-04-11 05:47:57 -07:00
|
|
|
|
|
|
|
// An array of all the AudioBufferSourceNode connected directly or indirectly
|
|
|
|
// to this AudioPannerNode.
|
|
|
|
nsTArray<AudioBufferSourceNode*> mSources;
|
2012-11-05 18:14:13 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|