Chromium Code Reviews| Index: third_party/WebKit/Source/modules/webaudio/IIRFilterNode.cpp |
| diff --git a/third_party/WebKit/Source/modules/webaudio/IIRFilterNode.cpp b/third_party/WebKit/Source/modules/webaudio/IIRFilterNode.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9a06b77695d882ecf27cfb54d9d7186fd699082b |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/webaudio/IIRFilterNode.cpp |
| @@ -0,0 +1,80 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
|
tkent
2016/01/13 03:28:28
2016
Raymond Toy
2016/01/13 18:30:53
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "modules/webaudio/IIRFilterNode.h" |
| + |
| +#include "bindings/core/v8/ExceptionMessages.h" |
| +#include "bindings/core/v8/ExceptionState.h" |
| +#include "core/dom/ExceptionCode.h" |
| +#include "modules/webaudio/AudioBasicProcessorHandler.h" |
| + |
| +namespace blink { |
| + |
| +IIRFilterNode::IIRFilterNode(AbstractAudioContext& context, float sampleRate, const Vector<double> feedforwardCoef, const Vector<double> feedbackCoef) |
| + : AudioNode(context) |
| +{ |
| + setHandler(AudioBasicProcessorHandler::create( |
| + AudioHandler::NodeTypeIIRFilter, *this, sampleRate, |
| + adoptPtr(new IIRProcessor(sampleRate, 1, feedforwardCoef, feedbackCoef)))); |
| +} |
| + |
| +DEFINE_TRACE(IIRFilterNode) |
| +{ |
| + AudioNode::trace(visitor); |
| +} |
| + |
| +IIRProcessor* IIRFilterNode::iirProcessor() const |
| +{ |
| + return static_cast<IIRProcessor*>(static_cast<AudioBasicProcessorHandler&>(handler()).processor()); |
| +} |
| + |
| +void IIRFilterNode::getFrequencyResponse(const DOMFloat32Array* frequencyHz, DOMFloat32Array* magResponse, DOMFloat32Array* phaseResponse, ExceptionState& exceptionState) |
| +{ |
| + if (!frequencyHz) { |
| + exceptionState.throwDOMException( |
| + NotSupportedError, |
| + "frequencyHz array cannot be null"); |
| + return; |
| + } |
| + |
| + if (!magResponse) { |
| + exceptionState.throwDOMException( |
| + NotSupportedError, |
| + "magResponse array cannot be null"); |
| + return; |
| + } |
| + |
| + if (!phaseResponse) { |
| + exceptionState.throwDOMException( |
| + NotSupportedError, |
| + "phaseResponse array cannot be null"); |
| + return; |
| + } |
| + |
| + unsigned frequencyHzLength = frequencyHz->length(); |
| + |
| + if (magResponse->length() < frequencyHzLength) { |
| + exceptionState.throwDOMException( |
| + NotSupportedError, |
| + ExceptionMessages::indexExceedsMinimumBound( |
| + "magResponse length", |
| + magResponse->length(), |
| + frequencyHzLength)); |
| + return; |
| + } |
| + |
| + if (phaseResponse->length() < frequencyHzLength) { |
| + exceptionState.throwDOMException( |
| + NotSupportedError, |
| + ExceptionMessages::indexExceedsMinimumBound( |
| + "phaseResponse length", |
| + phaseResponse->length(), |
| + frequencyHzLength)); |
| + return; |
| + } |
| + |
| + iirProcessor()->getFrequencyResponse(frequencyHzLength, frequencyHz->data(), magResponse->data(), phaseResponse->data()); |
| +} |
| + |
| +} // namespace blink |