Skip to content

Commit c8971dc

Browse files
authored
Fix Alsa softvol linear mapping (#950)
Use `--volume-range` overrides
1 parent 03e71f6 commit c8971dc

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030
- [main] `--alsa-mixer-device` and `--alsa-mixer-index` now fallback to the card and index specified in `--device`.
3131
- [core] Removed unsafe code (breaking)
3232
- [playback] Adhere to ReplayGain spec when calculating gain normalisation factor.
33+
- [playback] `alsa`: Use `--volume-range` overrides for softvol controls
3334

3435
### Removed
3536
- [playback] `alsamixer`: previously deprecated option `mixer-card` has been removed.

playback/src/mixer/alsamixer.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Mixer for AlsaMixer {
8484
warn!("Alsa rounding error detected, setting maximum dB to {:.2} instead of {:.2}", ZERO_DB.to_db(), max_millibel.to_db());
8585
max_millibel = ZERO_DB;
8686
} else {
87-
warn!("Please manually set with `--volume-ctrl` if this is incorrect");
87+
warn!("Please manually set `--volume-range` if this is incorrect");
8888
}
8989
}
9090
(min_millibel, max_millibel)
@@ -104,12 +104,23 @@ impl Mixer for AlsaMixer {
104104

105105
let min_db = min_millibel.to_db() as f64;
106106
let max_db = max_millibel.to_db() as f64;
107-
let db_range = f64::abs(max_db - min_db);
107+
let mut db_range = f64::abs(max_db - min_db);
108108

109109
// Synchronize the volume control dB range with the mixer control,
110110
// unless it was already set with a command line option.
111111
if !config.volume_ctrl.range_ok() {
112+
if db_range > 100.0 {
113+
debug!("Alsa mixer reported dB range > 100, which is suspect");
114+
warn!("Please manually set `--volume-range` if this is incorrect");
115+
}
112116
config.volume_ctrl.set_db_range(db_range);
117+
} else {
118+
let db_range_override = config.volume_ctrl.db_range();
119+
debug!(
120+
"Alsa dB volume range was detected as {} but overridden as {}",
121+
db_range, db_range_override
122+
);
123+
db_range = db_range_override;
113124
}
114125

115126
// For hardware controls with a small range (24 dB or less),

0 commit comments

Comments
 (0)