#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mode {
Realtime,
LowLatency,
Eco,
Debug,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ThreadPriority {
Low,
Normal,
High,
Realtime,
Custom(i32),
}
#[derive(Debug, Clone)]
pub struct AudioConfig {
pub sample_rate: u32,
pub buffer_size: usize,
pub channels: u16,
pub mode: Mode,
pub thread_priority: ThreadPriority,
pub device_name: Option<String>,
}
impl Default for AudioConfig {
fn default() -> Self {
Self {
sample_rate: 48000,
buffer_size: 256,
channels: 2,
mode: Mode::Realtime,
thread_priority: ThreadPriority::Realtime,
device_name: None,
}
}
}
impl AudioConfig {
pub fn new(sample_rate: u32, buffer_size: usize) -> Self {
Self {
sample_rate,
buffer_size,
..Default::default()
}
}
pub fn with_channels(mut self, channels: u16) -> Self {
self.channels = channels;
self
}
pub fn with_mode(mut self, mode: Mode) -> Self {
self.mode = mode;
self
}
pub fn with_priority(mut self, priority: ThreadPriority) -> Self {
self.thread_priority = priority;
self
}
pub fn with_device(mut self, name: impl Into<String>) -> Self {
self.device_name = Some(name.into());
self
}
pub fn latency_seconds(&self) -> f64 {
self.buffer_size as f64 / self.sample_rate as f64
}
pub fn latency_ms(&self) -> f64 {
self.latency_seconds() * 1000.0
}
}
#[derive(Debug, Clone)]
pub struct QueueConfig {
pub size: usize,
pub overflow_policy: queue::OverflowPolicy,
}
impl Default for QueueConfig {
fn default() -> Self {
Self {
size: 1024,
overflow_policy: queue::OverflowPolicy::OverwriteOldest,
}
}
}