| 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/AbstractAudioContext.h" | |
| 11 #include "modules/webaudio/AudioNodeInput.h" | 10 #include "modules/webaudio/AudioNodeInput.h" |
| 12 #include "modules/webaudio/AudioNodeOutput.h" | 11 #include "modules/webaudio/AudioNodeOutput.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 { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 return; | 76 return; |
| 77 | 77 |
| 78 m_stereoPanner = Spatializer::create(Spatializer::PanningModelEqualPower, sa
mpleRate()); | 78 m_stereoPanner = Spatializer::create(Spatializer::PanningModelEqualPower, sa
mpleRate()); |
| 79 | 79 |
| 80 AudioHandler::initialize(); | 80 AudioHandler::initialize(); |
| 81 } | 81 } |
| 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 AbstractAudioContext::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 (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 ASSERT(isMainThread()); | 110 ASSERT(isMainThread()); |
| 111 AbstractAudioContext::AutoLocker locker(context()); | 111 BaseAudioContext::AutoLocker locker(context()); |
| 112 | 112 |
| 113 ChannelCountMode oldMode = m_channelCountMode; | 113 ChannelCountMode oldMode = m_channelCountMode; |
| 114 | 114 |
| 115 if (mode == "clamped-max") { | 115 if (mode == "clamped-max") { |
| 116 m_newChannelCountMode = ClampedMax; | 116 m_newChannelCountMode = ClampedMax; |
| 117 } else if (mode == "explicit") { | 117 } else if (mode == "explicit") { |
| 118 m_newChannelCountMode = Explicit; | 118 m_newChannelCountMode = Explicit; |
| 119 } else if (mode == "max") { | 119 } else if (mode == "max") { |
| 120 // This is not supported for a StereoPannerNode, which can only handle | 120 // This is not supported for a StereoPannerNode, which can only handle |
| 121 // 1 or 2 channels. | 121 // 1 or 2 channels. |
| 122 exceptionState.throwDOMException( | 122 exceptionState.throwDOMException( |
| 123 NotSupportedError, | 123 NotSupportedError, |
| 124 "StereoPanner: 'max' is not allowed"); | 124 "StereoPanner: 'max' is not allowed"); |
| 125 m_newChannelCountMode = oldMode; | 125 m_newChannelCountMode = oldMode; |
| 126 } else { | 126 } else { |
| 127 // Do nothing for other invalid values. | 127 // Do nothing for other invalid values. |
| 128 m_newChannelCountMode = oldMode; | 128 m_newChannelCountMode = oldMode; |
| 129 } | 129 } |
| 130 | 130 |
| 131 if (m_newChannelCountMode != oldMode) | 131 if (m_newChannelCountMode != oldMode) |
| 132 context()->deferredTaskHandler().addChangedChannelCountMode(this); | 132 context()->deferredTaskHandler().addChangedChannelCountMode(this); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // ---------------------------------------------------------------- | 135 // ---------------------------------------------------------------- |
| 136 | 136 |
| 137 StereoPannerNode::StereoPannerNode(AbstractAudioContext& context, float sampleRa
te) | 137 StereoPannerNode::StereoPannerNode(BaseAudioContext& context, float sampleRate) |
| 138 : AudioNode(context) | 138 : AudioNode(context) |
| 139 , m_pan(AudioParam::create(context, 0)) | 139 , m_pan(AudioParam::create(context, 0)) |
| 140 { | 140 { |
| 141 setHandler(StereoPannerHandler::create(*this, sampleRate, m_pan->handler()))
; | 141 setHandler(StereoPannerHandler::create(*this, sampleRate, m_pan->handler()))
; |
| 142 } | 142 } |
| 143 | 143 |
| 144 StereoPannerNode* StereoPannerNode::create(AbstractAudioContext& context, float
sampleRate) | 144 StereoPannerNode* StereoPannerNode::create(BaseAudioContext& context, float samp
leRate) |
| 145 { | 145 { |
| 146 return new StereoPannerNode(context, sampleRate); | 146 return new StereoPannerNode(context, sampleRate); |
| 147 } | 147 } |
| 148 | 148 |
| 149 DEFINE_TRACE(StereoPannerNode) | 149 DEFINE_TRACE(StereoPannerNode) |
| 150 { | 150 { |
| 151 visitor->trace(m_pan); | 151 visitor->trace(m_pan); |
| 152 AudioNode::trace(visitor); | 152 AudioNode::trace(visitor); |
| 153 } | 153 } |
| 154 | 154 |
| 155 AudioParam* StereoPannerNode::pan() const | 155 AudioParam* StereoPannerNode::pan() const |
| 156 { | 156 { |
| 157 return m_pan; | 157 return m_pan; |
| 158 } | 158 } |
| 159 | 159 |
| 160 } // namespace blink | 160 } // namespace blink |
| 161 | 161 |
| OLD | NEW |