diff --git a/CHANGELOG.md b/CHANGELOG.md index f1e6ae1d..9a775d4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [librespot-audio] Removed `VorbisDecoder`, `VorbisError`, `AudioPacket`, `PassthroughDecoder`, `PassthroughError`, `AudioError`, `AudioDecoder` and the `convert` module from `librespot_audio`. The underlying crates `vorbis`, `librespot-tremor`, `lewton` and `ogg` should be used directly. +### Fixed + +* [librespot-playback] Incorrect `PlayerConfig::default().normalisation_threshold` caused distortion when using dynamic volume normalisation downstream + ## [0.2.0] - 2021-05-04 ## [0.1.6] - 2021-02-22 diff --git a/playback/src/config.rs b/playback/src/config.rs index 3ae0f34f..feb1d61e 100644 --- a/playback/src/config.rs +++ b/playback/src/config.rs @@ -1,4 +1,6 @@ +use super::player::NormalisationData; use crate::convert::i24; + use std::convert::TryFrom; use std::mem; use std::str::FromStr; @@ -138,7 +140,7 @@ impl Default for PlayerConfig { normalisation_type: NormalisationType::default(), normalisation_method: NormalisationMethod::default(), normalisation_pregain: 0.0, - normalisation_threshold: -1.0, + normalisation_threshold: NormalisationData::db_to_ratio(-1.0), normalisation_attack: 0.005, normalisation_release: 0.1, normalisation_knee: 1.0, diff --git a/playback/src/player.rs b/playback/src/player.rs index f5f3ab66..8cbb4372 100644 --- a/playback/src/player.rs +++ b/playback/src/player.rs @@ -233,6 +233,10 @@ impl NormalisationData { } fn get_factor(config: &PlayerConfig, data: NormalisationData) -> f32 { + if !config.normalisation { + return 1.0; + } + let [gain_db, gain_peak] = match config.normalisation_type { NormalisationType::Album => [data.album_gain_db, data.album_peak], NormalisationType::Track => [data.track_gain_db, data.track_peak], diff --git a/src/main.rs b/src/main.rs index 7a2ef2a4..a5106af2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -557,26 +557,26 @@ fn get_setup(args: &[String]) -> Setup { .opt_str("normalisation-pregain") .map(|pregain| pregain.parse::().expect("Invalid pregain float value")) .unwrap_or(PlayerConfig::default().normalisation_pregain), - normalisation_threshold: NormalisationData::db_to_ratio( - matches - .opt_str("normalisation-threshold") - .map(|threshold| { + normalisation_threshold: matches + .opt_str("normalisation-threshold") + .map(|threshold| { + NormalisationData::db_to_ratio( threshold .parse::() - .expect("Invalid threshold float value") - }) - .unwrap_or(PlayerConfig::default().normalisation_threshold), - ), + .expect("Invalid threshold float value"), + ) + }) + .unwrap_or(PlayerConfig::default().normalisation_threshold), normalisation_attack: matches .opt_str("normalisation-attack") - .map(|attack| attack.parse::().expect("Invalid attack float value")) - .unwrap_or(PlayerConfig::default().normalisation_attack * MILLIS) - / MILLIS, + .map(|attack| attack.parse::().expect("Invalid attack float value") / MILLIS) + .unwrap_or(PlayerConfig::default().normalisation_attack), normalisation_release: matches .opt_str("normalisation-release") - .map(|release| release.parse::().expect("Invalid release float value")) - .unwrap_or(PlayerConfig::default().normalisation_release * MILLIS) - / MILLIS, + .map(|release| { + release.parse::().expect("Invalid release float value") / MILLIS + }) + .unwrap_or(PlayerConfig::default().normalisation_release), normalisation_knee: matches .opt_str("normalisation-knee") .map(|knee| knee.parse::().expect("Invalid knee float value"))