| 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..bde304df7f59c90589c682379dea197ab348585f 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)
|
| +{
|
| + DCHECK(isMainThread());
|
| +
|
| + if (context.isContextClosed()) {
|
| + context.throwExceptionForClosedState(exceptionState);
|
| + return nullptr;
|
| + }
|
| +
|
| + if (feedbackCoef.size() == 0 || (feedbackCoef.size() > IIRFilter::kMaxOrder + 1)) {
|
| + 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)) {
|
| + 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);
|
|
|