#ifndef PannerNode_h
#define PannerNode_h
#include "platform/audio/AudioBus.h"
#include "platform/audio/Cone.h"
#include "platform/audio/Distance.h"
#include "platform/audio/HRTFDatabaseLoader.h"
#include "platform/audio/Panner.h"
#include "modules/webaudio/AudioListener.h"
#include "modules/webaudio/AudioNode.h"
#include "modules/webaudio/AudioParam.h"
#include "platform/geometry/FloatPoint3D.h"
#include "wtf/HashMap.h"
#include "wtf/OwnPtr.h"
namespace WebCore {
class PannerNode FINAL : public AudioNode {
public:
enum {
EQUALPOWER = 0,
HRTF = 1,
};
enum {
LINEAR_DISTANCE = 0,
INVERSE_DISTANCE = 1,
EXPONENTIAL_DISTANCE = 2,
};
static PassRefPtr<PannerNode> create(AudioContext* context, float sampleRate)
{
return adoptRef(new PannerNode(context, sampleRate));
}
virtual ~PannerNode();
virtual void process(size_t framesToProcess) OVERRIDE;
virtual void pullInputs(size_t framesToProcess) OVERRIDE;
virtual void initialize() OVERRIDE;
virtual void uninitialize() OVERRIDE;
AudioListener* listener();
String panningModel() const;
bool setPanningModel(unsigned);
void setPanningModel(const String&);
void setPosition(float x, float y, float z);
void setOrientation(float x, float y, float z);
void setVelocity(float x, float y, float z);
String distanceModel() const;
bool setDistanceModel(unsigned);
void setDistanceModel(const String&);
double refDistance() { return m_distanceEffect.refDistance(); }
void setRefDistance(double refDistance) { m_distanceEffect.setRefDistance(refDistance); }
double maxDistance() { return m_distanceEffect.maxDistance(); }
void setMaxDistance(double maxDistance) { m_distanceEffect.setMaxDistance(maxDistance); }
double rolloffFactor() { return m_distanceEffect.rolloffFactor(); }
void setRolloffFactor(double rolloffFactor) { m_distanceEffect.setRolloffFactor(rolloffFactor); }
double coneInnerAngle() const { return m_coneEffect.innerAngle(); }
void setConeInnerAngle(double angle) { m_coneEffect.setInnerAngle(angle); }
double coneOuterAngle() const { return m_coneEffect.outerAngle(); }
void setConeOuterAngle(double angle) { m_coneEffect.setOuterAngle(angle); }
double coneOuterGain() const { return m_coneEffect.outerGain(); }
void setConeOuterGain(double angle) { m_coneEffect.setOuterGain(angle); }
double dopplerRate();
virtual double tailTime() const OVERRIDE { return m_panner ? m_panner->tailTime() : 0; }
virtual double latencyTime() const OVERRIDE { return m_panner ? m_panner->latencyTime() : 0; }
private:
PannerNode(AudioContext*, float sampleRate);
void calculateAzimuthElevation(double* outAzimuth, double* outElevation);
float calculateDistanceConeGain();
double calculateDopplerRate();
void azimuthElevation(double* outAzimuth, double* outElevation);
float distanceConeGain();
bool isAzimuthElevationDirty();
bool isDistanceConeGainDirty();
bool isDopplerRateDirty();
void notifyAudioSourcesConnectedToNode(AudioNode*, HashMap<AudioNode*, bool> &visitedNodes);
void updateCachedListener();
void updateCachedSourceLocationInfo();
OwnPtr<Panner> m_panner;
unsigned m_panningModel;
unsigned m_distanceModel;
FloatPoint3D m_position;
FloatPoint3D m_orientation;
FloatPoint3D m_velocity;
FloatPoint3D m_cachedPosition;
FloatPoint3D m_cachedOrientation;
FloatPoint3D m_cachedVelocity;
RefPtr<AudioParam> m_distanceGain;
RefPtr<AudioParam> m_coneGain;
DistanceEffect m_distanceEffect;
ConeEffect m_coneEffect;
float m_lastGain;
double m_cachedAzimuth;
double m_cachedElevation;
float m_cachedDistanceConeGain;
double m_cachedDopplerRate;
RefPtr<AudioListener> m_cachedListener;
RefPtr<HRTFDatabaseLoader> m_hrtfDatabaseLoader;
unsigned m_connectionCount;
mutable Mutex m_processLock;
};
}
#endif