OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/webaudio/StereoPannerNode.h" | 5 #include "modules/webaudio/StereoPannerNode.h" |
6 #include "bindings/core/v8/ExceptionMessages.h" | 6 #include "bindings/core/v8/ExceptionMessages.h" |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "core/dom/ExceptionCode.h" | 8 #include "core/dom/ExceptionCode.h" |
9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
10 #include "modules/webaudio/AudioNodeInput.h" | 10 #include "modules/webaudio/AudioNodeInput.h" |
11 #include "modules/webaudio/AudioNodeOutput.h" | 11 #include "modules/webaudio/AudioNodeOutput.h" |
12 #include "modules/webaudio/BaseAudioContext.h" | 12 #include "modules/webaudio/BaseAudioContext.h" |
13 #include "platform/audio/StereoPanner.h" | 13 #include "platform/audio/StereoPanner.h" |
14 #include "wtf/MathExtras.h" | 14 #include "wtf/MathExtras.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 StereoPannerHandler::StereoPannerHandler(AudioNode& node, float sampleRate, Audi
oParamHandler& pan) | 18 StereoPannerHandler::StereoPannerHandler(AudioNode& node, float sampleRate, Audi
oParamHandler& pan) |
19 : AudioHandler(NodeTypeStereoPanner, node, sampleRate) | 19 : AudioHandler(NodeTypeStereoPanner, node, sampleRate) |
20 , m_pan(pan) | 20 , m_pan(pan) |
21 , m_sampleAccuratePanValues(ProcessingSizeInFrames) | 21 , m_sampleAccuratePanValues(ProcessingSizeInFrames) |
22 { | 22 { |
23 addInput(); | 23 addInput(); |
24 addOutput(2); | 24 addOutput(2); |
25 | 25 |
26 // The node-specific default mixing rules declare that StereoPannerNode | 26 // The node-specific default mixing rules declare that StereoPannerNode |
27 // can handle mono to stereo and stereo to stereo conversion. | 27 // can handle mono to stereo and stereo to stereo conversion. |
28 m_channelCount = 2; | 28 m_channelCount = 2; |
29 m_channelCountMode = ClampedMax; | 29 setInternalChannelCountMode(ClampedMax); |
30 m_channelInterpretation = AudioBus::Speakers; | 30 setInternalChannelInterpretation(AudioBus::Speakers); |
31 | 31 |
32 initialize(); | 32 initialize(); |
33 } | 33 } |
34 | 34 |
35 PassRefPtr<StereoPannerHandler> StereoPannerHandler::create(AudioNode& node, flo
at sampleRate, AudioParamHandler& pan) | 35 PassRefPtr<StereoPannerHandler> StereoPannerHandler::create(AudioNode& node, flo
at sampleRate, AudioParamHandler& pan) |
36 { | 36 { |
37 return adoptRef(new StereoPannerHandler(node, sampleRate, pan)); | 37 return adoptRef(new StereoPannerHandler(node, sampleRate, pan)); |
38 } | 38 } |
39 | 39 |
40 StereoPannerHandler::~StereoPannerHandler() | 40 StereoPannerHandler::~StereoPannerHandler() |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 void StereoPannerHandler::setChannelCount(unsigned long channelCount, ExceptionS
tate& exceptionState) | 83 void StereoPannerHandler::setChannelCount(unsigned long channelCount, ExceptionS
tate& exceptionState) |
84 { | 84 { |
85 ASSERT(isMainThread()); | 85 ASSERT(isMainThread()); |
86 BaseAudioContext::AutoLocker locker(context()); | 86 BaseAudioContext::AutoLocker locker(context()); |
87 | 87 |
88 // A PannerNode only supports 1 or 2 channels | 88 // A PannerNode only supports 1 or 2 channels |
89 if (channelCount > 0 && channelCount <= 2) { | 89 if (channelCount > 0 && channelCount <= 2) { |
90 if (m_channelCount != channelCount) { | 90 if (m_channelCount != channelCount) { |
91 m_channelCount = channelCount; | 91 m_channelCount = channelCount; |
92 if (m_channelCountMode != Max) | 92 if (internalChannelCountMode() != Max) |
93 updateChannelsForInputs(); | 93 updateChannelsForInputs(); |
94 } | 94 } |
95 } else { | 95 } else { |
96 exceptionState.throwDOMException( | 96 exceptionState.throwDOMException( |
97 NotSupportedError, | 97 NotSupportedError, |
98 ExceptionMessages::indexOutsideRange<unsigned long>( | 98 ExceptionMessages::indexOutsideRange<unsigned long>( |
99 "channelCount", | 99 "channelCount", |
100 channelCount, | 100 channelCount, |
101 1, | 101 1, |
102 ExceptionMessages::InclusiveBound, | 102 ExceptionMessages::InclusiveBound, |
103 2, | 103 2, |
104 ExceptionMessages::InclusiveBound)); | 104 ExceptionMessages::InclusiveBound)); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 void StereoPannerHandler::setChannelCountMode(const String& mode, ExceptionState
& exceptionState) | 108 void StereoPannerHandler::setChannelCountMode(const String& mode, ExceptionState
& exceptionState) |
109 { | 109 { |
110 ASSERT(isMainThread()); | 110 ASSERT(isMainThread()); |
111 BaseAudioContext::AutoLocker locker(context()); | 111 BaseAudioContext::AutoLocker locker(context()); |
112 | 112 |
113 ChannelCountMode oldMode = m_channelCountMode; | |
114 | |
115 if (mode == "clamped-max") { | 113 if (mode == "clamped-max") { |
116 m_newChannelCountMode = ClampedMax; | 114 setInternalChannelCountMode(ClampedMax); |
117 } else if (mode == "explicit") { | 115 } else if (mode == "explicit") { |
118 m_newChannelCountMode = Explicit; | 116 setInternalChannelCountMode(Explicit); |
119 } else if (mode == "max") { | 117 } else if (mode == "max") { |
120 // This is not supported for a StereoPannerNode, which can only handle | 118 // This is not supported for a StereoPannerNode, which can only handle |
121 // 1 or 2 channels. | 119 // 1 or 2 channels. |
122 exceptionState.throwDOMException( | 120 exceptionState.throwDOMException( |
123 NotSupportedError, | 121 NotSupportedError, |
124 "StereoPanner: 'max' is not allowed"); | 122 "StereoPanner: 'max' is not allowed"); |
125 m_newChannelCountMode = oldMode; | |
126 } else { | |
127 // Do nothing for other invalid values. | |
128 m_newChannelCountMode = oldMode; | |
129 } | 123 } |
130 | |
131 if (m_newChannelCountMode != oldMode) | |
132 context()->deferredTaskHandler().addChangedChannelCountMode(this); | |
133 } | 124 } |
134 | 125 |
135 // ---------------------------------------------------------------- | 126 // ---------------------------------------------------------------- |
136 | 127 |
137 StereoPannerNode::StereoPannerNode(BaseAudioContext& context) | 128 StereoPannerNode::StereoPannerNode(BaseAudioContext& context) |
138 : AudioNode(context) | 129 : AudioNode(context) |
139 , m_pan(AudioParam::create(context, ParamTypeStereoPannerPan, 0, -1, 1)) | 130 , m_pan(AudioParam::create(context, ParamTypeStereoPannerPan, 0, -1, 1)) |
140 { | 131 { |
141 setHandler(StereoPannerHandler::create(*this, context.sampleRate(), m_pan->h
andler())); | 132 setHandler(StereoPannerHandler::create(*this, context.sampleRate(), m_pan->h
andler())); |
142 } | 133 } |
(...skipping 16 matching lines...) Expand all Loading... |
159 AudioNode::trace(visitor); | 150 AudioNode::trace(visitor); |
160 } | 151 } |
161 | 152 |
162 AudioParam* StereoPannerNode::pan() const | 153 AudioParam* StereoPannerNode::pan() const |
163 { | 154 { |
164 return m_pan; | 155 return m_pan; |
165 } | 156 } |
166 | 157 |
167 } // namespace blink | 158 } // namespace blink |
168 | 159 |
OLD | NEW |