From a4ad6d4aa8de1e325755977c44d1f5274ab7e4e5 Mon Sep 17 00:00:00 2001 From: Roderick van Domburg Date: Sun, 16 May 2021 22:30:35 +0200 Subject: [PATCH] Fix default normalisation threshold [#745] --- CHANGELOG.md | 4 ++++ playback/src/config.rs | 4 +++- src/main.rs | 28 ++++++++++++++-------------- 3 files changed, 21 insertions(+), 15 deletions(-) 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/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"))