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/IIRDSPKernel.h" | 5 #include "modules/webaudio/IIRDSPKernel.h" |
6 | 6 |
7 #include "platform/wtf/MathExtras.h" | 7 #include "platform/wtf/MathExtras.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
11 IIRDSPKernel::IIRDSPKernel(IIRProcessor* processor) | |
12 : AudioDSPKernel(processor), | |
13 iir_(processor->Feedforward(), processor->Feedback()) { | |
14 tail_time_ = iir_.TailTime(processor->SampleRate()); | |
hongchan
2017/05/12 16:24:04
Is this the only moment that the tail time is comp
Raymond Toy
2017/05/12 17:33:18
Since the filter can't change, we only need to com
| |
15 } | |
16 | |
11 void IIRDSPKernel::Process(const float* source, | 17 void IIRDSPKernel::Process(const float* source, |
12 float* destination, | 18 float* destination, |
13 size_t frames_to_process) { | 19 size_t frames_to_process) { |
14 DCHECK(source); | 20 DCHECK(source); |
15 DCHECK(destination); | 21 DCHECK(destination); |
16 | 22 |
17 iir_.Process(source, destination, frames_to_process); | 23 iir_.Process(source, destination, frames_to_process); |
18 } | 24 } |
19 | 25 |
20 void IIRDSPKernel::GetFrequencyResponse(int n_frequencies, | 26 void IIRDSPKernel::GetFrequencyResponse(int n_frequencies, |
(...skipping 13 matching lines...) Expand all Loading... | |
34 // Convert from frequency in Hz to normalized frequency (0 -> 1), | 40 // Convert from frequency in Hz to normalized frequency (0 -> 1), |
35 // with 1 equal to the Nyquist frequency. | 41 // with 1 equal to the Nyquist frequency. |
36 for (int k = 0; k < n_frequencies; ++k) | 42 for (int k = 0; k < n_frequencies; ++k) |
37 frequency[k] = clampTo<float>(frequency_hz[k] / nyquist); | 43 frequency[k] = clampTo<float>(frequency_hz[k] / nyquist); |
38 | 44 |
39 iir_.GetFrequencyResponse(n_frequencies, frequency.data(), mag_response, | 45 iir_.GetFrequencyResponse(n_frequencies, frequency.data(), mag_response, |
40 phase_response); | 46 phase_response); |
41 } | 47 } |
42 | 48 |
43 double IIRDSPKernel::TailTime() const { | 49 double IIRDSPKernel::TailTime() const { |
44 // TODO(rtoy): This is true mathematically (infinite impulse response), but | 50 return tail_time_; |
45 // perhaps it should be limited to a smaller value, possibly based on the | |
46 // actual filter coefficients. To do that, we would probably need to find the | |
47 // pole, r, with largest magnitude and select some threshold, eps, such that | |
48 // |r|^n < eps for all n >= N. N is then the tailTime for the filter. If the | |
49 // the magnitude of r is greater than or equal to 1, the infinity is the right | |
50 // answer. (There is no constraint on the IIR filter that it be stable.) | |
51 return std::numeric_limits<double>::infinity(); | |
52 } | 51 } |
53 | 52 |
54 double IIRDSPKernel::LatencyTime() const { | 53 double IIRDSPKernel::LatencyTime() const { |
55 return 0; | 54 return 0; |
56 } | 55 } |
57 | 56 |
58 } // namespace blink | 57 } // namespace blink |
OLD | NEW |