box_average

Function box_average 

Source
pub fn box_average(
    window: impl Into<BoxAverageWindowInput>,
    x: impl Into<ElemNode>,
) -> Node
Expand description

Raw variable-width box average helper.

Computes a box-filter average over a configurable window length.

Supports two usage patterns:

  1. Static window with keying (for fast-path parameter updates): Pass props with window and key. The window can be updated via mounted.node_with_key("{key}_window") without rebuilding the graph.

  2. Dynamic window signal (for sample-rate modulation): Pass a signal node as the window parameter for runtime sample-rate control. No keying is available in this mode.

§Example: Keyed static window with fast-path updates

use elemaudio_rs::{Graph, el, extra};
use serde_json::json;

let graph = Graph::new().render(
    extra::box_average(
        json!({ "key": "boxavg", "window": 256.0 }),
        el::cycle(el::const_(440.0)),
    )
);

let mounted = graph.mount();
let batch = mounted.into_batch();
runtime.execute(&batch);

// Later, update window size without rebuilding the graph
if let Some(window_node) = mounted.node_with_key("boxavg_window") {
    let update = window_node.set_const_value(512.0);
    runtime.execute(&update);
}

§Example: Dynamic signal window for sample-rate modulation

use elemaudio_rs::{Graph, el, extra};

// Window size modulated by an LFO at sample rate
let window_lfo = el::mul((
    el::add([el::const_(256.0), el::const_(128.0)]),
    el::cycle(el::const_(0.5)),  // 0.5 Hz LFO
));

let graph = Graph::new().render(
    extra::box_average(
        window_lfo,
        el::white(),
    )
);

let mounted = graph.mount();
runtime.execute(&mounted.into_batch());