OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 |
| 7 #include "modules/webaudio/IIRDSPKernel.h" |
| 8 |
| 9 #include "platform/FloatConversion.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 void IIRDSPKernel::process(const float* source, float* destination, size_t frame
sToProcess) |
| 14 { |
| 15 ASSERT(source); |
| 16 ASSERT(destination); |
| 17 |
| 18 m_iir.process(source, destination, framesToProcess); |
| 19 } |
| 20 |
| 21 void IIRDSPKernel::getFrequencyResponse(int nFrequencies, const float* frequency
Hz, float* magResponse, float* phaseResponse) |
| 22 { |
| 23 bool isGood = nFrequencies > 0 && frequencyHz && magResponse && phaseRespons
e; |
| 24 ASSERT(isGood); |
| 25 if (!isGood) |
| 26 return; |
| 27 |
| 28 Vector<float> frequency(nFrequencies); |
| 29 |
| 30 double nyquist = this->nyquist(); |
| 31 |
| 32 // Convert from frequency in Hz to normalized frequency (0 -> 1), |
| 33 // with 1 equal to the Nyquist frequency. |
| 34 for (int k = 0; k < nFrequencies; ++k) |
| 35 frequency[k] = narrowPrecisionToFloat(frequencyHz[k] / nyquist); |
| 36 |
| 37 m_iir.getFrequencyResponse(nFrequencies, frequency.data(), magResponse, phas
eResponse); |
| 38 } |
| 39 |
| 40 double IIRDSPKernel::tailTime() const |
| 41 { |
| 42 // TODO(rtoy): This is true mathematically (infinite impulse response), but
perhaps it should be |
| 43 // limited to a smaller value, possibly based on the actual filter coefficie
nts. To do that, we |
| 44 // would probably need to find the pole, r, with largest magnitude and selec
t some threshold, |
| 45 // eps, such that |r|^n < eps for all n >= N. N is then the tailTime for th
e filter. If the |
| 46 // the magnitude of r is greater than or equal to 1, the infinity is the rig
ht answer. (There is |
| 47 // no constraint on the IIR filter that it be stable.) |
| 48 return std::numeric_limits<double>::infinity(); |
| 49 } |
| 50 |
| 51 double IIRDSPKernel::latencyTime() const |
| 52 { |
| 53 return 0; |
| 54 } |
| 55 |
| 56 } // blink |
OLD | NEW |