| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // A distance effect will attenuate the gain as the position moves away from the
listener. | 44 // A distance effect will attenuate the gain as the position moves away from the
listener. |
| 45 // A cone effect will attenuate the gain as the orientation moves away from the
listener. | 45 // A cone effect will attenuate the gain as the orientation moves away from the
listener. |
| 46 // All of these effects follow the OpenAL specification very closely. | 46 // All of these effects follow the OpenAL specification very closely. |
| 47 | 47 |
| 48 class PannerHandler final : public AudioHandler { | 48 class PannerHandler final : public AudioHandler { |
| 49 public: | 49 public: |
| 50 // These enums are used to distinguish what cached values of panner are dirt
y. | 50 // These enums are used to distinguish what cached values of panner are dirt
y. |
| 51 enum { | 51 enum { |
| 52 AzimuthElevationDirty = 0x1, | 52 AzimuthElevationDirty = 0x1, |
| 53 DistanceConeGainDirty = 0x2, | 53 DistanceConeGainDirty = 0x2, |
| 54 DopplerRateDirty = 0x4, | |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 static PassRefPtr<PannerHandler> create(AudioNode&, float sampleRate); | 56 static PassRefPtr<PannerHandler> create(AudioNode&, float sampleRate); |
| 58 ~PannerHandler() override; | 57 ~PannerHandler() override; |
| 59 | 58 |
| 60 // AudioHandler | 59 // AudioHandler |
| 61 void process(size_t framesToProcess) override; | 60 void process(size_t framesToProcess) override; |
| 62 void initialize() override; | 61 void initialize() override; |
| 63 void uninitialize() override; | 62 void uninitialize() override; |
| 64 | 63 |
| 65 // Panning model | 64 // Panning model |
| 66 String panningModel() const; | 65 String panningModel() const; |
| 67 void setPanningModel(const String&); | 66 void setPanningModel(const String&); |
| 68 | 67 |
| 69 // Position, orientation and velocity | 68 // Position and orientation |
| 70 void setPosition(float x, float y, float z); | 69 void setPosition(float x, float y, float z); |
| 71 void setOrientation(float x, float y, float z); | 70 void setOrientation(float x, float y, float z); |
| 72 void setVelocity(float x, float y, float z); | |
| 73 | 71 |
| 74 // Distance parameters | 72 // Distance parameters |
| 75 String distanceModel() const; | 73 String distanceModel() const; |
| 76 void setDistanceModel(const String&); | 74 void setDistanceModel(const String&); |
| 77 | 75 |
| 78 double refDistance() { return m_distanceEffect.refDistance(); } | 76 double refDistance() { return m_distanceEffect.refDistance(); } |
| 79 void setRefDistance(double); | 77 void setRefDistance(double); |
| 80 | 78 |
| 81 double maxDistance() { return m_distanceEffect.maxDistance(); } | 79 double maxDistance() { return m_distanceEffect.maxDistance(); } |
| 82 void setMaxDistance(double); | 80 void setMaxDistance(double); |
| 83 | 81 |
| 84 double rolloffFactor() { return m_distanceEffect.rolloffFactor(); } | 82 double rolloffFactor() { return m_distanceEffect.rolloffFactor(); } |
| 85 void setRolloffFactor(double); | 83 void setRolloffFactor(double); |
| 86 | 84 |
| 87 // Sound cones - angles in degrees | 85 // Sound cones - angles in degrees |
| 88 double coneInnerAngle() const { return m_coneEffect.innerAngle(); } | 86 double coneInnerAngle() const { return m_coneEffect.innerAngle(); } |
| 89 void setConeInnerAngle(double); | 87 void setConeInnerAngle(double); |
| 90 | 88 |
| 91 double coneOuterAngle() const { return m_coneEffect.outerAngle(); } | 89 double coneOuterAngle() const { return m_coneEffect.outerAngle(); } |
| 92 void setConeOuterAngle(double); | 90 void setConeOuterAngle(double); |
| 93 | 91 |
| 94 double coneOuterGain() const { return m_coneEffect.outerGain(); } | 92 double coneOuterGain() const { return m_coneEffect.outerGain(); } |
| 95 void setConeOuterGain(double); | 93 void setConeOuterGain(double); |
| 96 | 94 |
| 97 void markPannerAsDirty(unsigned); | 95 void markPannerAsDirty(unsigned); |
| 98 | 96 |
| 99 // It must be called on audio thread, currently called only process() in Aud
ioBufferSourceNode. | |
| 100 double dopplerRate(); | |
| 101 | |
| 102 double tailTime() const override { return m_panner ? m_panner->tailTime() :
0; } | 97 double tailTime() const override { return m_panner ? m_panner->tailTime() :
0; } |
| 103 double latencyTime() const override { return m_panner ? m_panner->latencyTim
e() : 0; } | 98 double latencyTime() const override { return m_panner ? m_panner->latencyTim
e() : 0; } |
| 104 | 99 |
| 105 void setChannelCount(unsigned long, ExceptionState&) final; | 100 void setChannelCount(unsigned long, ExceptionState&) final; |
| 106 void setChannelCountMode(const String&, ExceptionState&) final; | 101 void setChannelCountMode(const String&, ExceptionState&) final; |
| 107 | 102 |
| 108 private: | 103 private: |
| 109 PannerHandler(AudioNode&, float sampleRate); | 104 PannerHandler(AudioNode&, float sampleRate); |
| 110 // AbstractAudioContext's listener | 105 // AbstractAudioContext's listener |
| 111 AudioListener* listener(); | 106 AudioListener* listener(); |
| 112 | 107 |
| 113 bool setPanningModel(unsigned); // Returns true on success. | 108 bool setPanningModel(unsigned); // Returns true on success. |
| 114 bool setDistanceModel(unsigned); // Returns true on success. | 109 bool setDistanceModel(unsigned); // Returns true on success. |
| 115 | 110 |
| 116 void calculateAzimuthElevation(double* outAzimuth, double* outElevation); | 111 void calculateAzimuthElevation(double* outAzimuth, double* outElevation); |
| 117 float calculateDistanceConeGain(); // Returns the combined distance and cone
gain attenuation. | 112 float calculateDistanceConeGain(); // Returns the combined distance and cone
gain attenuation. |
| 118 double calculateDopplerRate(); | |
| 119 | 113 |
| 120 void azimuthElevation(double* outAzimuth, double* outElevation); | 114 void azimuthElevation(double* outAzimuth, double* outElevation); |
| 121 float distanceConeGain(); | 115 float distanceConeGain(); |
| 122 | 116 |
| 123 bool isAzimuthElevationDirty() const { return m_isAzimuthElevationDirty; } | 117 bool isAzimuthElevationDirty() const { return m_isAzimuthElevationDirty; } |
| 124 bool isDistanceConeGainDirty() const { return m_isDistanceConeGainDirty; } | 118 bool isDistanceConeGainDirty() const { return m_isDistanceConeGainDirty; } |
| 125 bool isDopplerRateDirty() const { return m_isDopplerRateDirty; } | |
| 126 | 119 |
| 127 // This Persistent doesn't make a reference cycle including the owner | 120 // This Persistent doesn't make a reference cycle including the owner |
| 128 // PannerNode. | 121 // PannerNode. |
| 129 Persistent<AudioListener> m_listener; | 122 Persistent<AudioListener> m_listener; |
| 130 OwnPtr<Panner> m_panner; | 123 OwnPtr<Panner> m_panner; |
| 131 unsigned m_panningModel; | 124 unsigned m_panningModel; |
| 132 unsigned m_distanceModel; | 125 unsigned m_distanceModel; |
| 133 | 126 |
| 134 // Current source location information | 127 // Current source location information |
| 135 FloatPoint3D m_position; | 128 FloatPoint3D m_position; |
| 136 FloatPoint3D m_orientation; | 129 FloatPoint3D m_orientation; |
| 137 FloatPoint3D m_velocity; | |
| 138 | 130 |
| 139 bool m_isAzimuthElevationDirty; | 131 bool m_isAzimuthElevationDirty; |
| 140 bool m_isDistanceConeGainDirty; | 132 bool m_isDistanceConeGainDirty; |
| 141 bool m_isDopplerRateDirty; | |
| 142 | 133 |
| 143 // Gain | 134 // Gain |
| 144 DistanceEffect m_distanceEffect; | 135 DistanceEffect m_distanceEffect; |
| 145 ConeEffect m_coneEffect; | 136 ConeEffect m_coneEffect; |
| 146 float m_lastGain; | 137 float m_lastGain; |
| 147 | 138 |
| 148 // Cached values | 139 // Cached values |
| 149 double m_cachedAzimuth; | 140 double m_cachedAzimuth; |
| 150 double m_cachedElevation; | 141 double m_cachedElevation; |
| 151 float m_cachedDistanceConeGain; | 142 float m_cachedDistanceConeGain; |
| 152 double m_cachedDopplerRate; | |
| 153 | 143 |
| 154 // Synchronize process() with setting of the panning model, source's locatio
n information, listener, distance parameters and sound cones. | 144 // Synchronize process() with setting of the panning model, source's locatio
n information, listener, distance parameters and sound cones. |
| 155 mutable Mutex m_processLock; | 145 mutable Mutex m_processLock; |
| 156 }; | 146 }; |
| 157 | 147 |
| 158 class PannerNode final : public AudioNode { | 148 class PannerNode final : public AudioNode { |
| 159 DEFINE_WRAPPERTYPEINFO(); | 149 DEFINE_WRAPPERTYPEINFO(); |
| 160 public: | 150 public: |
| 161 static PannerNode* create(AbstractAudioContext&, float sampleRate); | 151 static PannerNode* create(AbstractAudioContext&, float sampleRate); |
| 162 PannerHandler& pannerHandler() const; | 152 PannerHandler& pannerHandler() const; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 181 double coneOuterGain() const; | 171 double coneOuterGain() const; |
| 182 void setConeOuterGain(double); | 172 void setConeOuterGain(double); |
| 183 | 173 |
| 184 private: | 174 private: |
| 185 PannerNode(AbstractAudioContext&, float sampleRate); | 175 PannerNode(AbstractAudioContext&, float sampleRate); |
| 186 }; | 176 }; |
| 187 | 177 |
| 188 } // namespace blink | 178 } // namespace blink |
| 189 | 179 |
| 190 #endif // PannerNode_h | 180 #endif // PannerNode_h |
| OLD | NEW |