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

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

Issue 2862373002: Compute tail time from Biquad coefficients (Closed)
Patch Set: Initialize tail_time_ in constructor Created 3 years, 6 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 /* 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 13 matching lines...) Expand all
24 */ 24 */
25 25
26 #include "modules/webaudio/BiquadDSPKernel.h" 26 #include "modules/webaudio/BiquadDSPKernel.h"
27 #include <limits.h> 27 #include <limits.h>
28 #include "platform/audio/AudioUtilities.h" 28 #include "platform/audio/AudioUtilities.h"
29 #include "platform/wtf/MathExtras.h" 29 #include "platform/wtf/MathExtras.h"
30 #include "platform/wtf/Vector.h" 30 #include "platform/wtf/Vector.h"
31 31
32 namespace blink { 32 namespace blink {
33 33
34 // FIXME: As a recursive linear filter, depending on its parameters, a biquad
35 // filter can have an infinite tailTime. In practice, Biquad filters do not
36 // usually (except for very high resonance values) have a tailTime of longer
37 // than approx. 200ms. This value could possibly be calculated based on the
38 // settings of the Biquad.
39 static const double kMaxBiquadDelayTime = 0.2;
40
41 void BiquadDSPKernel::UpdateCoefficientsIfNecessary(int frames_to_process) { 34 void BiquadDSPKernel::UpdateCoefficientsIfNecessary(int frames_to_process) {
42 if (GetBiquadProcessor()->FilterCoefficientsDirty()) { 35 if (GetBiquadProcessor()->FilterCoefficientsDirty()) {
43 float cutoff_frequency[AudioUtilities::kRenderQuantumFrames]; 36 float cutoff_frequency[AudioUtilities::kRenderQuantumFrames];
44 float q[AudioUtilities::kRenderQuantumFrames]; 37 float q[AudioUtilities::kRenderQuantumFrames];
45 float gain[AudioUtilities::kRenderQuantumFrames]; 38 float gain[AudioUtilities::kRenderQuantumFrames];
46 float detune[AudioUtilities::kRenderQuantumFrames]; // in Cents 39 float detune[AudioUtilities::kRenderQuantumFrames]; // in Cents
47 40
48 SECURITY_CHECK(static_cast<unsigned>(frames_to_process) <= 41 SECURITY_CHECK(static_cast<unsigned>(frames_to_process) <=
49 AudioUtilities::kRenderQuantumFrames); 42 AudioUtilities::kRenderQuantumFrames);
50 43
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 107
115 case BiquadProcessor::kNotch: 108 case BiquadProcessor::kNotch:
116 biquad_.SetNotchParams(k, normalized_frequency, q[k]); 109 biquad_.SetNotchParams(k, normalized_frequency, q[k]);
117 break; 110 break;
118 111
119 case BiquadProcessor::kAllpass: 112 case BiquadProcessor::kAllpass:
120 biquad_.SetAllpassParams(k, normalized_frequency, q[k]); 113 biquad_.SetAllpassParams(k, normalized_frequency, q[k]);
121 break; 114 break;
122 } 115 }
123 } 116 }
117
118 UpdateTailTime(number_of_frames - 1);
119 }
120
121 void BiquadDSPKernel::UpdateTailTime(int coef_index) {
122 // A reasonable upper limit for the tail time. While it's easy to
123 // create biquad filters whose tail time can be much larger than
124 // this, limit the maximum to this value so that we don't keep such
125 // nodes alive "forever".
126 // TODO: What is a reasonable upper limit?
127 const double kMaxTailTime = 30;
128
129 double sample_rate = SampleRate();
130 double tail =
131 biquad_.TailFrame(coef_index, kMaxTailTime * sample_rate) / sample_rate;
132
133 tail_time_ = clampTo(tail, 0.0, kMaxTailTime);
124 } 134 }
125 135
126 void BiquadDSPKernel::Process(const float* source, 136 void BiquadDSPKernel::Process(const float* source,
127 float* destination, 137 float* destination,
128 size_t frames_to_process) { 138 size_t frames_to_process) {
129 DCHECK(source); 139 DCHECK(source);
130 DCHECK(destination); 140 DCHECK(destination);
131 DCHECK(GetBiquadProcessor()); 141 DCHECK(GetBiquadProcessor());
132 142
133 // Recompute filter coefficients if any of the parameters have changed. 143 // Recompute filter coefficients if any of the parameters have changed.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 detune = GetBiquadProcessor()->Parameter4().Value(); 202 detune = GetBiquadProcessor()->Parameter4().Value();
193 } 203 }
194 204
195 UpdateCoefficients(1, &cutoff_frequency, &q, &gain, &detune); 205 UpdateCoefficients(1, &cutoff_frequency, &q, &gain, &detune);
196 206
197 biquad_.GetFrequencyResponse(n_frequencies, frequency.data(), mag_response, 207 biquad_.GetFrequencyResponse(n_frequencies, frequency.data(), mag_response,
198 phase_response); 208 phase_response);
199 } 209 }
200 210
201 double BiquadDSPKernel::TailTime() const { 211 double BiquadDSPKernel::TailTime() const {
202 return kMaxBiquadDelayTime; 212 return tail_time_;
203 } 213 }
204 214
205 double BiquadDSPKernel::LatencyTime() const { 215 double BiquadDSPKernel::LatencyTime() const {
206 return 0; 216 return 0;
207 } 217 }
208 218
209 } // namespace blink 219 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/BiquadDSPKernel.h ('k') | third_party/WebKit/Source/platform/audio/Biquad.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698