More alsa stragglers

This commit is contained in:
ashthespy 2018-11-01 17:40:42 +01:00
parent a80bf86a2b
commit cc6c9b2dc4
3 changed files with 18 additions and 15 deletions

View file

@ -2,7 +2,6 @@ use super::{Open, Sink};
use alsa::device_name::HintIter;
use alsa::pcm::{Access, Format, HwParams, PCM};
use alsa::{Direction, Error, ValueOr};
use std::env;
use std::ffi::CString;
use std::io;
use std::process::exit;
@ -15,7 +14,7 @@ fn list_outputs() {
let i = HintIter::new(None, &*CString::new(*t).unwrap()).unwrap();
for a in i {
if let Some(Direction::Playback) = a.direction {
println!("{:#?}", a)
println!("{}\n\t{}", a.name.unwrap(), a.desc.unwrap());
}
}
}

View file

@ -14,25 +14,27 @@ impl AlsaMixer {
let mixer = alsa::mixer::Mixer::new(&self.config.card, false)?;
let sid = alsa::mixer::SelemId::new(&*self.config.mixer, self.config.index);
let selem = mixer.find_selem(&sid).expect("Couldn't find SelemId");
let selem = mixer
.find_selem(&sid)
.expect(format!("Couldn't find simple mixer control for {}", self.config.mixer).as_str());
let (min, max) = selem.get_playback_volume_range();
let cur_vol = selem
.get_playback_volume(alsa::mixer::SelemChannelId::mono())
.expect("Couldn't get current volume");
let range = (max - min) as f64;
let new_vol: u16;
if let Some(vol) = set_volume {
let alsa_volume: i64 = ((vol as f64 / 0xFFFF as f64) * range) as i64 + min;
debug!("Mapping volume {:?} [u16] ->> alsa {:?} [i64]", vol, alsa_volume);
debug!("Mapping volume {:?} ->> alsa {:?}", vol, alsa_volume);
selem
.set_playback_volume_all(alsa_volume)
.expect("Couldn't set alsa volume");
new_vol = vol;
} else {
let cur_vol = selem
.get_playback_volume(alsa::mixer::SelemChannelId::mono())
.expect("Couldn't get current volume");
new_vol = (((cur_vol - min) as f64 / range) * 0xFFFF as f64) as u16;
debug!("Mapping volume {:?} [u16] <<- alsa {:?} [i64]", new_vol, cur_vol);
debug!("Mapping volume {:?} <<- alsa {:?}", new_vol, cur_vol);
}
Ok(new_vol)

View file

@ -140,10 +140,10 @@ fn setup(args: &[String]) -> Setup {
.optopt(
"",
"device",
"Audio device to use. Use '?' to list options if using portaudio",
"Audio device to use. Use '?' to list options if using portaudio or alsa",
"DEVICE",
)
.optopt("", "mixer", "Mixer to use (Alsa or softmixer)", "MIXER")
.optopt("", "mixer", "Mixer to use (alsa or softmixer)", "MIXER")
.optopt(
"m",
"mixer-name",
@ -230,7 +230,10 @@ fn setup(args: &[String]) -> Setup {
let mixer_config = MixerConfig {
card: matches.opt_str("mixer-card").unwrap_or(String::from("default")),
mixer: matches.opt_str("mixer-name").unwrap_or(String::from("PCM")),
index: matches.opt_str("mixer-index").map(|index| index.parse::<u32>().unwrap()).unwrap_or(0),
index: matches
.opt_str("mixer-index")
.map(|index| index.parse::<u32>().unwrap())
.unwrap_or(0),
};
let use_audio_cache = !matches.opt_present("disable-audio-cache");
@ -247,8 +250,7 @@ fn setup(args: &[String]) -> Setup {
panic!("Initial volume must be in the range 0-100");
}
(volume as i32 * 0xFFFF / 100) as u16
})
.or_else(|| cache.as_ref().and_then(Cache::volume))
}).or_else(|| cache.as_ref().and_then(Cache::volume))
.unwrap_or(0x8000);
let zeroconf_port = matches