Fix fixed volume with hardware mixer.

fixes https://github.com/librespot-org/librespot/issues/1008
This commit is contained in:
JasonLG1979 2022-05-28 09:08:50 -05:00
parent fc1e74574a
commit e4deb5ddcd
2 changed files with 22 additions and 11 deletions

View file

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
### Fixed ### Fixed
- [playback] `alsamixer`: make `--volume-ctrl fixed` work as expected when combined with `--mixer alsa`
### Removed ### Removed

View file

@ -104,23 +104,33 @@ impl Mixer for AlsaMixer {
let min_db = min_millibel.to_db() as f64; let min_db = min_millibel.to_db() as f64;
let max_db = max_millibel.to_db() as f64; let max_db = max_millibel.to_db() as f64;
let mut db_range = f64::abs(max_db - min_db); let reported_db_range = f64::abs(max_db - min_db);
// Synchronize the volume control dB range with the mixer control, // Synchronize the volume control dB range with the mixer control,
// unless it was already set with a command line option. // unless it was already set with a command line option.
if !config.volume_ctrl.range_ok() { let db_range = if config.volume_ctrl.range_ok() {
if db_range > 100.0 {
debug!("Alsa mixer reported dB range > 100, which is suspect");
warn!("Please manually set `--volume-range` if this is incorrect");
}
config.volume_ctrl.set_db_range(db_range);
} else {
let db_range_override = config.volume_ctrl.db_range(); let db_range_override = config.volume_ctrl.db_range();
if db_range_override.is_normal() {
db_range_override
} else {
reported_db_range
}
} else {
config.volume_ctrl.set_db_range(reported_db_range);
reported_db_range
};
if reported_db_range == db_range {
debug!("Alsa dB volume range was reported as {}", reported_db_range);
if reported_db_range > 100.0 {
debug!("Alsa mixer reported dB range > 100, which is suspect");
debug!("Please manually set `--volume-range` if this is incorrect");
}
} else {
debug!( debug!(
"Alsa dB volume range was detected as {} but overridden as {}", "Alsa dB volume range was reported as {} but overridden to {}",
db_range, db_range_override reported_db_range, db_range
); );
db_range = db_range_override;
} }
// For hardware controls with a small range (24 dB or less), // For hardware controls with a small range (24 dB or less),