pub use crate::traits::{
Action,
ActionContext,
Algorithm,
AlgorithmCategory,
AlgorithmMetadata,
AudioNode,
ConnectionError,
ConnectionResult,
IntoParamValue,
NodeCategory,
NodeId,
NodeMetadata,
NodeParams,
NodeState,
NodeTypeId,
ParamMetadata,
ParamRange,
ParamType,
ParamValue,
ParameterError,
ParameterId,
ParameterResult,
Port,
PortDirection,
PortError,
PortId,
PortResult,
PortType,
ProcessError,
ProcessResult,
Processor,
Sink,
Source,
};
pub use crate::time::{ClockSource, ClockTick, SystemClock, TimeError, TimeResult};
pub use crate::interpolate::Interpolate;
pub use crate::math::Transcendental;
pub use crate::math::vector::math::{
abs_slice, clamp_slice, cos_slice, exp_slice, ln_slice,
max_slice, min_slice, sin_slice, sqrt_slice, tan_slice,
};
pub use crate::math::vector::ops::{
add_scalar_slice, add_slices, div_slices, mul_scalar_slice, mul_slices, sub_slices,
};
pub use crate::math::vector::scalar::{ScalarVector1, ScalarVector2, ScalarVector4, ScalarVector8};
#[cfg(feature = "simd")]
pub use crate::math::vector::simd::*;
pub use crate::math::vector::traits::{
Vector, VectorMask, VectorReduce, VectorScalarOps, VectorTranscendental,
};
pub use crate::buffer::{
utils,
AtomicCell,
AtomicCellError,
AtomicStats,
AudioBuffer,
Buffer,
BufferError,
BufferResult,
BufferStats,
DelayLine,
FanInBuffer,
FanOutBuffer,
PipeBuffer,
RingBuffer,
};
pub use crate::queues::{QueueError, QueueResult, TelemetryBlock};
pub use crate::{
CACHE_LINE_SIZE,
DEFAULT_BLOCK_SIZE,
DEFAULT_BUFFER_SIZE,
DEFAULT_SAMPLE_RATE,
MAX_BLOCK_SIZE,
MAX_BUFFER_SIZE,
MAX_SAMPLE_RATE,
MIN_BLOCK_SIZE,
MIN_BUFFER_SIZE,
MIN_SAMPLE_RATE,
VERSION,
};
pub type Sample = f32;
pub type MonoBlock<T, const N: usize> = [T; N];
pub type StereoBlock<T, const N: usize> = [MonoBlock<T, N>; 2];
pub type ControlValue<T> = T;
pub type DefaultPipeBuffer<const N: usize = DEFAULT_BLOCK_SIZE> = PipeBuffer<Sample, N>;
pub type DefaultDelayLine<const MAX_DELAY: usize> = DelayLine<Sample, MAX_DELAY>;
pub type DefaultRingBuffer<const N: usize> = RingBuffer<Sample, N>;
pub type DefaultClock = SystemClock;
pub mod f32_prelude {
use crate::buffer::{DelayLine, FanInBuffer, FanOutBuffer, PipeBuffer, RingBuffer};
pub type PipeBufferF32<const N: usize> = PipeBuffer<f32, N>;
pub type FanOutBufferF32<const N: usize, const CONSUMERS: usize> =
FanOutBuffer<f32, N, CONSUMERS>;
pub type FanInBufferF32<const N: usize, const PRODUCERS: usize> =
FanInBuffer<f32, N, PRODUCERS>;
pub type DelayLineF32<const MAX_DELAY: usize> = DelayLine<f32, MAX_DELAY>;
pub type RingBufferF32<const N: usize> = RingBuffer<f32, N>;
pub type SystemClockF32 = crate::time::SystemClock;
pub use crate::traits::{Processor as ProcessorF32, Sink as SinkF32, Source as SourceF32};
pub use crate::math::Transcendental;
}
pub mod f64_prelude {
use crate::buffer::{DelayLine, FanInBuffer, FanOutBuffer, PipeBuffer, RingBuffer};
pub type PipeBufferF64<const N: usize> = PipeBuffer<f64, N>;
pub type FanOutBufferF64<const N: usize, const CONSUMERS: usize> =
FanOutBuffer<f64, N, CONSUMERS>;
pub type FanInBufferF64<const N: usize, const PRODUCERS: usize> =
FanInBuffer<f64, N, PRODUCERS>;
pub type DelayLineF64<const MAX_DELAY: usize> = DelayLine<f64, MAX_DELAY>;
pub type RingBufferF64<const N: usize> = RingBuffer<f64, N>;
pub type SystemClockF64 = crate::time::SystemClock;
pub use crate::traits::{Processor as ProcessorF64, Sink as SinkF64, Source as SourceF64};
pub use crate::math::Transcendental;
}
pub mod time_prelude {
pub use crate::time::{ClockSource, ClockTick, SystemClock, TimeError, TimeResult};
}
pub mod buffer_prelude {
pub use crate::buffer::{
utils, AtomicCell, AtomicStats, AudioBuffer, BufferError, BufferResult, BufferStats,
DelayLine, FanInBuffer, FanOutBuffer, PipeBuffer, RingBuffer,
};
}
pub mod queue_prelude {
pub use crate::queues::{QueueError, QueueResult};
}
pub mod param_prelude {
pub use crate::traits::{
IntoParamValue, ParamMetadata, ParamRange, ParamType, ParamValue, ParameterError,
ParameterId, ParameterResult,
};
}
pub mod port_prelude {
pub use crate::traits::{PortDirection, PortError, PortId, PortResult, PortType};
}
pub mod node_prelude {
pub use crate::traits::{
AudioNode, NodeCategory, NodeId, NodeMetadata, NodeTypeId, Processor, Sink, Source,
};
}
pub mod external {
pub use std::f32::consts::PI;
pub use std::f64::consts::PI as PI_F64;
}
#[macro_export]
macro_rules! mono_block {
($data:expr, $size:expr) => {{
let mut block = [0.0; $size];
let len = $data.len().min($size);
block[..len].copy_from_slice(&$data[..len]);
block
}};
}
#[macro_export]
macro_rules! stereo_block {
($left:expr, $right:expr, $size:expr) => {{
let mut left_block = [0.0; $size];
let mut right_block = [0.0; $size];
let left_len = $left.len().min($size);
left_block[..left_len].copy_from_slice(&$left[..left_len]);
let right_len = $right.len().min($size);
right_block[..right_len].copy_from_slice(&$right[..right_len]);
[left_block, right_block]
}};
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_prelude_imports() {
let _node_id = NodeId(0);
let _port_id = PortId::audio_in(_node_id, 0);
let _param_id = ParameterId::new("test").unwrap();
let _clock = SystemClock::with_sample_rate(44100.0);
let _tick = ClockTick::new(0, 64, 44100.0);
let _pipe = PipeBuffer::<f32, 64>::new();
let _delay = DelayLine::<f32, 1024>::new(44100.0);
let _ring = RingBuffer::<f32, 256>::new();
let _cell = AtomicCell::new(42);
}
#[test]
fn test_type_aliases() {
let _pipe = DefaultPipeBuffer::<64>::new();
let _delay = DefaultDelayLine::<1024>::new(44100.0);
let _ring = DefaultRingBuffer::<256>::new();
let _clock = DefaultClock::with_sample_rate(44100.0);
}
#[test]
fn test_f32_prelude() {
use f32_prelude::*;
let _pipe = PipeBufferF32::<64>::new();
let _fan_out = FanOutBufferF32::<64, 4>::new();
let _fan_in = FanInBufferF32::<64, 2>::new();
let _delay = DelayLineF32::<1024>::new(44100.0);
let _ring = RingBufferF32::<256>::new();
let _clock = SystemClockF32::with_sample_rate(44100.0);
}
#[test]
fn test_f64_prelude() {
use f64_prelude::*;
let _pipe = PipeBufferF64::<64>::new();
let _fan_out = FanOutBufferF64::<64, 4>::new();
let _fan_in = FanInBufferF64::<64, 2>::new();
let _delay = DelayLineF64::<1024>::new(44100.0);
let _ring = RingBufferF64::<256>::new();
let _clock = SystemClockF64::with_sample_rate(44100.0);
}
#[test]
fn test_time_prelude() {
use time_prelude::*;
let mut clock = SystemClock::with_sample_rate(44100.0);
let tick = clock.next_tick(64);
let _pos = tick.absolute_seconds();
}
#[test]
fn test_buffer_prelude() {
use buffer_prelude::*;
let buffer = PipeBuffer::<f32, 64>::new();
let stats = buffer.stats();
let _fill = stats.fill_level;
}
#[test]
fn test_param_prelude() {
use param_prelude::*;
let _id = ParameterId::new("gain").unwrap();
let value = ParamValue::Float(0.5);
let _type = value.param_type();
}
#[test]
fn test_port_prelude() {
use port_prelude::*;
let port = PortId::audio_in(NodeId(0), 0);
assert!(port.is_audio());
assert!(port.is_input());
}
#[test]
fn test_constants() {
assert_eq!(DEFAULT_BLOCK_SIZE, 64);
assert_eq!(MAX_SAMPLE_RATE, 384_000.0);
assert_eq!(MIN_SAMPLE_RATE, 8_000.0);
assert_eq!(CACHE_LINE_SIZE, 64);
}
#[test]
fn test_macros() {
let data = vec![1.0, 2.0, 3.0];
let block = mono_block!(data, 4);
assert_eq!(block, [1.0, 2.0, 3.0, 0.0]);
let left = vec![1.0; 4];
let right = vec![2.0; 4];
let stereo = stereo_block!(left, right, 4);
assert_eq!(stereo[0], [1.0; 4]);
assert_eq!(stereo[1], [2.0; 4]);
}
#[test]
fn test_into_param_value() {
let f: f32 = 42.0;
let pv = f.into_param_value();
assert_eq!(pv.as_f32(), Some(42.0));
let i: i32 = 42;
let pv = i.into_param_value();
assert_eq!(pv.as_i32(), Some(42));
let b = true;
let pv = b.into_param_value();
assert_eq!(pv.as_bool(), Some(true));
}
}