box_sum

Function box_sum 

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

Raw variable-width box sum helper.

Computes a box-filter sum 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_sum(
        json!({ "key": "boxfilter", "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("boxfilter_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, WindowParam};
use serde_json::json;

// 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_sum(
        WindowParam::Dynamic(window_lfo),
        el::cycle(el::const_(440.0)),
    )
);

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