1 pub trait Mixer: Send {
open(_: Option<MixerConfig>) -> Self where Self: Sized2     fn open(_: Option<MixerConfig>) -> Self
3     where
4         Self: Sized;
start(&self)5     fn start(&self);
stop(&self)6     fn stop(&self);
set_volume(&self, volume: u16)7     fn set_volume(&self, volume: u16);
volume(&self) -> u168     fn volume(&self) -> u16;
get_audio_filter(&self) -> Option<Box<dyn AudioFilter + Send>>9     fn get_audio_filter(&self) -> Option<Box<dyn AudioFilter + Send>> {
10         None
11     }
12 }
13 
14 pub trait AudioFilter {
modify_stream(&self, data: &mut [i16])15     fn modify_stream(&self, data: &mut [i16]);
16 }
17 
18 #[cfg(feature = "alsa-backend")]
19 pub mod alsamixer;
20 #[cfg(feature = "alsa-backend")]
21 use self::alsamixer::AlsaMixer;
22 
23 #[derive(Debug, Clone)]
24 pub struct MixerConfig {
25     pub card: String,
26     pub mixer: String,
27     pub index: u32,
28 }
29 
30 impl Default for MixerConfig {
default() -> MixerConfig31     fn default() -> MixerConfig {
32         MixerConfig {
33             card: String::from("default"),
34             mixer: String::from("PCM"),
35             index: 0,
36         }
37     }
38 }
39 
40 pub mod softmixer;
41 use self::softmixer::SoftMixer;
42 
mk_sink<M: Mixer + 'static>(device: Option<MixerConfig>) -> Box<dyn Mixer>43 fn mk_sink<M: Mixer + 'static>(device: Option<MixerConfig>) -> Box<dyn Mixer> {
44     Box::new(M::open(device))
45 }
46 
find<T: AsRef<str>>(name: Option<T>) -> Option<fn(Option<MixerConfig>) -> Box<dyn Mixer>>47 pub fn find<T: AsRef<str>>(name: Option<T>) -> Option<fn(Option<MixerConfig>) -> Box<dyn Mixer>> {
48     match name.as_ref().map(AsRef::as_ref) {
49         None | Some("softvol") => Some(mk_sink::<SoftMixer>),
50         #[cfg(feature = "alsa-backend")]
51         Some("alsa") => Some(mk_sink::<AlsaMixer>),
52         _ => None,
53     }
54 }
55