UNPKG

@svta/common-media-library

Version:
30 lines 843 B
import { getBandwidthBps } from '../utils/getBandwidthBps.js'; /** * Zero-Lag Exponential Moving Average (ZLEMA) throughput estimator * * @group Throughput * * @beta */ export class ZlemaEstimator { constructor() { this.samples = []; } sample(sample) { this.samples.push(sample); } getEstimate() { if (this.samples.length === 0) { return NaN; } const alpha = 2 / (this.samples.length + 1); let ema, zlema; ema = zlema = getBandwidthBps(this.samples[this.samples.length - 1]); for (let i = 0; i < this.samples.length; i++) { ema = alpha * getBandwidthBps(this.samples[i]) + (1 - alpha) * ema; zlema = alpha * ema + (1 - alpha) * zlema; } return zlema; } } //# sourceMappingURL=ZlemaEstimator.js.map