-
Notifications
You must be signed in to change notification settings - Fork 0
/
traits.rs
52 lines (41 loc) · 1.7 KB
/
traits.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::error::Error;
use std::fmt::Debug;
pub type RenderCallback<B> =
dyn FnMut(&[<B as Backend>::AudioBuffers], &mut [<B as Backend>::AudioBuffers]) + Send;
pub trait Backend: Sized {
type Session: Session<Self>;
type Device: Device<Self> + Debug + Clone;
type Error: Error;
type AudioBuffers: AudioBuffers;
fn new() -> Result<Self, Self::Error>;
fn all_devices(&self) -> Result<Vec<Self::Device>, Self::Error>;
fn default_input_device(&self) -> Result<Self::Device, Self::Error>;
fn default_output_device(&self) -> Result<Self::Device, Self::Error>;
fn start_session(
&self,
sample_rate: f64,
input_device: Self::Device,
output_device: Self::Device,
callback: Box<RenderCallback<Self>>,
) -> Result<Self::Session, Self::Error>;
}
pub trait Session<B: Backend>: Sized {
fn input_device(&self) -> Result<B::Device, B::Error>;
fn output_device(&self) -> Result<B::Device, B::Error>;
fn set_input_device(&mut self, device: B::Device) -> Result<(), B::Error>;
fn set_output_device(&mut self, device: B::Device) -> Result<(), B::Error>;
}
pub trait Device<B: Backend> {
fn num_inputs(&self) -> Result<usize, B::Error>;
fn num_outputs(&self) -> Result<usize, B::Error>;
fn name(&self) -> Result<String, B::Error>;
fn set_nominal_sample_rate(&mut self, sample_rate: f64) -> Result<(), B::Error>;
fn nominal_sample_rate(&self) -> Result<f64, B::Error>;
fn actual_sample_rate(&self) -> Result<f64, B::Error>;
}
pub trait AudioBuffers {
fn num_frames(&self) -> usize;
fn num_channels(&self) -> usize;
fn interleaved_frames(&self) -> &[f32];
fn interleaved_frames_mut(&mut self) -> &mut [f32];
}