michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef AudioListener_h_ michael@0: #define AudioListener_h_ michael@0: michael@0: #include "nsWrapperCache.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "ThreeDPoint.h" michael@0: #include "AudioContext.h" michael@0: #include "PannerNode.h" michael@0: #include "WebAudioUtils.h" michael@0: #include "js/TypeDecls.h" michael@0: #include "mozilla/MemoryReporting.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace dom { michael@0: michael@0: class AudioListener MOZ_FINAL : public nsWrapperCache michael@0: { michael@0: public: michael@0: explicit AudioListener(AudioContext* aContext); michael@0: michael@0: NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AudioListener) michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioListener) michael@0: michael@0: size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; michael@0: michael@0: AudioContext* GetParentObject() const michael@0: { michael@0: return mContext; michael@0: } michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: double DopplerFactor() const michael@0: { michael@0: return mDopplerFactor; michael@0: } michael@0: void SetDopplerFactor(double aDopplerFactor) michael@0: { michael@0: if (WebAudioUtils::FuzzyEqual(mDopplerFactor, aDopplerFactor)) { michael@0: return; michael@0: } michael@0: mDopplerFactor = aDopplerFactor; michael@0: SendDoubleParameterToStream(PannerNode::LISTENER_DOPPLER_FACTOR, mDopplerFactor); michael@0: } michael@0: michael@0: double SpeedOfSound() const michael@0: { michael@0: return mSpeedOfSound; michael@0: } michael@0: void SetSpeedOfSound(double aSpeedOfSound) michael@0: { michael@0: if (WebAudioUtils::FuzzyEqual(mSpeedOfSound, aSpeedOfSound)) { michael@0: return; michael@0: } michael@0: mSpeedOfSound = aSpeedOfSound; michael@0: SendDoubleParameterToStream(PannerNode::LISTENER_SPEED_OF_SOUND, mSpeedOfSound); michael@0: } michael@0: michael@0: void SetPosition(double aX, double aY, double aZ) michael@0: { michael@0: if (WebAudioUtils::FuzzyEqual(mPosition.x, aX) && michael@0: WebAudioUtils::FuzzyEqual(mPosition.y, aY) && michael@0: WebAudioUtils::FuzzyEqual(mPosition.z, aZ)) { michael@0: return; michael@0: } michael@0: mPosition.x = aX; michael@0: mPosition.y = aY; michael@0: mPosition.z = aZ; michael@0: SendThreeDPointParameterToStream(PannerNode::LISTENER_POSITION, mPosition); michael@0: } michael@0: michael@0: const ThreeDPoint& Position() const michael@0: { michael@0: return mPosition; michael@0: } michael@0: michael@0: void SetOrientation(double aX, double aY, double aZ, michael@0: double aXUp, double aYUp, double aZUp); michael@0: michael@0: const ThreeDPoint& Velocity() const michael@0: { michael@0: return mVelocity; michael@0: } michael@0: michael@0: void SetVelocity(double aX, double aY, double aZ) michael@0: { michael@0: if (WebAudioUtils::FuzzyEqual(mVelocity.x, aX) && michael@0: WebAudioUtils::FuzzyEqual(mVelocity.y, aY) && michael@0: WebAudioUtils::FuzzyEqual(mVelocity.z, aZ)) { michael@0: return; michael@0: } michael@0: mVelocity.x = aX; michael@0: mVelocity.y = aY; michael@0: mVelocity.z = aZ; michael@0: SendThreeDPointParameterToStream(PannerNode::LISTENER_VELOCITY, mVelocity); michael@0: UpdatePannersVelocity(); michael@0: } michael@0: michael@0: void RegisterPannerNode(PannerNode* aPannerNode); michael@0: void UnregisterPannerNode(PannerNode* aPannerNode); michael@0: michael@0: private: michael@0: void SendDoubleParameterToStream(uint32_t aIndex, double aValue); michael@0: void SendThreeDPointParameterToStream(uint32_t aIndex, const ThreeDPoint& aValue); michael@0: void UpdatePannersVelocity(); michael@0: michael@0: private: michael@0: friend class PannerNode; michael@0: nsRefPtr mContext; michael@0: ThreeDPoint mPosition; michael@0: ThreeDPoint mFrontVector; michael@0: ThreeDPoint mRightVector; michael@0: ThreeDPoint mVelocity; michael@0: double mDopplerFactor; michael@0: double mSpeedOfSound; michael@0: nsTArray > mPanners; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif michael@0: