Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1145)

Unified Diff: third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.cpp

Issue 1361233004: Implement IIRFilter node for WebAudio. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix global-interface-listing Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.cpp b/third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.cpp
index dce992d003012f5d41d6429afa6e7242d77fc68b..43a5c47709c94bf8768f4b3425d94532e8b8adf0 100644
--- a/third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.cpp
@@ -50,6 +50,7 @@
#include "modules/webaudio/DelayNode.h"
#include "modules/webaudio/DynamicsCompressorNode.h"
#include "modules/webaudio/GainNode.h"
+#include "modules/webaudio/IIRFilterNode.h"
#include "modules/webaudio/MediaElementAudioSourceNode.h"
#include "modules/webaudio/MediaStreamAudioDestinationNode.h"
#include "modules/webaudio/MediaStreamAudioSourceNode.h"
@@ -63,6 +64,7 @@
#include "modules/webaudio/StereoPannerNode.h"
#include "modules/webaudio/WaveShaperNode.h"
#include "platform/ThreadSafeFunctional.h"
+#include "platform/audio/IIRFilter.h"
#include "public/platform/Platform.h"
#include "wtf/text/WTFString.h"
@@ -550,6 +552,90 @@ PeriodicWave* AbstractAudioContext::createPeriodicWave(DOMFloat32Array* real, DO
return PeriodicWave::create(sampleRate(), real, imag, isNormalizationDisabled);
}
+IIRFilterNode* AbstractAudioContext::createIIRFilter(Vector<double> feedforwardCoef, Vector<double> feedbackCoef, ExceptionState& exceptionState)
+{
+ ASSERT(isMainThread());
+
+ if (isContextClosed()) {
+ throwExceptionForClosedState(exceptionState);
+ return nullptr;
+ }
+
+ if (!feedbackCoef.size() || (feedbackCoef.size() > IIRFilter::kMaxOrder + 1)) {
tkent 2016/01/13 03:28:28 nit: You may compare with 0 like |feedbackCoef.siz
Raymond Toy 2016/01/13 18:30:53 Ah, this seems to have changed from the original w
+ 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() || (feedforwardCoef.size() > IIRFilter::kMaxOrder + 1)) {
tkent 2016/01/13 03:28:28 Ditto.
Raymond Toy 2016/01/13 18:30:53 Done.
+ 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]) {
tkent 2016/01/13 03:28:28 Ditto.
Raymond Toy 2016/01/13 18:30:53 Done.
+ 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]) {
tkent 2016/01/13 03:28:28 Ditto.
Raymond Toy 2016/01/13 18:30:53 Done.
+ 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 IIRFilterNode::create(*this, sampleRate(), feedforwardCoef, feedbackCoef);
+}
+
String AbstractAudioContext::state() const
{
// These strings had better match the strings for AudioContextState in AudioContext.idl.

Powered by Google App Engine
This is Rietveld 408576698