pub mod node;
pub mod param;
pub mod registry;
pub mod schema;
pub use aether_ndk_macro::aether_node;
pub use aether_core::{
node::DspNode,
param::ParamBlock,
state::StateBlob,
BUFFER_SIZE, MAX_INPUTS,
};
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ParamDef {
pub name: &'static str,
pub min: f32,
pub max: f32,
pub default: f32,
}
pub trait AetherNodeMeta {
fn type_name() -> &'static str;
fn param_defs() -> &'static [ParamDef];
}
pub trait DspProcess: Send {
fn process(
&mut self,
inputs: &NodeInputs,
output: &mut NodeOutput,
params: &mut ParamBlock,
sample_rate: f32,
);
fn capture_state(&self) -> StateBlob { StateBlob::EMPTY }
fn restore_state(&mut self, _state: StateBlob) {}
}
pub struct NodeInputs<'a> {
pub raw: &'a [Option<&'a [f32; BUFFER_SIZE]>; MAX_INPUTS],
}
impl<'a> NodeInputs<'a> {
pub fn get(&self, slot: usize) -> &[f32; BUFFER_SIZE] {
static SILENCE: [f32; BUFFER_SIZE] = [0.0f32; BUFFER_SIZE];
self.raw.get(slot).and_then(|s| *s).unwrap_or(&SILENCE)
}
}
pub type NodeOutput = [f32; BUFFER_SIZE];
pub struct NodeAdapter<T: DspProcess + AetherNodeMeta> {
pub inner: T,
}
impl<T: DspProcess + AetherNodeMeta + 'static> DspNode for NodeAdapter<T> {
fn process(
&mut self,
inputs: &[Option<&[f32; BUFFER_SIZE]>; MAX_INPUTS],
output: &mut [f32; BUFFER_SIZE],
params: &mut ParamBlock,
sample_rate: f32,
) {
let wrapped = NodeInputs { raw: inputs };
self.inner.process(&wrapped, output, params, sample_rate);
}
fn capture_state(&self) -> StateBlob { self.inner.capture_state() }
fn restore_state(&mut self, state: StateBlob) { self.inner.restore_state(state); }
fn type_name(&self) -> &'static str { T::type_name() }
}
pub fn into_node<T>(node: T) -> Box<dyn DspNode>
where
T: DspProcess + AetherNodeMeta + 'static,
{
Box::new(NodeAdapter { inner: node })
}
pub mod prelude {
pub use super::{
aether_node, into_node, AetherNodeMeta, DspProcess, NodeInputs,
NodeOutput, ParamDef,
};
pub use aether_core::param::ParamBlock;
pub use aether_core::state::StateBlob;
pub use aether_core::{BUFFER_SIZE, MAX_INPUTS};
}