mirror of
https://github.com/ivabus/speakersafetyd
synced 2024-11-22 08:15:07 +03:00
types: Always set amp gain to max on startup
The kernel should clamp this to the correct value. We still read it back later, to make sure our amp output calculations are correct. Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
071830b040
commit
f8d9c55cbb
2 changed files with 40 additions and 2 deletions
|
@ -131,6 +131,26 @@ pub fn write_ev(card: &alsa::ctl::Ctl, ev: &alsa::ctl::ElemValue, name: &str) {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
Wrapper for alsa::ctl::Ctl::elem_write().
|
||||
*/
|
||||
pub fn get_range_db(
|
||||
card: &alsa::ctl::Ctl,
|
||||
el: &alsa::ctl::ElemId,
|
||||
name: &str,
|
||||
) -> (MilliBel, MilliBel) {
|
||||
match card.get_db_range(el) {
|
||||
// alsa:Result<()>
|
||||
Ok(val) => val,
|
||||
Err(e) => {
|
||||
panic!(
|
||||
"Could not get elem db range {}. alsa-lib error: {:?}",
|
||||
name, e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Wrapper for alsa::ctl::Ctl::elem_read().
|
||||
*/
|
||||
|
|
22
src/types.rs
22
src/types.rs
|
@ -107,7 +107,7 @@ impl Mixer {
|
|||
helpers::read_ev(card, &mut vs.val, &vs.elem_name);
|
||||
assert!(vs.val.get_boolean(0).unwrap());
|
||||
|
||||
Mixer {
|
||||
let mut ret = Mixer {
|
||||
drv: name.to_owned(),
|
||||
level: Elem::new(
|
||||
prefix.clone() + &globals.ctl_volume,
|
||||
|
@ -119,7 +119,25 @@ impl Mixer {
|
|||
card,
|
||||
alsa::ctl::ElemType::Integer,
|
||||
),
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Set amp gain to max available (kernel should've clamped).
|
||||
* alsa-rs only has bindings for range in dB, so we go through
|
||||
* that.
|
||||
*/
|
||||
|
||||
let (_min, max) =
|
||||
helpers::get_range_db(card, &mut ret.amp_gain.id, &ret.amp_gain.elem_name);
|
||||
let max_int = card
|
||||
.convert_from_db(&mut ret.amp_gain.id, max, alsa::Round::Floor)
|
||||
.unwrap();
|
||||
|
||||
ret.amp_gain.val.set_integer(0, max_int.try_into().unwrap());
|
||||
|
||||
helpers::write_ev(card, &ret.amp_gain.val, &ret.amp_gain.elem_name);
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
fn get_amp_gain(&mut self, card: &Ctl) -> f32 {
|
||||
|
|
Loading…
Reference in a new issue