Skip to main content

rill_io/
lib.rs

1//! Audio I/O backends for Rill
2//!
3//! This crate provides a unified interface to various audio backends
4//! (ALSA, CPAL, PipeWire, JACK). Graph processing is handled by
5//! [`rill_graph::AudioEngine`] — this crate is purely about hardware I/O.
6
7#![warn(missing_docs)]
8
9mod backend;
10mod buffer;
11mod config;
12mod error;
13
14pub mod backends;
15
16pub use backend::{AudioBackend, BackendType, DeviceInfo};
17pub use config::AudioConfig;
18pub use error::{IoError, IoResult};
19
20pub use backends::NullBackend;
21
22#[cfg(feature = "cpal")]
23pub use backends::CpalBackend;
24
25#[cfg(feature = "alsa")]
26pub use backends::AlsaBackend;
27
28#[cfg(feature = "pipewire")]
29pub use backends::PipewireBackend;
30
31#[cfg(feature = "jack")]
32pub use backends::JackBackend;
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    #[test]
39    fn test_config_default() {
40        let config = AudioConfig::default();
41        assert_eq!(config.sample_rate, 48000);
42        assert_eq!(config.buffer_size, 256);
43        assert_eq!(config.input_channels, 2);
44        assert_eq!(config.output_channels, 2);
45    }
46
47    #[test]
48    fn test_config_with_methods() {
49        let config = AudioConfig::new()
50            .with_sample_rate(44100)
51            .with_buffer_size(512)
52            .with_channels(1);
53        assert_eq!(config.sample_rate, 44100);
54        assert_eq!(config.buffer_size, 512);
55    }
56
57    #[test]
58    fn test_latency_calculation() {
59        let config = AudioConfig::new()
60            .with_sample_rate(48000)
61            .with_buffer_size(256);
62        let latency_sec = config.latency_seconds();
63        let latency_ms = config.latency_ms();
64        assert!((latency_sec - 256.0 / 48000.0).abs() < 1e-10);
65        assert!((latency_ms - 256.0 * 1000.0 / 48000.0).abs() < 1e-10);
66    }
67}