+ -- Parameter smoothing: we want to filter out parameter changes that are
+ -- faster than 15Hz, and interpolate between parameter values.
+ -- For performance reasons, we want to ensure that two consecutive values
+ -- of the interpolated "steepness" are less that 1 apart. By choosing the
+ -- interpolation chunk size to be 64 in most cases, but 32 if the rate is
+ -- strictly less than 16kHz (there's only 8kHz in standard rates), we can
+ -- ensure that steepness interpolation will never change the parameter by
+ -- more than ~0.82.
+ lpf_chunk = 64
+ if rate < 16000 then lpf_chunk = 32 end
+ -- We apply a discrete version of the standard RC low-pass, with a cutoff
+ -- frequency of 15Hz. For more information about the underlying math, see
+ -- https://en.wikipedia.org/wiki/Low-pass_filter#Discrete-time_realization
+ -- (here Δt is lpf_chunk / rate)
+ local R = 2 * math.pi * lpf_chunk * 15 -- Hz
+ lpf = R / (R + rate)