Skip to main content

Crate weirdnet_audio_plugin

Crate weirdnet_audio_plugin 

Source
Expand description

Audio plugins: a plugin takes a weirdnet_media::waveform::Waveform and typed parameters and returns a new waveform or an error.

  • Plugin and ParamSpec: what a plugin is and which parameters it takes (kind, range, default, unit).
  • ParamValues: the values for one use of a plugin. ParamSpecs validate and resolve them (defaults filled in, unknown names and out-of-range values rejected), so a plugin only ever sees complete, valid values.
  • Registry: plugins by id. Registry::with_builtins has weirdnet.gain, weirdnet.levels, weirdnet.frequencies and weirdnet.duration.
  • apply_chain: runs PluginInstances in order; the error says which step failed. chain_cache_key is the BLAKE3 key a cache uses for the result: source content, plugin ids and versions, resolved parameter values; bypassed steps do not count.
use weirdnet_audio_plugin::{ParamValues, PluginInstance, Registry, apply_chain, chain_cache_key, waveform_hash};
use weirdnet_media::waveform::Waveform;

let registry = Registry::with_builtins();
let input = Waveform::tone(48_000, 440.0, 4_800, 0.5)?;
let chain = [
    PluginInstance::new("weirdnet.frequencies", ParamValues::new().with_choice("type", "low").with_float("cutoff_hz", 800.0)),
    PluginInstance::new("weirdnet.gain", ParamValues::new().with_float("gain_db", -6.0)),
];
let output = apply_chain(&registry, &input, &chain)?;
let cache_key = chain_cache_key(&registry, &waveform_hash(&input), &chain)?;
assert_eq!(output.frames(), input.frames());
assert_eq!(cache_key.len(), 32);

Every built-in’s defaults are an identity, so a freshly added plugin changes nothing until a parameter moves. Hosting third-party plugin formats is out of scope.

Modules§

builtin
The built-in plugins. Each one’s default values leave in-range audio unchanged.

Structs§

ParamSpec
A parameter a plugin takes.
ParamValues
Values for one use of a plugin, by parameter name. Missing names mean the default.
PluginInstance
One use of a plugin in a chain.
Registry
Plugins by id.

Enums§

ChainError
Why a chain failed, and where.
ParamKind
The type of a parameter.
ParamValue
One parameter’s value.
PluginError
Why a plugin could not process a waveform.

Traits§

Plugin
An audio effect. Implementations are pure: the same input and values give the same output, which is what lets results be cached.

Functions§

apply_chain
Runs chain over input, in order, skipping bypassed instances. An empty chain returns a clone of the input.
chain_cache_key
The key a cache uses for “source through chain”.
waveform_hash
The BLAKE3 hash of a waveform’s content (sample rate, channels and every sample’s bits). Use it as the source of chain_cache_key for audio that has no content hash of its own.