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

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

Issue 1361233004: Implement IIRFilter node for WebAudio. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test issue by printing fewer digits. 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/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..0cf20480324d354b2f7beddd9f74b94e074f3051
--- /dev/null
+++ b/third_party/WebKit/Source/modules/webaudio/IIRFilterNode.cpp
@@ -0,0 +1,80 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// 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

Powered by Google App Engine
This is Rietveld 408576698