OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 20 matching lines...) Expand all Loading... |
31 namespace blink { | 31 namespace blink { |
32 | 32 |
33 // FIXME: As a recursive linear filter, depending on its parameters, a biquad fi
lter can have | 33 // FIXME: As a recursive linear filter, depending on its parameters, a biquad fi
lter can have |
34 // an infinite tailTime. In practice, Biquad filters do not usually (except for
very high resonance values) | 34 // an infinite tailTime. In practice, Biquad filters do not usually (except for
very high resonance values) |
35 // have a tailTime of longer than approx. 200ms. This value could possibly be ca
lculated based on the | 35 // have a tailTime of longer than approx. 200ms. This value could possibly be ca
lculated based on the |
36 // settings of the Biquad. | 36 // settings of the Biquad. |
37 static const double MaxBiquadDelayTime = 0.2; | 37 static const double MaxBiquadDelayTime = 0.2; |
38 | 38 |
39 void BiquadDSPKernel::updateCoefficientsIfNecessary(int framesToProcess) | 39 void BiquadDSPKernel::updateCoefficientsIfNecessary(int framesToProcess) |
40 { | 40 { |
41 if (biquadProcessor()->filterCoefficientsDirty()) { | 41 if (getBiquadProcessor()->filterCoefficientsDirty()) { |
42 float cutoffFrequency[AudioUtilities::kRenderQuantumFrames]; | 42 float cutoffFrequency[AudioUtilities::kRenderQuantumFrames]; |
43 float Q[AudioUtilities::kRenderQuantumFrames]; | 43 float Q[AudioUtilities::kRenderQuantumFrames]; |
44 float gain[AudioUtilities::kRenderQuantumFrames]; | 44 float gain[AudioUtilities::kRenderQuantumFrames]; |
45 float detune[AudioUtilities::kRenderQuantumFrames]; // in Cents | 45 float detune[AudioUtilities::kRenderQuantumFrames]; // in Cents |
46 | 46 |
47 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION( | 47 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION( |
48 static_cast<unsigned>(framesToProcess) <= AudioUtilities::kRenderQua
ntumFrames); | 48 static_cast<unsigned>(framesToProcess) <= AudioUtilities::kRenderQua
ntumFrames); |
49 | 49 |
50 if (biquadProcessor()->hasSampleAccurateValues()) { | 50 if (getBiquadProcessor()->hasSampleAccurateValues()) { |
51 biquadProcessor()->parameter1().calculateSampleAccurateValues(cutoff
Frequency, framesToProcess); | 51 getBiquadProcessor()->parameter1().calculateSampleAccurateValues(cut
offFrequency, framesToProcess); |
52 biquadProcessor()->parameter2().calculateSampleAccurateValues(Q, fra
mesToProcess); | 52 getBiquadProcessor()->parameter2().calculateSampleAccurateValues(Q,
framesToProcess); |
53 biquadProcessor()->parameter3().calculateSampleAccurateValues(gain,
framesToProcess); | 53 getBiquadProcessor()->parameter3().calculateSampleAccurateValues(gai
n, framesToProcess); |
54 biquadProcessor()->parameter4().calculateSampleAccurateValues(detune
, framesToProcess); | 54 getBiquadProcessor()->parameter4().calculateSampleAccurateValues(det
une, framesToProcess); |
55 updateCoefficients(framesToProcess, cutoffFrequency, Q, gain, detune
); | 55 updateCoefficients(framesToProcess, cutoffFrequency, Q, gain, detune
); |
56 } else { | 56 } else { |
57 cutoffFrequency[0] = biquadProcessor()->parameter1().smoothedValue()
; | 57 cutoffFrequency[0] = getBiquadProcessor()->parameter1().smoothedValu
e(); |
58 Q[0] = biquadProcessor()->parameter2().smoothedValue(); | 58 Q[0] = getBiquadProcessor()->parameter2().smoothedValue(); |
59 gain[0] = biquadProcessor()->parameter3().smoothedValue(); | 59 gain[0] = getBiquadProcessor()->parameter3().smoothedValue(); |
60 detune[0] = biquadProcessor()->parameter4().smoothedValue(); | 60 detune[0] = getBiquadProcessor()->parameter4().smoothedValue(); |
61 updateCoefficients(1, cutoffFrequency, Q, gain, detune); | 61 updateCoefficients(1, cutoffFrequency, Q, gain, detune); |
62 } | 62 } |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 void BiquadDSPKernel::updateCoefficients(int numberOfFrames, const float* cutoff
Frequency, const float* Q, const float* gain, const float* detune) | 66 void BiquadDSPKernel::updateCoefficients(int numberOfFrames, const float* cutoff
Frequency, const float* Q, const float* gain, const float* detune) |
67 { | 67 { |
68 // Convert from Hertz to normalized frequency 0 -> 1. | 68 // Convert from Hertz to normalized frequency 0 -> 1. |
69 double nyquist = this->nyquist(); | 69 double nyquist = this->nyquist(); |
70 | 70 |
71 m_biquad.setHasSampleAccurateValues(numberOfFrames > 1); | 71 m_biquad.setHasSampleAccurateValues(numberOfFrames > 1); |
72 | 72 |
73 for (int k = 0; k < numberOfFrames; ++k) { | 73 for (int k = 0; k < numberOfFrames; ++k) { |
74 double normalizedFrequency = cutoffFrequency[k] / nyquist; | 74 double normalizedFrequency = cutoffFrequency[k] / nyquist; |
75 | 75 |
76 // Offset frequency by detune. | 76 // Offset frequency by detune. |
77 if (detune[k]) | 77 if (detune[k]) |
78 normalizedFrequency *= pow(2, detune[k] / 1200); | 78 normalizedFrequency *= pow(2, detune[k] / 1200); |
79 | 79 |
80 // Configure the biquad with the new filter parameters for the appropria
te type of filter. | 80 // Configure the biquad with the new filter parameters for the appropria
te type of filter. |
81 switch (biquadProcessor()->type()) { | 81 switch (getBiquadProcessor()->type()) { |
82 case BiquadProcessor::LowPass: | 82 case BiquadProcessor::LowPass: |
83 m_biquad.setLowpassParams(k, normalizedFrequency, Q[k]); | 83 m_biquad.setLowpassParams(k, normalizedFrequency, Q[k]); |
84 break; | 84 break; |
85 | 85 |
86 case BiquadProcessor::HighPass: | 86 case BiquadProcessor::HighPass: |
87 m_biquad.setHighpassParams(k, normalizedFrequency, Q[k]); | 87 m_biquad.setHighpassParams(k, normalizedFrequency, Q[k]); |
88 break; | 88 break; |
89 | 89 |
90 case BiquadProcessor::BandPass: | 90 case BiquadProcessor::BandPass: |
91 m_biquad.setBandpassParams(k, normalizedFrequency, Q[k]); | 91 m_biquad.setBandpassParams(k, normalizedFrequency, Q[k]); |
(...skipping 19 matching lines...) Expand all Loading... |
111 m_biquad.setAllpassParams(k, normalizedFrequency, Q[k]); | 111 m_biquad.setAllpassParams(k, normalizedFrequency, Q[k]); |
112 break; | 112 break; |
113 } | 113 } |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 void BiquadDSPKernel::process(const float* source, float* destination, size_t fr
amesToProcess) | 117 void BiquadDSPKernel::process(const float* source, float* destination, size_t fr
amesToProcess) |
118 { | 118 { |
119 ASSERT(source); | 119 ASSERT(source); |
120 ASSERT(destination); | 120 ASSERT(destination); |
121 ASSERT(biquadProcessor()); | 121 ASSERT(getBiquadProcessor()); |
122 | 122 |
123 // Recompute filter coefficients if any of the parameters have changed. | 123 // Recompute filter coefficients if any of the parameters have changed. |
124 // FIXME: as an optimization, implement a way that a Biquad object can simpl
y copy its internal filter coefficients from another Biquad object. | 124 // FIXME: as an optimization, implement a way that a Biquad object can simpl
y copy its internal filter coefficients from another Biquad object. |
125 // Then re-factor this code to only run for the first BiquadDSPKernel of eac
h BiquadProcessor. | 125 // Then re-factor this code to only run for the first BiquadDSPKernel of eac
h BiquadProcessor. |
126 | 126 |
127 | 127 |
128 // The audio thread can't block on this lock; skip updating the coefficients
for this block if | 128 // The audio thread can't block on this lock; skip updating the coefficients
for this block if |
129 // necessary. We'll get them the next time around. | 129 // necessary. We'll get them the next time around. |
130 { | 130 { |
131 MutexTryLocker tryLocker(m_processLock); | 131 MutexTryLocker tryLocker(m_processLock); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // | 165 // |
166 // The BiquadDSPKernel object here (along with it's Biquad object) is fo
r querying the | 166 // The BiquadDSPKernel object here (along with it's Biquad object) is fo
r querying the |
167 // frequency response and is NOT the same as the one in process() which
is used for | 167 // frequency response and is NOT the same as the one in process() which
is used for |
168 // performing the actual filtering. This one is is created in | 168 // performing the actual filtering. This one is is created in |
169 // BiquadProcessor::getFrequencyResponse for this purpose. Both, however
, point to the same | 169 // BiquadProcessor::getFrequencyResponse for this purpose. Both, however
, point to the same |
170 // BiquadProcessor object. | 170 // BiquadProcessor object. |
171 // | 171 // |
172 // FIXME: Simplify this: crbug.com/390266 | 172 // FIXME: Simplify this: crbug.com/390266 |
173 MutexLocker processLocker(m_processLock); | 173 MutexLocker processLocker(m_processLock); |
174 | 174 |
175 cutoffFrequency = biquadProcessor()->parameter1().value(); | 175 cutoffFrequency = getBiquadProcessor()->parameter1().value(); |
176 Q = biquadProcessor()->parameter2().value(); | 176 Q = getBiquadProcessor()->parameter2().value(); |
177 gain = biquadProcessor()->parameter3().value(); | 177 gain = getBiquadProcessor()->parameter3().value(); |
178 detune = biquadProcessor()->parameter4().value(); | 178 detune = getBiquadProcessor()->parameter4().value(); |
179 } | 179 } |
180 | 180 |
181 updateCoefficients(1, &cutoffFrequency, &Q, &gain, &detune); | 181 updateCoefficients(1, &cutoffFrequency, &Q, &gain, &detune); |
182 | 182 |
183 m_biquad.getFrequencyResponse(nFrequencies, frequency.data(), magResponse, p
haseResponse); | 183 m_biquad.getFrequencyResponse(nFrequencies, frequency.data(), magResponse, p
haseResponse); |
184 } | 184 } |
185 | 185 |
186 double BiquadDSPKernel::tailTime() const | 186 double BiquadDSPKernel::tailTime() const |
187 { | 187 { |
188 return MaxBiquadDelayTime; | 188 return MaxBiquadDelayTime; |
189 } | 189 } |
190 | 190 |
191 double BiquadDSPKernel::latencyTime() const | 191 double BiquadDSPKernel::latencyTime() const |
192 { | 192 { |
193 return 0; | 193 return 0; |
194 } | 194 } |
195 | 195 |
196 } // namespace blink | 196 } // namespace blink |
197 | 197 |
OLD | NEW |