Chromium Code Reviews| Index: third_party/WebKit/Source/modules/webaudio/IIRDSPKernel.cpp |
| diff --git a/third_party/WebKit/Source/modules/webaudio/IIRDSPKernel.cpp b/third_party/WebKit/Source/modules/webaudio/IIRDSPKernel.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cedcb315ed5a6ae4fb68cb405ae2313dd0fa911d |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/webaudio/IIRDSPKernel.cpp |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
|
tkent
2016/01/13 03:28:28
2016
Raymond Toy
2016/01/13 18:30:53
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "modules/webaudio/IIRDSPKernel.h" |
| + |
| +#include "platform/FloatConversion.h" |
| + |
| +namespace blink { |
| + |
| +void IIRDSPKernel::process(const float* source, float* destination, size_t framesToProcess) |
| +{ |
| + ASSERT(source); |
| + ASSERT(destination); |
| + |
| + m_iir.process(source, destination, framesToProcess); |
| +} |
| + |
| +void IIRDSPKernel::getFrequencyResponse(int nFrequencies, const float* frequencyHz, float* magResponse, float* phaseResponse) |
| +{ |
| + bool isGood = nFrequencies > 0 && frequencyHz && magResponse && phaseResponse; |
| + ASSERT(isGood); |
| + if (!isGood) |
| + return; |
| + |
| + Vector<float> frequency(nFrequencies); |
| + |
| + double nyquist = this->nyquist(); |
| + |
| + // Convert from frequency in Hz to normalized frequency (0 -> 1), |
| + // with 1 equal to the Nyquist frequency. |
| + for (int k = 0; k < nFrequencies; ++k) |
| + frequency[k] = narrowPrecisionToFloat(frequencyHz[k] / nyquist); |
| + |
| + m_iir.getFrequencyResponse(nFrequencies, frequency.data(), magResponse, phaseResponse); |
| +} |
| + |
| +double IIRDSPKernel::tailTime() const |
| +{ |
| + // TODO(rtoy): This is true mathematically (infinite impulse response), but perhaps it should be |
| + // limited to a smaller value, possibly based on the actual filter coefficients. To do that, we |
| + // would probably need to find the pole, r, with largest magnitude and select some threshold, |
| + // eps, such that |r|^n < eps for all n >= N. N is then the tailTime for the filter. If the |
| + // the magnitude of r is greater than or equal to 1, the infinity is the right answer. (There is |
| + // no constraint on the IIR filter that it be stable.) |
| + return std::numeric_limits<double>::infinity(); |
| +} |
| + |
| +double IIRDSPKernel::latencyTime() const |
| +{ |
| + return 0; |
| +} |
| + |
| +} // blink |
|
tkent
2016/01/13 03:28:28
nit: blink -> namespace blink
Raymond Toy
2016/01/13 18:30:53
Done.
|