content/media/webaudio/AudioListener.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/AudioListener.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,132 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef AudioListener_h_
    1.11 +#define AudioListener_h_
    1.12 +
    1.13 +#include "nsWrapperCache.h"
    1.14 +#include "nsCycleCollectionParticipant.h"
    1.15 +#include "mozilla/Attributes.h"
    1.16 +#include "nsAutoPtr.h"
    1.17 +#include "ThreeDPoint.h"
    1.18 +#include "AudioContext.h"
    1.19 +#include "PannerNode.h"
    1.20 +#include "WebAudioUtils.h"
    1.21 +#include "js/TypeDecls.h"
    1.22 +#include "mozilla/MemoryReporting.h"
    1.23 +
    1.24 +namespace mozilla {
    1.25 +
    1.26 +namespace dom {
    1.27 +
    1.28 +class AudioListener MOZ_FINAL : public nsWrapperCache
    1.29 +{
    1.30 +public:
    1.31 +  explicit AudioListener(AudioContext* aContext);
    1.32 +
    1.33 +  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AudioListener)
    1.34 +  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioListener)
    1.35 +
    1.36 +  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
    1.37 +
    1.38 +  AudioContext* GetParentObject() const
    1.39 +  {
    1.40 +    return mContext;
    1.41 +  }
    1.42 +
    1.43 +  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    1.44 +
    1.45 +  double DopplerFactor() const
    1.46 +  {
    1.47 +    return mDopplerFactor;
    1.48 +  }
    1.49 +  void SetDopplerFactor(double aDopplerFactor)
    1.50 +  {
    1.51 +    if (WebAudioUtils::FuzzyEqual(mDopplerFactor, aDopplerFactor)) {
    1.52 +      return;
    1.53 +    }
    1.54 +    mDopplerFactor = aDopplerFactor;
    1.55 +    SendDoubleParameterToStream(PannerNode::LISTENER_DOPPLER_FACTOR, mDopplerFactor);
    1.56 +  }
    1.57 +
    1.58 +  double SpeedOfSound() const
    1.59 +  {
    1.60 +    return mSpeedOfSound;
    1.61 +  }
    1.62 +  void SetSpeedOfSound(double aSpeedOfSound)
    1.63 +  {
    1.64 +    if (WebAudioUtils::FuzzyEqual(mSpeedOfSound, aSpeedOfSound)) {
    1.65 +      return;
    1.66 +    }
    1.67 +    mSpeedOfSound = aSpeedOfSound;
    1.68 +    SendDoubleParameterToStream(PannerNode::LISTENER_SPEED_OF_SOUND, mSpeedOfSound);
    1.69 +  }
    1.70 +
    1.71 +  void SetPosition(double aX, double aY, double aZ)
    1.72 +  {
    1.73 +    if (WebAudioUtils::FuzzyEqual(mPosition.x, aX) &&
    1.74 +        WebAudioUtils::FuzzyEqual(mPosition.y, aY) &&
    1.75 +        WebAudioUtils::FuzzyEqual(mPosition.z, aZ)) {
    1.76 +      return;
    1.77 +    }
    1.78 +    mPosition.x = aX;
    1.79 +    mPosition.y = aY;
    1.80 +    mPosition.z = aZ;
    1.81 +    SendThreeDPointParameterToStream(PannerNode::LISTENER_POSITION, mPosition);
    1.82 +  }
    1.83 +
    1.84 +  const ThreeDPoint& Position() const
    1.85 +  {
    1.86 +    return mPosition;
    1.87 +  }
    1.88 +
    1.89 +  void SetOrientation(double aX, double aY, double aZ,
    1.90 +                      double aXUp, double aYUp, double aZUp);
    1.91 +
    1.92 +  const ThreeDPoint& Velocity() const
    1.93 +  {
    1.94 +    return mVelocity;
    1.95 +  }
    1.96 +
    1.97 +  void SetVelocity(double aX, double aY, double aZ)
    1.98 +  {
    1.99 +    if (WebAudioUtils::FuzzyEqual(mVelocity.x, aX) &&
   1.100 +        WebAudioUtils::FuzzyEqual(mVelocity.y, aY) &&
   1.101 +        WebAudioUtils::FuzzyEqual(mVelocity.z, aZ)) {
   1.102 +      return;
   1.103 +    }
   1.104 +    mVelocity.x = aX;
   1.105 +    mVelocity.y = aY;
   1.106 +    mVelocity.z = aZ;
   1.107 +    SendThreeDPointParameterToStream(PannerNode::LISTENER_VELOCITY, mVelocity);
   1.108 +    UpdatePannersVelocity();
   1.109 +  }
   1.110 +
   1.111 +  void RegisterPannerNode(PannerNode* aPannerNode);
   1.112 +  void UnregisterPannerNode(PannerNode* aPannerNode);
   1.113 +
   1.114 +private:
   1.115 +  void SendDoubleParameterToStream(uint32_t aIndex, double aValue);
   1.116 +  void SendThreeDPointParameterToStream(uint32_t aIndex, const ThreeDPoint& aValue);
   1.117 +  void UpdatePannersVelocity();
   1.118 +
   1.119 +private:
   1.120 +  friend class PannerNode;
   1.121 +  nsRefPtr<AudioContext> mContext;
   1.122 +  ThreeDPoint mPosition;
   1.123 +  ThreeDPoint mFrontVector;
   1.124 +  ThreeDPoint mRightVector;
   1.125 +  ThreeDPoint mVelocity;
   1.126 +  double mDopplerFactor;
   1.127 +  double mSpeedOfSound;
   1.128 +  nsTArray<WeakPtr<PannerNode> > mPanners;
   1.129 +};
   1.130 +
   1.131 +}
   1.132 +}
   1.133 +
   1.134 +#endif
   1.135 +

mercurial