1pub use crate::traits::{
47 Action,
48 ActionContext,
49
50 Algorithm,
52 AlgorithmCategory,
53 AlgorithmMetadata,
54 AudioNode,
56 ConnectionError,
57 ConnectionResult,
58 IntoParamValue,
60
61 NodeCategory,
62 NodeId,
64 NodeMetadata,
65 NodeState,
66
67 NodeTypeId,
68 ParamMetadata,
69
70 ParamRange,
71 ParamType,
72 ParamValue,
73 ParameterError,
74 ParameterId,
76 ParameterResult,
77 Port,
78
79 PortDirection,
80 PortError,
81 PortId,
83 PortResult,
84 PortType,
85 ProcessError,
86 ProcessResult,
88 Processor,
89 Sink,
90
91 Source,
92};
93
94pub use crate::time::{ClockSource, ClockTick, SystemClock, TimeError, TimeResult};
99
100pub use crate::math::Transcendental;
105
106pub use crate::math::vector::math::{
111 abs_slice, clamp_slice, cos_slice, exp_slice, ln_slice,
112 max_slice, min_slice, sin_slice, sqrt_slice, tan_slice,
113};
114pub use crate::math::vector::ops::{
115 add_scalar_slice, add_slices, div_slices, mul_scalar_slice, mul_slices, sub_slices,
116};
117pub use crate::math::vector::scalar::{ScalarVector1, ScalarVector2, ScalarVector4, ScalarVector8};
118#[cfg(feature = "simd")]
119pub use crate::math::vector::simd::*;
120pub use crate::math::vector::traits::{
121 Vector, VectorMask, VectorReduce, VectorScalarOps, VectorTranscendental,
122};
123
124pub use crate::buffer::{
129 utils,
131 AtomicCell,
133 AtomicCellError,
134 AtomicStats,
135
136 AudioBuffer,
138
139 Buffer,
141
142 BufferError,
144 BufferResult,
145
146 BufferStats,
148
149 DelayLine,
150 FanInBuffer,
151 FanOutBuffer,
152 PipeBuffer,
154 RingBuffer,
155};
156
157pub use crate::queues::{QueueError, QueueResult, TelemetryBlock};
162
163pub use crate::{
168 CACHE_LINE_SIZE,
170 DEFAULT_BLOCK_SIZE,
172 DEFAULT_BUFFER_SIZE,
174 DEFAULT_SAMPLE_RATE,
175
176 MAX_BLOCK_SIZE,
177 MAX_BUFFER_SIZE,
178 MAX_SAMPLE_RATE,
180 MIN_BLOCK_SIZE,
181
182 MIN_BUFFER_SIZE,
183
184 MIN_SAMPLE_RATE,
185 VERSION,
187};
188
189pub type Sample = f32;
195
196pub type MonoBlock<T, const N: usize> = [T; N];
198
199pub type StereoBlock<T, const N: usize> = [MonoBlock<T, N>; 2];
201
202pub type ControlValue<T> = T;
204
205pub type DefaultPipeBuffer<const N: usize = DEFAULT_BLOCK_SIZE> = PipeBuffer<Sample, N>;
207
208pub type DefaultDelayLine<const MAX_DELAY: usize> = DelayLine<Sample, MAX_DELAY>;
210
211pub type DefaultRingBuffer<const N: usize> = RingBuffer<Sample, N>;
213
214pub type DefaultClock = SystemClock;
216
217pub mod f32_prelude {
223 use crate::buffer::{DelayLine, FanInBuffer, FanOutBuffer, PipeBuffer, RingBuffer};
224
225 pub type PipeBufferF32<const N: usize> = PipeBuffer<f32, N>;
227
228 pub type FanOutBufferF32<const N: usize, const CONSUMERS: usize> =
230 FanOutBuffer<f32, N, CONSUMERS>;
231
232 pub type FanInBufferF32<const N: usize, const PRODUCERS: usize> =
234 FanInBuffer<f32, N, PRODUCERS>;
235
236 pub type DelayLineF32<const MAX_DELAY: usize> = DelayLine<f32, MAX_DELAY>;
238
239 pub type RingBufferF32<const N: usize> = RingBuffer<f32, N>;
241
242 pub type SystemClockF32 = crate::time::SystemClock;
244
245 pub use crate::traits::{Processor as ProcessorF32, Sink as SinkF32, Source as SourceF32};
247
248 pub use crate::math::Transcendental;
249}
250
251pub mod f64_prelude {
253 use crate::buffer::{DelayLine, FanInBuffer, FanOutBuffer, PipeBuffer, RingBuffer};
254
255 pub type PipeBufferF64<const N: usize> = PipeBuffer<f64, N>;
257
258 pub type FanOutBufferF64<const N: usize, const CONSUMERS: usize> =
260 FanOutBuffer<f64, N, CONSUMERS>;
261
262 pub type FanInBufferF64<const N: usize, const PRODUCERS: usize> =
264 FanInBuffer<f64, N, PRODUCERS>;
265
266 pub type DelayLineF64<const MAX_DELAY: usize> = DelayLine<f64, MAX_DELAY>;
268
269 pub type RingBufferF64<const N: usize> = RingBuffer<f64, N>;
271
272 pub type SystemClockF64 = crate::time::SystemClock;
274
275 pub use crate::traits::{Processor as ProcessorF64, Sink as SinkF64, Source as SourceF64};
277
278 pub use crate::math::Transcendental;
279}
280
281pub mod time_prelude {
283 pub use crate::time::{ClockSource, ClockTick, SystemClock, TimeError, TimeResult};
284}
285
286pub mod buffer_prelude {
288 pub use crate::buffer::{
289 utils, AtomicCell, AtomicStats, AudioBuffer, BufferError, BufferResult, BufferStats,
290 DelayLine, FanInBuffer, FanOutBuffer, PipeBuffer, RingBuffer,
291 };
292}
293
294pub mod queue_prelude {
296 pub use crate::queues::{QueueError, QueueResult};
297}
298
299pub mod param_prelude {
301 pub use crate::traits::{
302 IntoParamValue, ParamMetadata, ParamRange, ParamType, ParamValue, ParameterError,
303 ParameterId, ParameterResult,
304 };
305}
306
307pub mod port_prelude {
309 pub use crate::traits::{PortDirection, PortError, PortId, PortResult, PortType};
310}
311
312pub mod node_prelude {
314 pub use crate::traits::{
315 AudioNode, NodeCategory, NodeId, NodeMetadata, NodeTypeId, Processor, Sink, Source,
316 };
317}
318
319pub mod external {
325 pub use std::f32::consts::PI;
326 pub use std::f64::consts::PI as PI_F64;
327}
328
329#[macro_export]
343macro_rules! mono_block {
344 ($data:expr, $size:expr) => {{
345 let mut block = [0.0; $size];
346 let len = $data.len().min($size);
347 block[..len].copy_from_slice(&$data[..len]);
348 block
349 }};
350}
351
352#[macro_export]
363macro_rules! stereo_block {
364 ($left:expr, $right:expr, $size:expr) => {{
365 let mut left_block = [0.0; $size];
366 let mut right_block = [0.0; $size];
367
368 let left_len = $left.len().min($size);
369 left_block[..left_len].copy_from_slice(&$left[..left_len]);
370
371 let right_len = $right.len().min($size);
372 right_block[..right_len].copy_from_slice(&$right[..right_len]);
373
374 [left_block, right_block]
375 }};
376}
377
378#[cfg(test)]
383mod tests {
384 use super::*;
385
386 #[test]
387 fn test_prelude_imports() {
388 let _node_id = NodeId(0);
390 let _port_id = PortId::audio_in(_node_id, 0);
391 let _param_id = ParameterId::new("test").unwrap();
392 let _clock = SystemClock::with_sample_rate(44100.0);
393 let _tick = ClockTick::new(0, 64, 44100.0);
394
395 let _pipe = PipeBuffer::<f32, 64>::new();
397 let _delay = DelayLine::<f32, 1024>::new(44100.0);
398 let _ring = RingBuffer::<f32, 256>::new();
399
400 let _cell = AtomicCell::new(42);
402 }
403
404 #[test]
405 fn test_type_aliases() {
406 let _pipe = DefaultPipeBuffer::<64>::new();
407 let _delay = DefaultDelayLine::<1024>::new(44100.0);
408 let _ring = DefaultRingBuffer::<256>::new();
409 let _clock = DefaultClock::with_sample_rate(44100.0);
410 }
411
412 #[test]
413 fn test_f32_prelude() {
414 use f32_prelude::*;
415
416 let _pipe = PipeBufferF32::<64>::new();
417 let _fan_out = FanOutBufferF32::<64, 4>::new();
418 let _fan_in = FanInBufferF32::<64, 2>::new();
419 let _delay = DelayLineF32::<1024>::new(44100.0);
420 let _ring = RingBufferF32::<256>::new();
421 let _clock = SystemClockF32::with_sample_rate(44100.0);
422 }
423
424 #[test]
425 fn test_f64_prelude() {
426 use f64_prelude::*;
427
428 let _pipe = PipeBufferF64::<64>::new();
429 let _fan_out = FanOutBufferF64::<64, 4>::new();
430 let _fan_in = FanInBufferF64::<64, 2>::new();
431 let _delay = DelayLineF64::<1024>::new(44100.0);
432 let _ring = RingBufferF64::<256>::new();
433 let _clock = SystemClockF64::with_sample_rate(44100.0);
434 }
435
436 #[test]
437 fn test_time_prelude() {
438 use time_prelude::*;
439
440 let mut clock = SystemClock::with_sample_rate(44100.0);
441 let tick = clock.next_tick(64);
442 let _pos = tick.absolute_seconds();
443 }
444
445 #[test]
446 fn test_buffer_prelude() {
447 use buffer_prelude::*;
448
449 let buffer = PipeBuffer::<f32, 64>::new();
450 let stats = buffer.stats();
451 let _fill = stats.fill_level;
452 }
453
454 #[test]
455 fn test_param_prelude() {
456 use param_prelude::*;
457
458 let _id = ParameterId::new("gain").unwrap();
459 let value = ParamValue::Float(0.5);
460 let _type = value.param_type();
461 }
462
463 #[test]
464 fn test_port_prelude() {
465 use port_prelude::*;
466
467 let port = PortId::audio_in(NodeId(0), 0);
468 assert!(port.is_audio());
469 assert!(port.is_input());
470 }
471
472 #[test]
473 fn test_constants() {
474 assert_eq!(DEFAULT_BLOCK_SIZE, 64);
475 assert_eq!(MAX_SAMPLE_RATE, 384_000.0);
476 assert_eq!(MIN_SAMPLE_RATE, 8_000.0);
477 assert_eq!(CACHE_LINE_SIZE, 64);
478 }
479
480 #[test]
481 fn test_macros() {
482 let data = vec![1.0, 2.0, 3.0];
483 let block = mono_block!(data, 4);
484 assert_eq!(block, [1.0, 2.0, 3.0, 0.0]);
485
486 let left = vec![1.0; 4];
487 let right = vec![2.0; 4];
488 let stereo = stereo_block!(left, right, 4);
489 assert_eq!(stereo[0], [1.0; 4]);
490 assert_eq!(stereo[1], [2.0; 4]);
491 }
492
493 #[test]
494 fn test_into_param_value() {
495 let f: f32 = 42.0;
496 let pv = f.into_param_value();
497 assert_eq!(pv.as_f32(), Some(42.0));
498
499 let i: i32 = 42;
500 let pv = i.into_param_value();
501 assert_eq!(pv.as_i32(), Some(42));
502
503 let b = true;
504 let pv = b.into_param_value();
505 assert_eq!(pv.as_bool(), Some(true));
506 }
507}