Class: MovingAverage

MovingAverage

Compute a moving average operation on the incomming frames (scalar or vector type). If the input is of type vector, the moving average is computed for each dimension in parallel. If the source sample rate is defined frame time is shifted to the middle of the window defined by the order.

support standalone usage

Constructor

new MovingAverage(options)

Parameters:
Name Type Description
options Object

Override default parameters.

Properties
Name Type Attributes Default Description
order Number <optional>
10

Number of successive values on which the average is computed.

fill Number <optional>
0

Value to fill the ring buffer with before the first input frame.

Source:
To Do:
  • - Implement `processSignal` ?
Example
import * as lfo from 'waves-lfo/common';

const eventIn = new lfo.source.EventIn({
  frameSize: 2,
  frameType: 'vector'
});

const movingAverage = new lfo.operator.MovingAverage({
  order: 5,
  fill: 0
});

const logger = new lfo.sink.Logger({ data: true });

eventIn.connect(movingAverage);
movingAverage.connect(logger);

eventIn.start();

eventIn.process(null, [1, 1]);
> [0.2, 0.2]
eventIn.process(null, [1, 1]);
> [0.4, 0.4]
eventIn.process(null, [1, 1]);
> [0.6, 0.6]
eventIn.process(null, [1, 1]);
> [0.8, 0.8]
eventIn.process(null, [1, 1]);
> [1, 1]

Methods

inputScalar(value) → {Number}

Use the MovingAverage operator in standalone mode (i.e. outside of a graph) with a scalar input.

Parameters:
Name Type Description
value Number

Value to feed the moving average with.

Source:
Returns:
  • Average value.
Type
Number
Example
import * as lfo from 'waves-lfo/client';

const movingAverage = new lfo.operator.MovingAverage({ order: 5 });
movingAverage.initStream({ frameSize: 1, frameType: 'scalar' });

movingAverage.inputScalar(1);
> 0.2
movingAverage.inputScalar(1);
> 0.4
movingAverage.inputScalar(1);
> 0.6

inputVector(values) → {Float32Array}

Use the MovingAverage operator in standalone mode (i.e. outside of a graph) with a vector input.

Parameters:
Name Type Description
values Array

Values to feed the moving average with.

Source:
Returns:
  • Average value for each dimension.
Type
Float32Array
Example
import * as lfo from 'waves-lfo/client';

const movingAverage = new lfo.operator.MovingAverage({ order: 5 });
movingAverage.initStream({ frameSize: 2, frameType: 'scalar' });

movingAverage.inputArray([1, 1]);
> [0.2, 0.2]
movingAverage.inputArray([1, 1]);
> [0.4, 0.4]
movingAverage.inputArray([1, 1]);
> [0.6, 0.6]