Merge pull request #749 from roderickvd/fix-default-threshold

This commit is contained in:
Sasha Hilton 2021-05-18 04:40:46 +01:00 committed by GitHub
commit 79f75b9119
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 15 deletions

View file

@ -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. * [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.2.0] - 2021-05-04
## [0.1.6] - 2021-02-22 ## [0.1.6] - 2021-02-22

View file

@ -1,4 +1,6 @@
use super::player::NormalisationData;
use crate::convert::i24; use crate::convert::i24;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::mem; use std::mem;
use std::str::FromStr; use std::str::FromStr;
@ -138,7 +140,7 @@ impl Default for PlayerConfig {
normalisation_type: NormalisationType::default(), normalisation_type: NormalisationType::default(),
normalisation_method: NormalisationMethod::default(), normalisation_method: NormalisationMethod::default(),
normalisation_pregain: 0.0, normalisation_pregain: 0.0,
normalisation_threshold: -1.0, normalisation_threshold: NormalisationData::db_to_ratio(-1.0),
normalisation_attack: 0.005, normalisation_attack: 0.005,
normalisation_release: 0.1, normalisation_release: 0.1,
normalisation_knee: 1.0, normalisation_knee: 1.0,

View file

@ -233,6 +233,10 @@ impl NormalisationData {
} }
fn get_factor(config: &PlayerConfig, data: NormalisationData) -> f32 { fn get_factor(config: &PlayerConfig, data: NormalisationData) -> f32 {
if !config.normalisation {
return 1.0;
}
let [gain_db, gain_peak] = match config.normalisation_type { let [gain_db, gain_peak] = match config.normalisation_type {
NormalisationType::Album => [data.album_gain_db, data.album_peak], NormalisationType::Album => [data.album_gain_db, data.album_peak],
NormalisationType::Track => [data.track_gain_db, data.track_peak], NormalisationType::Track => [data.track_gain_db, data.track_peak],

View file

@ -557,26 +557,26 @@ fn get_setup(args: &[String]) -> Setup {
.opt_str("normalisation-pregain") .opt_str("normalisation-pregain")
.map(|pregain| pregain.parse::<f32>().expect("Invalid pregain float value")) .map(|pregain| pregain.parse::<f32>().expect("Invalid pregain float value"))
.unwrap_or(PlayerConfig::default().normalisation_pregain), .unwrap_or(PlayerConfig::default().normalisation_pregain),
normalisation_threshold: NormalisationData::db_to_ratio( normalisation_threshold: matches
matches
.opt_str("normalisation-threshold") .opt_str("normalisation-threshold")
.map(|threshold| { .map(|threshold| {
NormalisationData::db_to_ratio(
threshold threshold
.parse::<f32>() .parse::<f32>()
.expect("Invalid threshold float value") .expect("Invalid threshold float value"),
)
}) })
.unwrap_or(PlayerConfig::default().normalisation_threshold), .unwrap_or(PlayerConfig::default().normalisation_threshold),
),
normalisation_attack: matches normalisation_attack: matches
.opt_str("normalisation-attack") .opt_str("normalisation-attack")
.map(|attack| attack.parse::<f32>().expect("Invalid attack float value")) .map(|attack| attack.parse::<f32>().expect("Invalid attack float value") / MILLIS)
.unwrap_or(PlayerConfig::default().normalisation_attack * MILLIS) .unwrap_or(PlayerConfig::default().normalisation_attack),
/ MILLIS,
normalisation_release: matches normalisation_release: matches
.opt_str("normalisation-release") .opt_str("normalisation-release")
.map(|release| release.parse::<f32>().expect("Invalid release float value")) .map(|release| {
.unwrap_or(PlayerConfig::default().normalisation_release * MILLIS) release.parse::<f32>().expect("Invalid release float value") / MILLIS
/ MILLIS, })
.unwrap_or(PlayerConfig::default().normalisation_release),
normalisation_knee: matches normalisation_knee: matches
.opt_str("normalisation-knee") .opt_str("normalisation-knee")
.map(|knee| knee.parse::<f32>().expect("Invalid knee float value")) .map(|knee| knee.parse::<f32>().expect("Invalid knee float value"))