2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "modules/webaudio/AudioListener.h"
35 #include "modules/webaudio/PannerNode.h"
36 #include "platform/audio/AudioBus.h"
40 AudioListener::AudioListener()
42 , m_orientation(0, 0, -1)
46 , m_speedOfSound(343.3)
48 ScriptWrappable::init(this);
51 AudioListener::~AudioListener()
56 void AudioListener::addPanner(PannerNode* panner)
61 m_panners.append(panner);
64 void AudioListener::removePanner(PannerNode* panner)
66 for (unsigned i = 0; i < m_panners.size(); ++i) {
67 if (panner == m_panners[i]) {
74 void AudioListener::markPannersAsDirty(unsigned type)
76 for (unsigned i = 0; i < m_panners.size(); ++i)
77 m_panners[i]->markPannerAsDirty(type);
80 void AudioListener::setPosition(const FloatPoint3D &position)
82 if (m_position == position)
85 // This synchronizes with panner's process().
86 MutexLocker listenerLocker(m_listenerLock);
87 m_position = position;
88 markPannersAsDirty(PannerNode::AzimuthElevationDirty | PannerNode::DistanceConeGainDirty | PannerNode::DopplerRateDirty);
91 void AudioListener::setOrientation(const FloatPoint3D &orientation)
93 if (m_orientation == orientation)
96 // This synchronizes with panner's process().
97 MutexLocker listenerLocker(m_listenerLock);
98 m_orientation = orientation;
99 markPannersAsDirty(PannerNode::AzimuthElevationDirty);
102 void AudioListener::setUpVector(const FloatPoint3D &upVector)
104 if (m_upVector == upVector)
107 // This synchronizes with panner's process().
108 MutexLocker listenerLocker(m_listenerLock);
109 m_upVector = upVector;
110 markPannersAsDirty(PannerNode::AzimuthElevationDirty);
113 void AudioListener::setVelocity(const FloatPoint3D &velocity)
115 if (m_velocity == velocity)
118 // This synchronizes with panner's process().
119 MutexLocker listenerLocker(m_listenerLock);
120 m_velocity = velocity;
121 markPannersAsDirty(PannerNode::DopplerRateDirty);
124 void AudioListener::setDopplerFactor(double dopplerFactor)
126 if (m_dopplerFactor == dopplerFactor)
129 // This synchronizes with panner's process().
130 MutexLocker listenerLocker(m_listenerLock);
131 m_dopplerFactor = dopplerFactor;
132 markPannersAsDirty(PannerNode::DopplerRateDirty);
135 void AudioListener::setSpeedOfSound(double speedOfSound)
137 if (m_speedOfSound == speedOfSound)
140 // This synchronizes with panner's process().
141 MutexLocker listenerLocker(m_listenerLock);
142 m_speedOfSound = speedOfSound;
143 markPannersAsDirty(PannerNode::DopplerRateDirty);
146 } // namespace WebCore
148 #endif // ENABLE(WEB_AUDIO)