Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/IIRDSPKernel.cpp

Issue 2342913003: Replace narrowPrecisionToFloat with clampTo<float> (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/FloatConversion.h" 7 #include "wtf/MathExtras.h"
8 8
9 namespace blink { 9 namespace blink {
10 10
11 void IIRDSPKernel::process(const float* source, float* destination, size_t frame sToProcess) 11 void IIRDSPKernel::process(const float* source, float* destination, size_t frame sToProcess)
12 { 12 {
13 DCHECK(source); 13 DCHECK(source);
14 DCHECK(destination); 14 DCHECK(destination);
15 15
16 m_iir.process(source, destination, framesToProcess); 16 m_iir.process(source, destination, framesToProcess);
17 } 17 }
18 18
19 void IIRDSPKernel::getFrequencyResponse(int nFrequencies, const float* frequency Hz, float* magResponse, float* phaseResponse) 19 void IIRDSPKernel::getFrequencyResponse(int nFrequencies, const float* frequency Hz, float* magResponse, float* phaseResponse)
20 { 20 {
21 bool isGood = nFrequencies > 0 && frequencyHz && magResponse && phaseRespons e; 21 bool isGood = nFrequencies > 0 && frequencyHz && magResponse && phaseRespons e;
22 DCHECK(isGood); 22 DCHECK(isGood);
23 if (!isGood) 23 if (!isGood)
24 return; 24 return;
25 25
26 Vector<float> frequency(nFrequencies); 26 Vector<float> frequency(nFrequencies);
27 27
28 double nyquist = this->nyquist(); 28 double nyquist = this->nyquist();
29 29
30 // Convert from frequency in Hz to normalized frequency (0 -> 1), 30 // Convert from frequency in Hz to normalized frequency (0 -> 1),
31 // with 1 equal to the Nyquist frequency. 31 // with 1 equal to the Nyquist frequency.
32 for (int k = 0; k < nFrequencies; ++k) 32 for (int k = 0; k < nFrequencies; ++k)
33 frequency[k] = narrowPrecisionToFloat(frequencyHz[k] / nyquist); 33 frequency[k] = clampTo<float>(frequencyHz[k] / nyquist);
34 34
35 m_iir.getFrequencyResponse(nFrequencies, frequency.data(), magResponse, phas eResponse); 35 m_iir.getFrequencyResponse(nFrequencies, frequency.data(), magResponse, phas eResponse);
36 } 36 }
37 37
38 double IIRDSPKernel::tailTime() const 38 double IIRDSPKernel::tailTime() const
39 { 39 {
40 // TODO(rtoy): This is true mathematically (infinite impulse response), but perhaps it should be 40 // TODO(rtoy): This is true mathematically (infinite impulse response), but perhaps it should be
41 // limited to a smaller value, possibly based on the actual filter coefficie nts. To do that, we 41 // limited to a smaller value, possibly based on the actual filter coefficie nts. To do that, we
42 // would probably need to find the pole, r, with largest magnitude and selec t some threshold, 42 // would probably need to find the pole, r, with largest magnitude and selec t some threshold,
43 // eps, such that |r|^n < eps for all n >= N. N is then the tailTime for th e filter. If the 43 // eps, such that |r|^n < eps for all n >= N. N is then the tailTime for th e filter. If the
44 // the magnitude of r is greater than or equal to 1, the infinity is the rig ht answer. (There is 44 // the magnitude of r is greater than or equal to 1, the infinity is the rig ht answer. (There is
45 // no constraint on the IIR filter that it be stable.) 45 // no constraint on the IIR filter that it be stable.)
46 return std::numeric_limits<double>::infinity(); 46 return std::numeric_limits<double>::infinity();
47 } 47 }
48 48
49 double IIRDSPKernel::latencyTime() const 49 double IIRDSPKernel::latencyTime() const
50 { 50 {
51 return 0; 51 return 0;
52 } 52 }
53 53
54 } // namespace blink 54 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/BiquadDSPKernel.cpp ('k') | third_party/WebKit/Source/platform/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698