use aether_core::{
command::Command,
node::DspNode,
param::{Param, ParamBlock},
scheduler::Scheduler,
BUFFER_SIZE, MAX_INPUTS,
};
use ringbuf::{traits::*, HeapRb};
use std::thread;
use std::time::Duration;
struct Gain {
gain: f32,
}
impl DspNode for Gain {
fn process(
&mut self,
inputs: &[Option<&[f32; BUFFER_SIZE]>; MAX_INPUTS],
output: &mut [f32; BUFFER_SIZE],
params: &mut ParamBlock,
_sample_rate: f32,
) {
let silence = [0.0f32; BUFFER_SIZE];
let input = inputs[0].unwrap_or(&silence);
for (i, out) in output.iter_mut().enumerate() {
let gain_param = params.get(0);
*out = input[i] * gain_param.current;
params.tick_all(); }
}
fn type_name(&self) -> &'static str {
"Gain"
}
}
fn main() {
println!("AetherDSP Core - Command Ring Example");
println!("======================================\n");
let (mut producer, mut consumer) = HeapRb::<Command>::new(1024).split();
let mut sched = Scheduler::new(48_000.0);
let gain_id = sched
.graph
.add_node(Box::new(Gain { gain: 1.0 }))
.expect("Failed to add node");
sched.graph.set_output_node(gain_id);
println!("✓ Created scheduler with gain node");
println!("✓ Created command ring buffer (capacity: 1024)\n");
let control_thread = thread::spawn(move || {
println!("[Control Thread] Sending gain automation...\n");
for i in 0..=10 {
let gain_value = i as f32 / 10.0;
let cmd = Command::UpdateParam {
node: gain_id,
param_index: 0,
new_param: Param::new(gain_value),
};
if producer.try_push(cmd).is_ok() {
println!("[Control] Set gain = {:.1}", gain_value);
}
thread::sleep(Duration::from_millis(100));
}
println!("\n[Control Thread] Done sending commands");
});
println!("[RT Thread] Processing audio blocks...\n");
let mut output = vec![0.0f32; BUFFER_SIZE * 2];
for block in 0..15 {
sched.process_block(&mut consumer, &mut output);
thread::sleep(Duration::from_millis(80));
if block % 3 == 0 {
println!("[RT] Processed block {}", block);
}
}
control_thread.join().unwrap();
println!("\n✓ Success! Commands were safely sent from control → RT thread");
println!("✓ No locks, no allocations, no blocking");
}