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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webaudio/BiquadDSPKernel.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/BiquadDSPKernel.cpp b/third_party/WebKit/Source/modules/webaudio/BiquadDSPKernel.cpp
index 85fda7fa1898fc7a6c5f5079703717a8078740c3..1b2c73d5712493fbc1ef9123c8e19e66270a9195 100644
--- a/third_party/WebKit/Source/modules/webaudio/BiquadDSPKernel.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/BiquadDSPKernel.cpp
@@ -31,13 +31,6 @@
namespace blink {
-// FIXME: As a recursive linear filter, depending on its parameters, a biquad
-// filter can have an infinite tailTime. In practice, Biquad filters do not
-// usually (except for very high resonance values) have a tailTime of longer
-// than approx. 200ms. This value could possibly be calculated based on the
-// settings of the Biquad.
-static const double kMaxBiquadDelayTime = 0.2;
-
void BiquadDSPKernel::UpdateCoefficientsIfNecessary(int frames_to_process) {
if (GetBiquadProcessor()->FilterCoefficientsDirty()) {
float cutoff_frequency[AudioUtilities::kRenderQuantumFrames];
@@ -121,6 +114,23 @@ void BiquadDSPKernel::UpdateCoefficients(int number_of_frames,
break;
}
}
+
+ UpdateTailTime(number_of_frames - 1);
+}
+
+void BiquadDSPKernel::UpdateTailTime(int coef_index) {
+ // A reasonable upper limit for the tail time. While it's easy to
+ // create biquad filters whose tail time can be much larger than
+ // this, limit the maximum to this value so that we don't keep such
+ // nodes alive "forever".
+ // TODO: What is a reasonable upper limit?
+ const double kMaxTailTime = 30;
+
+ double sample_rate = SampleRate();
+ double tail =
+ biquad_.TailFrame(coef_index, kMaxTailTime * sample_rate) / sample_rate;
+
+ tail_time_ = clampTo(tail, 0.0, kMaxTailTime);
}
void BiquadDSPKernel::Process(const float* source,
@@ -199,7 +209,7 @@ void BiquadDSPKernel::GetFrequencyResponse(int n_frequencies,
}
double BiquadDSPKernel::TailTime() const {
- return kMaxBiquadDelayTime;
+ return tail_time_;
}
double BiquadDSPKernel::LatencyTime() const {
« 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