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 |
| index 401e199f33e63739b32b39c644269c57ca624921..8b2d3016c61642fce89f4e9b0d71853e24363ec3 100644 |
| --- a/third_party/WebKit/Source/modules/webaudio/IIRFilterNode.cpp |
| +++ b/third_party/WebKit/Source/modules/webaudio/IIRFilterNode.cpp |
| @@ -7,17 +7,18 @@ |
| #include "bindings/core/v8/ExceptionMessages.h" |
| #include "bindings/core/v8/ExceptionState.h" |
| #include "core/dom/ExceptionCode.h" |
| +#include "modules/webaudio/AbstractAudioContext.h" |
| #include "modules/webaudio/AudioBasicProcessorHandler.h" |
| #include "platform/Histogram.h" |
| namespace blink { |
| -IIRFilterNode::IIRFilterNode(AbstractAudioContext& context, float sampleRate, const Vector<double> feedforwardCoef, const Vector<double> feedbackCoef) |
| +IIRFilterNode::IIRFilterNode(AbstractAudioContext& context, const Vector<double> feedforwardCoef, const Vector<double> feedbackCoef) |
| : AudioNode(context) |
| { |
| setHandler(AudioBasicProcessorHandler::create( |
| - AudioHandler::NodeTypeIIRFilter, *this, sampleRate, |
| - adoptPtr(new IIRProcessor(sampleRate, 1, feedforwardCoef, feedbackCoef)))); |
| + AudioHandler::NodeTypeIIRFilter, *this, context.sampleRate(), |
| + adoptPtr(new IIRProcessor(context.sampleRate(), 1, feedforwardCoef, feedbackCoef)))); |
| // Histogram of the IIRFilter order. createIIRFilter ensures that the length of |feedbackCoef| |
| // is in the range [1, IIRFilter::kMaxOrder + 1]. The order is one less than the length of this |
| @@ -27,6 +28,94 @@ IIRFilterNode::IIRFilterNode(AbstractAudioContext& context, float sampleRate, co |
| filterOrderHistogram.sample(feedbackCoef.size() - 1); |
| } |
| +IIRFilterNode* IIRFilterNode::create( |
| + AbstractAudioContext& context, |
| + const Vector<double> feedforwardCoef, |
| + const Vector<double> feedbackCoef, |
| + ExceptionState& exceptionState) |
| +{ |
| + ASSERT(isMainThread()); |
|
hongchan
2016/05/13 01:20:12
DCHECK.
Raymond Toy
2016/05/20 23:12:00
Done.
|
| + |
| + if (context.isContextClosed()) { |
| + context.throwExceptionForClosedState(exceptionState); |
| + return nullptr; |
| + } |
| + |
| + if (feedbackCoef.size() == 0 || (feedbackCoef.size() > IIRFilter::kMaxOrder + 1)) { |
|
hongchan
2016/05/13 01:20:12
This line is over 80 cols. What should we do? Wrap
Raymond Toy
2016/05/13 15:59:51
Blink code is still governed by blink style. Blin
|
| + exceptionState.throwDOMException( |
| + NotSupportedError, |
| + ExceptionMessages::indexOutsideRange<size_t>( |
| + "number of feedback coefficients", |
| + feedbackCoef.size(), |
| + 1, |
| + ExceptionMessages::InclusiveBound, |
| + IIRFilter::kMaxOrder + 1, |
| + ExceptionMessages::InclusiveBound)); |
| + return nullptr; |
| + } |
| + |
| + if (feedforwardCoef.size() == 0 || (feedforwardCoef.size() > IIRFilter::kMaxOrder + 1)) { |
|
hongchan
2016/05/13 01:20:12
Over 80 cols.
|
| + exceptionState.throwDOMException( |
| + NotSupportedError, |
| + ExceptionMessages::indexOutsideRange<size_t>( |
| + "number of feedforward coefficients", |
| + feedforwardCoef.size(), |
| + 1, |
| + ExceptionMessages::InclusiveBound, |
| + IIRFilter::kMaxOrder + 1, |
| + ExceptionMessages::InclusiveBound)); |
| + return nullptr; |
| + } |
| + |
| + if (feedbackCoef[0] == 0) { |
| + exceptionState.throwDOMException( |
| + InvalidStateError, |
| + "First feedback coefficient cannot be zero."); |
| + return nullptr; |
| + } |
| + |
| + bool hasNonZeroCoef = false; |
| + |
| + for (size_t k = 0; k < feedforwardCoef.size(); ++k) { |
| + if (feedforwardCoef[k] != 0) { |
| + hasNonZeroCoef = true; |
| + break; |
| + } |
| + } |
| + |
| + if (!hasNonZeroCoef) { |
| + exceptionState.throwDOMException( |
| + InvalidStateError, |
| + "At least one feedforward coefficient must be non-zero."); |
| + return nullptr; |
| + } |
| + |
| + // Make sure all coefficents are finite. |
| + for (size_t k = 0; k < feedforwardCoef.size(); ++k) { |
| + double c = feedforwardCoef[k]; |
| + if (!std::isfinite(c)) { |
| + String name = "feedforward coefficient " + String::number(k); |
| + exceptionState.throwDOMException( |
| + InvalidStateError, |
| + ExceptionMessages::notAFiniteNumber(c, name.ascii().data())); |
| + return nullptr; |
| + } |
| + } |
| + |
| + for (size_t k = 0; k < feedbackCoef.size(); ++k) { |
| + double c = feedbackCoef[k]; |
| + if (!std::isfinite(c)) { |
| + String name = "feedback coefficient " + String::number(k); |
| + exceptionState.throwDOMException( |
| + InvalidStateError, |
| + ExceptionMessages::notAFiniteNumber(c, name.ascii().data())); |
| + return nullptr; |
| + } |
| + } |
| + |
| + return new IIRFilterNode(context, feedforwardCoef, feedbackCoef); |
| +} |
| + |
| DEFINE_TRACE(IIRFilterNode) |
| { |
| AudioNode::trace(visitor); |