| OLD | NEW |
| 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "modules/webaudio/AnalyserNode.h" | 25 #include "modules/webaudio/AnalyserNode.h" |
| 26 #include "bindings/core/v8/ExceptionMessages.h" | 26 #include "bindings/core/v8/ExceptionMessages.h" |
| 27 #include "bindings/core/v8/ExceptionState.h" | 27 #include "bindings/core/v8/ExceptionState.h" |
| 28 #include "core/dom/ExceptionCode.h" | 28 #include "core/dom/ExceptionCode.h" |
| 29 #include "modules/webaudio/AnalyserOptions.h" |
| 29 #include "modules/webaudio/AudioNodeInput.h" | 30 #include "modules/webaudio/AudioNodeInput.h" |
| 30 #include "modules/webaudio/AudioNodeOutput.h" | 31 #include "modules/webaudio/AudioNodeOutput.h" |
| 31 | 32 |
| 32 namespace blink { | 33 namespace blink { |
| 33 | 34 |
| 34 AnalyserHandler::AnalyserHandler(AudioNode& node, float sampleRate) | 35 AnalyserHandler::AnalyserHandler(AudioNode& node, float sampleRate) |
| 35 : AudioBasicInspectorHandler(NodeTypeAnalyser, node, sampleRate, 2) | 36 : AudioBasicInspectorHandler(NodeTypeAnalyser, node, sampleRate, 2) |
| 36 { | 37 { |
| 37 initialize(); | 38 initialize(); |
| 38 } | 39 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 { | 94 { |
| 94 if (k > minDecibels()) { | 95 if (k > minDecibels()) { |
| 95 m_analyser.setMaxDecibels(k); | 96 m_analyser.setMaxDecibels(k); |
| 96 } else { | 97 } else { |
| 97 exceptionState.throwDOMException( | 98 exceptionState.throwDOMException( |
| 98 IndexSizeError, | 99 IndexSizeError, |
| 99 ExceptionMessages::indexExceedsMinimumBound("maxDecibels", k, minDec
ibels())); | 100 ExceptionMessages::indexExceedsMinimumBound("maxDecibels", k, minDec
ibels())); |
| 100 } | 101 } |
| 101 } | 102 } |
| 102 | 103 |
| 104 void AnalyserHandler::setMinMaxDecibels(double minDecibels, double maxDecibels,
ExceptionState& exceptionState) |
| 105 { |
| 106 if (minDecibels >= maxDecibels) { |
| 107 exceptionState.throwDOMException( |
| 108 IndexSizeError, |
| 109 "maxDecibels (" + String::number(maxDecibels) |
| 110 + ") must be greater than or equal to minDecibels " |
| 111 + "( " + String::number(minDecibels) + ")."); |
| 112 return; |
| 113 } |
| 114 m_analyser.setMinDecibels(minDecibels); |
| 115 m_analyser.setMaxDecibels(maxDecibels); |
| 116 } |
| 117 |
| 103 void AnalyserHandler::setSmoothingTimeConstant(double k, ExceptionState& excepti
onState) | 118 void AnalyserHandler::setSmoothingTimeConstant(double k, ExceptionState& excepti
onState) |
| 104 { | 119 { |
| 105 if (k >= 0 && k <= 1) { | 120 if (k >= 0 && k <= 1) { |
| 106 m_analyser.setSmoothingTimeConstant(k); | 121 m_analyser.setSmoothingTimeConstant(k); |
| 107 } else { | 122 } else { |
| 108 exceptionState.throwDOMException( | 123 exceptionState.throwDOMException( |
| 109 IndexSizeError, | 124 IndexSizeError, |
| 110 ExceptionMessages::indexOutsideRange("smoothing value", k, 0.0, Exce
ptionMessages::InclusiveBound, 1.0, ExceptionMessages::InclusiveBound)); | 125 ExceptionMessages::indexOutsideRange("smoothing value", k, 0.0, Exce
ptionMessages::InclusiveBound, 1.0, ExceptionMessages::InclusiveBound)); |
| 111 } | 126 } |
| 112 } | 127 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 124 DCHECK(isMainThread()); | 139 DCHECK(isMainThread()); |
| 125 | 140 |
| 126 if (context.isContextClosed()) { | 141 if (context.isContextClosed()) { |
| 127 context.throwExceptionForClosedState(exceptionState); | 142 context.throwExceptionForClosedState(exceptionState); |
| 128 return nullptr; | 143 return nullptr; |
| 129 } | 144 } |
| 130 | 145 |
| 131 return new AnalyserNode(context); | 146 return new AnalyserNode(context); |
| 132 } | 147 } |
| 133 | 148 |
| 149 AnalyserNode* AnalyserNode::create(BaseAudioContext* context, const AnalyserOpti
ons& options, ExceptionState& exceptionState) |
| 150 { |
| 151 DCHECK(isMainThread()); |
| 152 |
| 153 AnalyserNode* node = create(*context, exceptionState); |
| 154 |
| 155 if (!node) |
| 156 return nullptr; |
| 157 |
| 158 node->handleChannelOptions(options, exceptionState); |
| 159 |
| 160 if (options.hasFftSize()) |
| 161 node->setFftSize(options.fftSize(), exceptionState); |
| 162 |
| 163 if (options.hasSmoothingTimeConstant()) |
| 164 node->setSmoothingTimeConstant(options.smoothingTimeConstant(), exceptio
nState); |
| 165 |
| 166 // minDecibels and maxDecibels have default values. Set both of the values |
| 167 // at once. |
| 168 node->setMinMaxDecibels(options.minDecibels(), options.maxDecibels(), except
ionState); |
| 169 |
| 170 return node; |
| 171 } |
| 172 |
| 134 AnalyserHandler& AnalyserNode::analyserHandler() const | 173 AnalyserHandler& AnalyserNode::analyserHandler() const |
| 135 { | 174 { |
| 136 return static_cast<AnalyserHandler&>(handler()); | 175 return static_cast<AnalyserHandler&>(handler()); |
| 137 } | 176 } |
| 138 | 177 |
| 139 unsigned AnalyserNode::fftSize() const | 178 unsigned AnalyserNode::fftSize() const |
| 140 { | 179 { |
| 141 return analyserHandler().fftSize(); | 180 return analyserHandler().fftSize(); |
| 142 } | 181 } |
| 143 | 182 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 159 double AnalyserNode::minDecibels() const | 198 double AnalyserNode::minDecibels() const |
| 160 { | 199 { |
| 161 return analyserHandler().minDecibels(); | 200 return analyserHandler().minDecibels(); |
| 162 } | 201 } |
| 163 | 202 |
| 164 void AnalyserNode::setMaxDecibels(double max, ExceptionState& exceptionState) | 203 void AnalyserNode::setMaxDecibels(double max, ExceptionState& exceptionState) |
| 165 { | 204 { |
| 166 analyserHandler().setMaxDecibels(max, exceptionState); | 205 analyserHandler().setMaxDecibels(max, exceptionState); |
| 167 } | 206 } |
| 168 | 207 |
| 208 void AnalyserNode::setMinMaxDecibels(double min, double max, ExceptionState& exc
eptionState) |
| 209 { |
| 210 analyserHandler().setMinMaxDecibels(min, max, exceptionState); |
| 211 } |
| 212 |
| 169 double AnalyserNode::maxDecibels() const | 213 double AnalyserNode::maxDecibels() const |
| 170 { | 214 { |
| 171 return analyserHandler().maxDecibels(); | 215 return analyserHandler().maxDecibels(); |
| 172 } | 216 } |
| 173 | 217 |
| 174 void AnalyserNode::setSmoothingTimeConstant(double smoothingTime, ExceptionState
& exceptionState) | 218 void AnalyserNode::setSmoothingTimeConstant(double smoothingTime, ExceptionState
& exceptionState) |
| 175 { | 219 { |
| 176 analyserHandler().setSmoothingTimeConstant(smoothingTime, exceptionState); | 220 analyserHandler().setSmoothingTimeConstant(smoothingTime, exceptionState); |
| 177 } | 221 } |
| 178 | 222 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 196 analyserHandler().getFloatTimeDomainData(array); | 240 analyserHandler().getFloatTimeDomainData(array); |
| 197 } | 241 } |
| 198 | 242 |
| 199 void AnalyserNode::getByteTimeDomainData(DOMUint8Array* array) | 243 void AnalyserNode::getByteTimeDomainData(DOMUint8Array* array) |
| 200 { | 244 { |
| 201 analyserHandler().getByteTimeDomainData(array); | 245 analyserHandler().getByteTimeDomainData(array); |
| 202 } | 246 } |
| 203 | 247 |
| 204 } // namespace blink | 248 } // namespace blink |
| 205 | 249 |
| OLD | NEW |