librespot/playback/src/mixer/mod.rs

59 lines
1.4 KiB
Rust
Raw Normal View History

2018-02-26 01:50:41 +00:00
pub trait Mixer: Send {
fn open(_: Option<MixerConfig>) -> Self
2018-02-26 01:50:41 +00:00
where
Self: Sized;
fn start(&self);
fn stop(&self);
fn set_volume(&self, volume: u16);
fn volume(&self) -> u16;
fn get_audio_filter(&self) -> Option<Box<dyn AudioFilter + Send>> {
None
}
}
2017-01-27 13:20:31 +00:00
pub trait AudioFilter {
fn modify_stream(&self, data: &mut [f32]);
2017-01-25 21:49:18 +00:00
}
2018-03-20 15:32:43 +00:00
#[cfg(feature = "alsa-backend")]
pub mod alsamixer;
#[cfg(feature = "alsa-backend")]
use self::alsamixer::AlsaMixer;
#[derive(Debug, Clone)]
pub struct MixerConfig {
pub card: String,
pub mixer: String,
pub index: u32,
2018-09-17 15:28:54 +00:00
pub mapped_volume: bool,
}
impl Default for MixerConfig {
fn default() -> MixerConfig {
MixerConfig {
card: String::from("default"),
mixer: String::from("PCM"),
index: 0,
2018-09-17 15:28:54 +00:00
mapped_volume: true,
}
}
}
2017-02-21 21:49:45 +00:00
pub mod softmixer;
use self::softmixer::SoftMixer;
type MixerFn = fn(Option<MixerConfig>) -> Box<dyn Mixer>;
fn mk_sink<M: Mixer + 'static>(device: Option<MixerConfig>) -> Box<dyn Mixer> {
2018-03-20 15:32:43 +00:00
Box::new(M::open(device))
}
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) {
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,
}
}