use sound_stream::{Amplitude, Sample, Settings};
use std::num::Float;
pub type Volume = Amplitude;
pub type Panning = f32;
pub trait Node<S> where S: Sample {
#[inline]
fn vol(&self) -> Volume { 1.0 }
#[inline]
fn pan(&self) -> Panning { 0.0 }
#[inline]
fn inputs(&mut self) -> Vec<&mut Node<S>> { Vec::new() }
#[inline]
fn vol_per_channel(&self) -> [Amplitude; 2] {
if self.pan() >= 0.0 {
[self.vol() * (self.pan() - 1.0).abs(), self.vol()]
} else {
[self.vol(), self.vol() * (self.pan() + 1.0)]
}
}
#[inline]
fn audio_requested(&mut self, output: &mut [S], settings: Settings) {
let frames = settings.frames as usize;
let channels = settings.channels as usize;
let buffer_size = frames * channels;
let vol_per_channel = self.vol_per_channel();
for input in self.inputs() {
let mut working = vec![Sample::zero(); buffer_size];
input.audio_requested(&mut working[..], settings);
Sample::add_buffers(output, &working[..], &vol_per_channel[..]);
}
self.process_buffer(output, settings);
}
#[inline]
fn process_buffer(&mut self, _output: &mut [S], _settings: Settings) {}
}