| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/webaudio/IIRProcessor.h" | 5 #include "modules/webaudio/IIRProcessor.h" |
| 6 | 6 |
| 7 #include "modules/webaudio/IIRDSPKernel.h" | 7 #include "modules/webaudio/IIRDSPKernel.h" |
| 8 #include "wtf/PtrUtil.h" | 8 #include "wtf/PtrUtil.h" |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 IIRProcessor::IIRProcessor(float sampleRate, size_t numberOfChannels, const Vect
or<double>& feedforwardCoef, const Vector<double>& feedbackCoef) | 13 IIRProcessor::IIRProcessor(float sampleRate, size_t numberOfChannels, const Vect
or<double>& feedforwardCoef, const Vector<double>& feedbackCoef) |
| 14 : AudioDSPKernelProcessor(sampleRate, numberOfChannels) | 14 : AudioDSPKernelProcessor(sampleRate, numberOfChannels) |
| 15 { | 15 { |
| 16 unsigned feedbackLength = feedbackCoef.size(); | 16 unsigned feedbackLength = feedbackCoef.size(); |
| 17 unsigned feedforwardLength = feedforwardCoef.size(); | 17 unsigned feedforwardLength = feedforwardCoef.size(); |
| 18 ASSERT(feedbackLength > 0); | 18 DCHECK_GT(static_cast<int>(feedbackLength), 0); |
| 19 ASSERT(feedforwardLength > 0); | 19 DCHECK_GT(static_cast<int>(feedforwardLength), 0); |
| 20 | 20 |
| 21 m_feedforward.allocate(feedforwardLength); | 21 m_feedforward.allocate(feedforwardLength); |
| 22 m_feedback.allocate(feedbackLength); | 22 m_feedback.allocate(feedbackLength); |
| 23 m_feedforward.copyToRange(feedforwardCoef.data(), 0, feedforwardLength); | 23 m_feedforward.copyToRange(feedforwardCoef.data(), 0, feedforwardLength); |
| 24 m_feedback.copyToRange(feedbackCoef.data(), 0, feedbackLength); | 24 m_feedback.copyToRange(feedbackCoef.data(), 0, feedbackLength); |
| 25 | 25 |
| 26 // Need to scale the feedback and feedforward coefficients appropriately. (I
t's up to the caller | 26 // Need to scale the feedback and feedforward coefficients appropriately. (I
t's up to the caller |
| 27 // to ensure feedbackCoef[0] is not 0!) | 27 // to ensure feedbackCoef[0] is not 0!) |
| 28 ASSERT(feedbackCoef[0] != 0); | 28 DCHECK_NE(feedbackCoef[0], 0); |
| 29 | 29 |
| 30 if (feedbackCoef[0] != 1) { | 30 if (feedbackCoef[0] != 1) { |
| 31 // The provided filter is: | 31 // The provided filter is: |
| 32 // | 32 // |
| 33 // a[0]*y(n) + a[1]*y(n-1) + ... = b[0]*x(n) + b[1]*x(n-1) + ... | 33 // a[0]*y(n) + a[1]*y(n-1) + ... = b[0]*x(n) + b[1]*x(n-1) + ... |
| 34 // | 34 // |
| 35 // We want the leading coefficient of y(n) to be 1: | 35 // We want the leading coefficient of y(n) to be 1: |
| 36 // | 36 // |
| 37 // y(n) + a[1]/a[0]*y(n-1) + ... = b[0]/a[0]*x(n) + b[1]/a[0]*x(n-1) +
... | 37 // y(n) + a[1]/a[0]*y(n-1) + ... = b[0]/a[0]*x(n) + b[1]/a[0]*x(n-1) +
... |
| 38 // | 38 // |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 for (unsigned i = 0; i < m_kernels.size(); ++i) | 74 for (unsigned i = 0; i < m_kernels.size(); ++i) |
| 75 m_kernels[i]->process(source->channel(i)->data(), destination->channel(i
)->mutableData(), framesToProcess); | 75 m_kernels[i]->process(source->channel(i)->data(), destination->channel(i
)->mutableData(), framesToProcess); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void IIRProcessor::getFrequencyResponse(int nFrequencies, const float* frequency
Hz, float* magResponse, float* phaseResponse) | 78 void IIRProcessor::getFrequencyResponse(int nFrequencies, const float* frequency
Hz, float* magResponse, float* phaseResponse) |
| 79 { | 79 { |
| 80 m_responseKernel->getFrequencyResponse(nFrequencies, frequencyHz, magRespons
e, phaseResponse); | 80 m_responseKernel->getFrequencyResponse(nFrequencies, frequencyHz, magRespons
e, phaseResponse); |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace blink | 83 } // namespace blink |
| OLD | NEW |