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 setInternalChannelCountMode(ClampedMax); | 29 m_channelCountMode = ClampedMax; |
30 setInternalChannelInterpretation(AudioBus::Speakers); | 30 m_channelInterpretation = 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 DCHECK(isMainThread()); | 85 DCHECK(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 (internalChannelCountMode() != Max) | 92 if (m_channelCountMode != 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 DCHECK(isMainThread()); | 110 DCHECK(isMainThread()); |
111 BaseAudioContext::AutoLocker locker(context()); | 111 BaseAudioContext::AutoLocker locker(context()); |
112 | 112 |
| 113 ChannelCountMode oldMode = m_channelCountMode; |
| 114 |
113 if (mode == "clamped-max") { | 115 if (mode == "clamped-max") { |
114 setInternalChannelCountMode(ClampedMax); | 116 m_newChannelCountMode = ClampedMax; |
115 } else if (mode == "explicit") { | 117 } else if (mode == "explicit") { |
116 setInternalChannelCountMode(Explicit); | 118 m_newChannelCountMode = Explicit; |
117 } else if (mode == "max") { | 119 } else if (mode == "max") { |
118 // This is not supported for a StereoPannerNode, which can only handle | 120 // This is not supported for a StereoPannerNode, which can only handle |
119 // 1 or 2 channels. | 121 // 1 or 2 channels. |
120 exceptionState.throwDOMException( | 122 exceptionState.throwDOMException( |
121 NotSupportedError, | 123 NotSupportedError, |
122 "StereoPanner: 'max' is not allowed"); | 124 "StereoPanner: 'max' is not allowed"); |
| 125 m_newChannelCountMode = oldMode; |
| 126 } else { |
| 127 // Do nothing for other invalid values. |
| 128 m_newChannelCountMode = oldMode; |
123 } | 129 } |
| 130 |
| 131 if (m_newChannelCountMode != oldMode) |
| 132 context()->deferredTaskHandler().addChangedChannelCountMode(this); |
124 } | 133 } |
125 | 134 |
126 // ---------------------------------------------------------------- | 135 // ---------------------------------------------------------------- |
127 | 136 |
128 StereoPannerNode::StereoPannerNode(BaseAudioContext& context) | 137 StereoPannerNode::StereoPannerNode(BaseAudioContext& context) |
129 : AudioNode(context) | 138 : AudioNode(context) |
130 , m_pan(AudioParam::create(context, ParamTypeStereoPannerPan, 0, -1, 1)) | 139 , m_pan(AudioParam::create(context, ParamTypeStereoPannerPan, 0, -1, 1)) |
131 { | 140 { |
132 setHandler(StereoPannerHandler::create(*this, context.sampleRate(), m_pan->h
andler())); | 141 setHandler(StereoPannerHandler::create(*this, context.sampleRate(), m_pan->h
andler())); |
133 } | 142 } |
(...skipping 16 matching lines...) Expand all Loading... |
150 AudioNode::trace(visitor); | 159 AudioNode::trace(visitor); |
151 } | 160 } |
152 | 161 |
153 AudioParam* StereoPannerNode::pan() const | 162 AudioParam* StereoPannerNode::pan() const |
154 { | 163 { |
155 return m_pan; | 164 return m_pan; |
156 } | 165 } |
157 | 166 |
158 } // namespace blink | 167 } // namespace blink |
159 | 168 |
OLD | NEW |