Bug 849914 - Implement the latest spec changes to PannerNode and AudioListener; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 11 Mar 2013 19:09:27 -0400
changeset 134849 6d81ef71bfb31c2f280780f3ea43bf2b58020e12
parent 134848 fee79a593fd3fae0cc0321e1e0e7a98517bea69b
child 134850 8948998650e16e9f04fb1d5c8d27a6dc53fd061e
push id2452
push userlsblakk@mozilla.com
push dateMon, 13 May 2013 16:59:38 +0000
treeherdermozilla-beta@d4b152d29d8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs849914
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 849914 - Implement the latest spec changes to PannerNode and AudioListener; r=roc
content/media/webaudio/AudioListener.cpp
content/media/webaudio/AudioListener.h
content/media/webaudio/PannerNode.cpp
content/media/webaudio/PannerNode.h
content/media/webaudio/ThreeDPoint.h
content/media/webaudio/test/test_pannerNode.html
dom/webidl/AudioListener.webidl
dom/webidl/PannerNode.webidl
--- a/content/media/webaudio/AudioListener.cpp
+++ b/content/media/webaudio/AudioListener.cpp
@@ -16,21 +16,21 @@ namespace dom {
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(AudioListener, mContext)
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AudioListener, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AudioListener, Release)
 
 AudioListener::AudioListener(AudioContext* aContext)
   : mContext(aContext)
   , mPosition()
-  , mOrientation(0.f, 0.f, -1.f)
-  , mUpVector(0.f, 1.f, 0.f)
+  , mOrientation(0., 0., -1.)
+  , mUpVector(0., 1., 0.)
   , mVelocity()
-  , mDopplerFactor(1.f)
-  , mSpeedOfSound(343.3f) // meters/second
+  , mDopplerFactor(1.)
+  , mSpeedOfSound(343.3) // meters/second
 {
   MOZ_ASSERT(aContext);
   SetIsDOMBinding();
 }
 
 JSObject*
 AudioListener::WrapObject(JSContext* aCx, JSObject* aScope)
 {
--- a/content/media/webaudio/AudioListener.h
+++ b/content/media/webaudio/AudioListener.h
@@ -34,66 +34,66 @@ public:
 
   AudioContext* GetParentObject() const
   {
     return mContext;
   }
 
   virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
 
-  float DopplerFactor() const
+  double DopplerFactor() const
   {
     return mDopplerFactor;
   }
-  void SetDopplerFactor(float aDopplerFactor)
+  void SetDopplerFactor(double aDopplerFactor)
   {
     mDopplerFactor = aDopplerFactor;
   }
 
-  float SpeedOfSound() const
+  double SpeedOfSound() const
   {
     return mSpeedOfSound;
   }
-  void SetSpeedOfSound(float aSpeedOfSound)
+  void SetSpeedOfSound(double aSpeedOfSound)
   {
     mSpeedOfSound = aSpeedOfSound;
   }
 
-  void SetPosition(float aX, float aY, float aZ)
+  void SetPosition(double aX, double aY, double aZ)
   {
     mPosition.x = aX;
     mPosition.y = aY;
     mPosition.z = aZ;
   }
 
-  void SetOrientation(float aX, float aY, float aZ,
-                      float aXUp, float aYUp, float aZUp)
+  void SetOrientation(double aX, double aY, double aZ,
+                      double aXUp, double aYUp, double aZUp)
   {
     mOrientation.x = aX;
     mOrientation.y = aY;
     mOrientation.z = aZ;
     mUpVector.x = aXUp;
     mUpVector.y = aYUp;
     mUpVector.z = aZUp;
   }
 
-  void SetVelocity(float aX, float aY, float aZ)
+  void SetVelocity(double aX, double aY, double aZ)
   {
     mVelocity.x = aX;
     mVelocity.y = aY;
     mVelocity.z = aZ;
   }
 
 private:
   nsRefPtr<AudioContext> mContext;
   ThreeDPoint mPosition;
   ThreeDPoint mOrientation;
   ThreeDPoint mUpVector;
   ThreeDPoint mVelocity;
-  float mDopplerFactor;
-  float mSpeedOfSound;
+  double mDopplerFactor;
+  double mSpeedOfSound;
 };
 
 }
 }
 
 #endif
 
