2021-05-24 13:53:32 +00:00
|
|
|
use crate::config::VolumeCtrl;
|
|
|
|
|
|
|
|
pub mod mappings;
|
|
|
|
use self::mappings::MappedCtrl;
|
|
|
|
|
2018-02-26 01:50:41 +00:00
|
|
|
pub trait Mixer: Send {
|
2021-05-24 13:53:32 +00:00
|
|
|
fn open(config: MixerConfig) -> Self
|
2018-02-26 01:50:41 +00:00
|
|
|
where
|
|
|
|
Self: Sized;
|
2021-05-24 13:53:32 +00:00
|
|
|
|
2017-01-25 21:22:53 +00:00
|
|
|
fn set_volume(&self, volume: u16);
|
2017-01-20 19:39:05 +00:00
|
|
|
fn volume(&self) -> u16;
|
2021-05-24 13:53:32 +00:00
|
|
|
|
2019-10-08 09:31:18 +00:00
|
|
|
fn get_audio_filter(&self) -> Option<Box<dyn AudioFilter + Send>> {
|
2017-01-25 21:22:53 +00:00
|
|
|
None
|
2017-01-20 19:39:05 +00:00
|
|
|
}
|
2017-01-25 21:22:53 +00:00
|
|
|
}
|
|
|
|
|
2017-01-27 13:20:31 +00:00
|
|
|
pub trait AudioFilter {
|
2021-02-24 20:39:42 +00:00
|
|
|
fn modify_stream(&self, data: &mut [f32]);
|
2017-01-25 21:49:18 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 13:53:32 +00:00
|
|
|
pub mod softmixer;
|
|
|
|
use self::softmixer::SoftMixer;
|
|
|
|
|
2018-03-20 15:32:43 +00:00
|
|
|
#[cfg(feature = "alsa-backend")]
|
|
|
|
pub mod alsamixer;
|
|
|
|
#[cfg(feature = "alsa-backend")]
|
|
|
|
use self::alsamixer::AlsaMixer;
|
|
|
|
|
2018-09-11 16:53:18 +00:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct MixerConfig {
|
|
|
|
pub card: String,
|
2021-05-24 13:53:32 +00:00
|
|
|
pub control: String,
|
2018-09-11 16:53:18 +00:00
|
|
|
pub index: u32,
|
2021-05-24 13:53:32 +00:00
|
|
|
pub volume_ctrl: VolumeCtrl,
|
2018-09-11 16:53:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for MixerConfig {
|
2019-10-08 09:31:18 +00:00
|
|
|
fn default() -> MixerConfig {
|
|
|
|
MixerConfig {
|
|
|
|
card: String::from("default"),
|
2021-05-24 13:53:32 +00:00
|
|
|
control: String::from("PCM"),
|
2019-10-08 09:31:18 +00:00
|
|
|
index: 0,
|
2021-05-24 13:53:32 +00:00
|
|
|
volume_ctrl: VolumeCtrl::default(),
|
2018-09-11 16:53:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-24 13:53:32 +00:00
|
|
|
pub type MixerFn = fn(MixerConfig) -> Box<dyn Mixer>;
|
2021-03-10 21:32:24 +00:00
|
|
|
|
2021-05-24 13:53:32 +00:00
|
|
|
fn mk_sink<M: Mixer + 'static>(config: MixerConfig) -> Box<dyn Mixer> {
|
|
|
|
Box::new(M::open(config))
|
2017-02-22 04:17:04 +00:00
|
|
|
}
|
|
|
|
|
2021-03-10 21:32:24 +00:00
|
|
|
pub fn find<T: AsRef<str>>(name: Option<T>) -> Option<MixerFn> {
|
2017-02-21 21:49:45 +00:00
|
|
|
match name.as_ref().map(AsRef::as_ref) {
|
2017-02-22 04:17:04 +00:00
|
|
|
None | Some("softvol") => Some(mk_sink::<SoftMixer>),
|
2018-03-20 15:32:43 +00:00
|
|
|
#[cfg(feature = "alsa-backend")]
|
|
|
|
Some("alsa") => Some(mk_sink::<AlsaMixer>),
|
2017-02-21 21:49:45 +00:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|