Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Side by Side Diff: Source/modules/webaudio/AudioListener.cpp

Issue 232453003: Add logic to cache elements of panner node from calculation with own attributes and AudioListener (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Unrelated fix has been separated. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/modules/webaudio/AudioListener.h ('k') | Source/modules/webaudio/PannerNode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 14 matching lines...) Expand all
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 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. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "config.h" 29 #include "config.h"
30 30
31 #if ENABLE(WEB_AUDIO) 31 #if ENABLE(WEB_AUDIO)
32 32
33 #include "modules/webaudio/AudioListener.h" 33 #include "modules/webaudio/AudioListener.h"
34 34
35 #include "modules/webaudio/PannerNode.h"
35 #include "platform/audio/AudioBus.h" 36 #include "platform/audio/AudioBus.h"
36 37
37 namespace WebCore { 38 namespace WebCore {
38 39
39 AudioListener::AudioListener() 40 AudioListener::AudioListener()
40 : m_position(0, 0, 0) 41 : m_position(0, 0, 0)
41 , m_orientation(0, 0, -1) 42 , m_orientation(0, 0, -1)
42 , m_upVector(0, 1, 0) 43 , m_upVector(0, 1, 0)
43 , m_velocity(0, 0, 0) 44 , m_velocity(0, 0, 0)
44 , m_dopplerFactor(1) 45 , m_dopplerFactor(1)
45 , m_speedOfSound(343.3) 46 , m_speedOfSound(343.3)
46 { 47 {
47 ScriptWrappable::init(this); 48 ScriptWrappable::init(this);
48 } 49 }
49 50
51 AudioListener::~AudioListener()
52 {
53 m_panners.clear();
54 }
55
56 void AudioListener::addPanner(PannerNode* panner)
57 {
58 if (!panner)
59 return;
60
61 m_panners.append(panner);
62 }
63
64 void AudioListener::removePanner(PannerNode* panner)
65 {
66 for (unsigned i = 0; i < m_panners.size(); ++i) {
67 if (panner == m_panners[i]) {
68 m_panners.remove(i);
69 break;
70 }
71 }
72 }
73
74 void AudioListener::markPannersAsDirty(unsigned type)
75 {
76 for (unsigned i = 0; i < m_panners.size(); ++i)
77 m_panners[i]->markPannerAsDirty(type);
78 }
79
80 void AudioListener::setPosition(const FloatPoint3D &position)
81 {
82 if (m_position == position)
83 return;
84
85 // This synchronizes with panner's process().
86 MutexLocker listenerLocker(m_listenerLock);
87 m_position = position;
88 markPannersAsDirty(PannerNode::AzimuthElevationDirty | PannerNode::DistanceC oneGainDirty | PannerNode::DopplerRateDirty);
89 }
90
91 void AudioListener::setOrientation(const FloatPoint3D &orientation)
92 {
93 if (m_orientation == orientation)
94 return;
95
96 // This synchronizes with panner's process().
97 MutexLocker listenerLocker(m_listenerLock);
98 m_orientation = orientation;
99 markPannersAsDirty(PannerNode::AzimuthElevationDirty);
100 }
101
102 void AudioListener::setUpVector(const FloatPoint3D &upVector)
103 {
104 if (m_upVector == upVector)
105 return;
106
107 // This synchronizes with panner's process().
108 MutexLocker listenerLocker(m_listenerLock);
109 m_upVector = upVector;
110 markPannersAsDirty(PannerNode::AzimuthElevationDirty);
111 }
112
113 void AudioListener::setVelocity(const FloatPoint3D &velocity)
114 {
115 if (m_velocity == velocity)
116 return;
117
118 // This synchronizes with panner's process().
119 MutexLocker listenerLocker(m_listenerLock);
120 m_velocity = velocity;
121 markPannersAsDirty(PannerNode::DopplerRateDirty);
122 }
123
124 void AudioListener::setDopplerFactor(double dopplerFactor)
125 {
126 if (m_dopplerFactor == dopplerFactor)
127 return;
128
129 // This synchronizes with panner's process().
130 MutexLocker listenerLocker(m_listenerLock);
131 m_dopplerFactor = dopplerFactor;
132 markPannersAsDirty(PannerNode::DopplerRateDirty);
133 }
134
135 void AudioListener::setSpeedOfSound(double speedOfSound)
136 {
137 if (m_speedOfSound == speedOfSound)
138 return;
139
140 // This synchronizes with panner's process().
141 MutexLocker listenerLocker(m_listenerLock);
142 m_speedOfSound = speedOfSound;
143 markPannersAsDirty(PannerNode::DopplerRateDirty);
144 }
145
50 } // namespace WebCore 146 } // namespace WebCore
51 147
52 #endif // ENABLE(WEB_AUDIO) 148 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/modules/webaudio/AudioListener.h ('k') | Source/modules/webaudio/PannerNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698