--- a/content/media/webaudio/PannerNode.cpp
+++ b/content/media/webaudio/PannerNode.cpp
@@ -1,33 +1,32 @@
 /* -*- 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/. */
 
 #include "PannerNode.h"
-#include "mozilla/dom/PannerNodeBinding.h"
 
 namespace mozilla {
 namespace dom {
 
 PannerNode::PannerNode(AudioContext* aContext)
   : AudioNode(aContext)
-  , mPanningModel(PanningModelEnum::HRTF)
-  , mDistanceModel(DistanceModelEnum::INVERSE_DISTANCE)
+  , mPanningModel(PanningModelTypeValues::HRTF)
+  , mDistanceModel(DistanceModelTypeValues::Inverse)
   , mPosition()
-  , mOrientation(1.f, 0.f, 0.f)
+  , mOrientation(1., 0., 0.)
   , mVelocity()
-  , mRefDistance(1.f)
-  , mMaxDistance(10000.f)
-  , mRolloffFactor(1.f)
-  , mConeInnerAngle(360.f)
-  , mConeOuterAngle(360.f)
-  , mConeOuterGain(0.f)
+  , mRefDistance(1.)
+  , mMaxDistance(10000.)
+  , mRolloffFactor(1.)
+  , mConeInnerAngle(360.)
+  , mConeOuterAngle(360.)
+  , mConeOuterGain(0.)
 {
 }
 
 JSObject*
 PannerNode::WrapObject(JSContext* aCx, JSObject* aScope)
 {
   return PannerNodeBinding::Wrap(aCx, aScope, this);
 }
--- a/content/media/webaudio/PannerNode.h
+++ b/content/media/webaudio/PannerNode.h
@@ -6,159 +6,135 @@
 
 #ifndef PannerNode_h_
 #define PannerNode_h_
 
 #include "AudioNode.h"
 #include "AudioParam.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/TypedEnum.h"
+#include "mozilla/dom/PannerNodeBinding.h"
 #include "ThreeDPoint.h"
 
 namespace mozilla {
 namespace dom {
 
 class AudioContext;
 
-MOZ_BEGIN_ENUM_CLASS(PanningModelEnum, uint16_t)
-  EQUALPOWER = 0,
-  HRTF = 1,
-  SOUNDFIELD = 2,
-  Max = 2
-MOZ_END_ENUM_CLASS(PanningModelEnum)
-MOZ_BEGIN_ENUM_CLASS(DistanceModelEnum, uint16_t)
-  LINEAR_DISTANCE = 0,
-  INVERSE_DISTANCE = 1,
-  EXPONENTIAL_DISTANCE = 2,
-  Max = 2
-MOZ_END_ENUM_CLASS(DistanceModelEnum)
-
 class PannerNode : public AudioNode
 {
 public:
   explicit PannerNode(AudioContext* aContext);
 
   virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope);
 
-  uint16_t PanningModel() const
-  {
-    return static_cast<uint16_t> (mPanningModel);
-  }
-  void SetPanningModel(uint16_t aPanningModel, ErrorResult& aRv)
+  PanningModelType PanningModel() const
   {
-    PanningModelEnum panningModel =
-      static_cast<PanningModelEnum> (aPanningModel);
-    if (panningModel > PanningModelEnum::Max) {
-      aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
-    } else {
-      mPanningModel = panningModel;
-    }
+    return mPanningModel;
+  }
+  void SetPanningModel(PanningModelType aPanningModel)
+  {
+    mPanningModel = aPanningModel;
   }
 
-  uint16_t DistanceModel() const
-  {
-    return static_cast<uint16_t> (mDistanceModel);
-  }
-  void SetDistanceModel(uint16_t aDistanceModel, ErrorResult& aRv)
+  DistanceModelType DistanceModel() const
   {
-    DistanceModelEnum distanceModel =
-      static_cast<DistanceModelEnum> (aDistanceModel);
-    if (distanceModel > DistanceModelEnum::Max) {
-      aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
-    } else {
-      mDistanceModel = distanceModel;
-    }
+    return mDistanceModel;
+  }
+  void SetDistanceModel(DistanceModelType aDistanceModel)
+  {
+    mDistanceModel = aDistanceModel;
   }
 
-  void SetPosition(float aX, float aY, float aZ)
+  void SetPosition(double aX, double aY, double aZ)
   {
     mPosition.x = aX;
     mPosition.y = aY;
     mPosition.z = aZ;
   }
 
-  void SetOrientation(float aX, float aY, float aZ)
+  void SetOrientation(double aX, double aY, double aZ)
   {
     mOrientation.x = aX;
     mOrientation.y = aY;
     mOrientation.z = aZ;
   }
 
-  void SetVelocity(float aX, float aY, float aZ)
+  void SetVelocity(double aX, double aY, double aZ)
   {
     mVelocity.x = aX;
     mVelocity.y = aY;
     mVelocity.z = aZ;
   }
 
-  float RefDistance() const
+  double RefDistance() const
   {
     return mRefDistance;
   }
-  void SetRefDistance(float aRefDistance)
+  void SetRefDistance(double aRefDistance)
   {
     mRefDistance = aRefDistance;
   }
 
-  float MaxDistance() const
+  double MaxDistance() const
   {
     return mMaxDistance;
   }
-  void SetMaxDistance(float aMaxDistance)
+  void SetMaxDistance(double aMaxDistance)
   {
     mMaxDistance = aMaxDistance;
   }
 
-  float RolloffFactor() const
+  double RolloffFactor() const
   {
     return mRolloffFactor;
   }
-  void SetRolloffFactor(float aRolloffFactor)
+  void SetRolloffFactor(double aRolloffFactor)
   {
     mRolloffFactor = aRolloffFactor;
   }
 
-  float ConeInnerAngle() const
+  double ConeInnerAngle() const
   {
     return mConeInnerAngle;
   }
-  void SetConeInnerAngle(float aConeInnerAngle)
+  void SetConeInnerAngle(double aConeInnerAngle)
   {
     mConeInnerAngle = aConeInnerAngle;
   }
 
-  float ConeOuterAngle() const
+  double ConeOuterAngle() const
   {
     return mConeOuterAngle;
   }
-  void SetConeOuterAngle(float aConeOuterAngle)
+  void SetConeOuterAngle(double aConeOuterAngle)
   {
     mConeOuterAngle = aConeOuterAngle;
   }
 
-  float ConeOuterGain() const
+  double ConeOuterGain() const
   {
     return mConeOuterGain;
   }
-  void SetConeOuterGain(float aConeOuterGain)
+  void SetConeOuterGain(double aConeOuterGain)
   {
     mConeOuterGain = aConeOuterGain;
   }
 
 private:
-  PanningModelEnum mPanningModel;
-  DistanceModelEnum mDistanceModel;
+  PanningModelType mPanningModel;
+  DistanceModelType mDistanceModel;
   ThreeDPoint mPosition;
   ThreeDPoint mOrientation;
   ThreeDPoint mVelocity;
-  float mRefDistance;
-  float mMaxDistance;
-  float mRolloffFactor;
-  float mConeInnerAngle;
-  float mConeOuterAngle;
-  float mConeOuterGain;
+  double mRefDistance;
+  double mMaxDistance;
+  double mRolloffFactor;
+  double mConeInnerAngle;
+  double mConeOuterAngle;
+  double mConeOuterGain;
 };
 
 }
 }
 
 #endif
 
--- a/content/media/webaudio/ThreeDPoint.h
+++ b/content/media/webaudio/ThreeDPoint.h
@@ -8,28 +8,28 @@
 #define ThreeDPoint_h_
 
 namespace mozilla {
 
 namespace dom {
 
 struct ThreeDPoint {
   ThreeDPoint()
-    : x(0.f)
-    , y(0.f)
-    , z(0.f)
+    : x(0.)
+    , y(0.)
+    , z(0.)
   {
   }
-  ThreeDPoint(float aX, float aY, float aZ)
+  ThreeDPoint(double aX, double aY, double aZ)
     : x(aX)
     , y(aY)
     , z(aZ)
   {
   }
 
-  float x, y, z;
+  double x, y, z;
 };
 
 }
 }
 
 #endif
 
--- a/content/media/webaudio/test/test_pannerNode.html
+++ b/content/media/webaudio/test/test_pannerNode.html
@@ -30,18 +30,18 @@ addLoadEvent(function() {
   var panner = context.createPanner();
 
   source.buffer = buffer;
 
   source.connect(panner);
   panner.connect(destination);
 
   // Verify default values
-  is(panner.panningModel, 1, "Correct default value for panning model");
-  is(panner.distanceModel, 1, "Correct default value for distance model");
+  is(panner.panningModel, "HRTF", "Correct default value for panning model");
+  is(panner.distanceModel, "inverse", "Correct default value for distance model");
   near(panner.refDistance, 1, "Correct default value for ref distance");
   near(panner.maxDistance, 10000, "Correct default value for max distance");
   near(panner.rolloffFactor, 1, "Correct default value for rolloff factor");
   near(panner.coneInnerAngle, 360, "Correct default value for cone inner angle");
   near(panner.coneOuterAngle, 360, "Correct default value for cone outer angle");
   near(panner.coneOuterGain, 0, "Correct default value for cone outer gain");
 
   panner.setPosition(1, 1, 1);
--- a/dom/webidl/AudioListener.webidl
+++ b/dom/webidl/AudioListener.webidl
@@ -9,20 +9,20 @@
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 [PrefControlled]
 interface AudioListener {
 
     // same as OpenAL (default 1) 
-    attribute float dopplerFactor;
+    attribute double dopplerFactor;
 
     // in meters / second (default 343.3) 
-    attribute float speedOfSound;
+    attribute double speedOfSound;
 
     // Uses a 3D cartesian coordinate system 
-    void setPosition(float x, float y, float z);
-    void setOrientation(float x, float y, float z, float xUp, float yUp, float zUp);
-    void setVelocity(float x, float y, float z);
+    void setPosition(double x, double y, double z);
+    void setOrientation(double x, double y, double z, double xUp, double yUp, double zUp);
+    void setVelocity(double x, double y, double z);
 
 };
 
--- a/dom/webidl/PannerNode.webidl
+++ b/dom/webidl/PannerNode.webidl
@@ -5,44 +5,44 @@
  *
  * The origin of this IDL file is
  * https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
+enum PanningModelType {
+  "equalpower",
+  "HRTF",
+  "soundfield"
+};
+
+enum DistanceModelType {
+  "linear",
+  "inverse",
+  "exponential"
+};
+
 [PrefControlled]
 interface PannerNode : AudioNode {
 
-    // Panning model 
-    const unsigned short EQUALPOWER = 0;
-    const unsigned short HRTF = 1;
-    const unsigned short SOUNDFIELD = 2;
-
-    // Distance model 
-    const unsigned short LINEAR_DISTANCE = 0;
-    const unsigned short INVERSE_DISTANCE = 1;
-    const unsigned short EXPONENTIAL_DISTANCE = 2;
-
     // Default for stereo is HRTF 
-    [SetterThrows]
-    attribute unsigned short panningModel;
+    attribute PanningModelType panningModel;
 
     // Uses a 3D cartesian coordinate system 
-    void setPosition(float x, float y, float z);
-    void setOrientation(float x, float y, float z);
-    void setVelocity(float x, float y, float z);
+    void setPosition(double x, double y, double z);
+    void setOrientation(double x, double y, double z);
+    void setVelocity(double x, double y, double z);
 
     // Distance model and attributes 
-    [SetterThrows]
-    attribute unsigned short distanceModel;
-    attribute float refDistance;
-    attribute float maxDistance;
-    attribute float rolloffFactor;
+    attribute DistanceModelType distanceModel;
+    attribute double refDistance;
+    attribute double maxDistance;
+    attribute double rolloffFactor;
 
     // Directional sound cone 
-    attribute float coneInnerAngle;
-    attribute float coneOuterAngle;
-    attribute float coneOuterGain;
+    attribute double coneInnerAngle;
+    attribute double coneOuterAngle;
+    attribute double coneOuterGain;
 
 };