Commit e060b7d8 authored by Raymond Toy's avatar Raymond Toy Committed by Commit Bot

Document the discrete time constant formula

Add comments to show how to get the discrete time constant value for
the formula for setTargetAtTime.

No code changes at all.

Change-Id: I6af196475671e030c665e5a968c18579bc8f7e83
Reviewed-on: https://chromium-review.googlesource.com/940455Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Commit-Queue: Raymond Toy <rtoy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539922}
parent 5b066b1e
...@@ -43,6 +43,26 @@ float LinearToDecibels(float linear) { ...@@ -43,6 +43,26 @@ float LinearToDecibels(float linear) {
double DiscreteTimeConstantForSampleRate(double time_constant, double DiscreteTimeConstantForSampleRate(double time_constant,
double sample_rate) { double sample_rate) {
// From the WebAudio spec, the formula for setTargetAtTime is
//
// v(t) = V1 + (V0 - V1)*exp(-t/tau)
//
// where tau is the time constant, V1 is the target value and V0 is
// the starting value.
//
// Rewrite this as
//
// v(t) = V0 + (V1 - V0)*(1-exp(-t/tau))
//
// The implementation of setTargetAtTime uses this form. So at the
// sample points, we have
//
// v(n/Fs) = V0 + (V1 - V0)*(1-exp(-n/(Fs*tau)))
//
// where Fs is the sample rate of the sampled systme. Thus, the
// discrete time constant is
//
// 1 - exp(-1/(Fs*tau)
return 1 - exp(-1 / (sample_rate * time_constant)); return 1 - exp(-1 / (sample_rate * time_constant));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment