// 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. #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_IIR_FILTER_NODE_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_IIR_FILTER_NODE_H_ #include "base/memory/weak_ptr.h" #include "base/single_thread_task_runner.h" #include "third_party/blink/renderer/core/typed_arrays/array_buffer_view_helpers.h" #include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h" #include "third_party/blink/renderer/modules/webaudio/audio_basic_processor_handler.h" #include "third_party/blink/renderer/modules/webaudio/audio_node.h" #include "third_party/blink/renderer/modules/webaudio/iir_processor.h" namespace blink { class BaseAudioContext; class ExceptionState; class IIRFilterOptions; class IIRFilterHandler : public AudioBasicProcessorHandler, public base::SupportsWeakPtr { public: static scoped_refptr Create( AudioNode&, float sample_rate, const Vector& feedforward_coef, const Vector& feedback_coef, bool is_filter_stable); void Process(uint32_t frames_to_process) override; private: IIRFilterHandler(AudioNode&, float sample_rate, const Vector& feedforward_coef, const Vector& feedback_coef, bool is_filter_stable); void NotifyBadState() const; // Only notify the user of the once. No need to spam the console with // messages, because once we're in a bad state, it usually stays that way // forever. Only accessed from audio thread. bool did_warn_bad_filter_state_ = false; scoped_refptr task_runner_; }; class IIRFilterNode : public AudioNode { DEFINE_WRAPPERTYPEINFO(); public: static IIRFilterNode* Create(BaseAudioContext&, const Vector& feedforward, const Vector& feedback, ExceptionState&); static IIRFilterNode* Create(BaseAudioContext*, const IIRFilterOptions*, ExceptionState&); IIRFilterNode(BaseAudioContext&, const Vector& denominator, const Vector& numerator, bool is_filter_stable); void Trace(Visitor*) const override; // Get the magnitude and phase response of the filter at the given // set of frequencies (in Hz). The phase response is in radians. void getFrequencyResponse(NotShared frequency_hz, NotShared mag_response, NotShared phase_response, ExceptionState&); // InspectorHelperMixin void ReportDidCreate() final; void ReportWillBeDestroyed() final; private: IIRProcessor* GetIIRFilterProcessor() const; }; } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_IIR_FILTER_NODE_H_