Skip to content

Commit 703b667

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into dithering-and-noise-shaping
2 parents de77487 + 6881875 commit 703b667

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- [playback] Add support for noise shaping with `--shape-noise` for lower perceived noise (breaking)
1212

1313
### Changed
14-
1514
* [audio, playback] Moved `VorbisDecoder`, `VorbisError`, `AudioPacket`, `PassthroughDecoder`, `PassthroughError`, `AudioError`, `AudioDecoder` and the `convert` module from `librespot-audio` to `librespot-playback`. The underlying crates `vorbis`, `librespot-tremor`, `lewton` and `ogg` should be used directly. (breaking)
1615

16+
### Fixed
17+
* [playback] Incorrect `PlayerConfig::default().normalisation_threshold` caused distortion when using dynamic volume normalisation downstream
18+
1719
## [0.2.0] - 2021-05-04
1820

1921
## [0.1.6] - 2021-02-22

core/tests/connect.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1+
use std::time::Duration;
2+
13
use librespot_core::authentication::Credentials;
24
use librespot_core::config::SessionConfig;
35
use librespot_core::session::Session;
46

7+
use tokio::time::timeout;
8+
59
#[tokio::test]
610
async fn test_connection() {
7-
let result = Session::connect(
8-
SessionConfig::default(),
9-
Credentials::with_password("test", "test"),
10-
None,
11-
)
12-
.await;
11+
timeout(Duration::from_secs(30), async {
12+
let result = Session::connect(
13+
SessionConfig::default(),
14+
Credentials::with_password("test", "test"),
15+
None,
16+
)
17+
.await;
1318

14-
match result {
15-
Ok(_) => panic!("Authentication succeeded despite of bad credentials."),
16-
Err(e) => assert_eq!(e.to_string(), "Login failed with reason: Bad credentials"),
17-
};
19+
match result {
20+
Ok(_) => panic!("Authentication succeeded despite of bad credentials."),
21+
Err(e) => assert_eq!(e.to_string(), "Login failed with reason: Bad credentials"),
22+
}
23+
})
24+
.await
25+
.unwrap();
1826
}

playback/src/config.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use super::player::NormalisationData;
12
use crate::convert::i24;
23
pub use crate::dither::{Ditherer, DithererBuilder};
34
pub use crate::shape_noise::{NoiseShaper, NoiseShaperBuilder};
5+
46
use std::convert::TryFrom;
57
use std::mem;
68
use std::str::FromStr;
@@ -146,7 +148,7 @@ impl Default for PlayerConfig {
146148
normalisation_type: NormalisationType::default(),
147149
normalisation_method: NormalisationMethod::default(),
148150
normalisation_pregain: 0.0,
149-
normalisation_threshold: -1.0,
151+
normalisation_threshold: NormalisationData::db_to_ratio(-1.0),
150152
normalisation_attack: 0.005,
151153
normalisation_release: 0.1,
152154
normalisation_knee: 1.0,

playback/src/player.rs

+4
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ impl NormalisationData {
235235
}
236236

237237
fn get_factor(config: &PlayerConfig, data: NormalisationData) -> f32 {
238+
if !config.normalisation {
239+
return 1.0;
240+
}
241+
238242
let [gain_db, gain_peak] = match config.normalisation_type {
239243
NormalisationType::Album => [data.album_gain_db, data.album_peak],
240244
NormalisationType::Track => [data.track_gain_db, data.track_peak],

src/main.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -567,26 +567,24 @@ fn get_setup(args: &[String]) -> Setup {
567567
.opt_str("normalisation-pregain")
568568
.map(|pregain| pregain.parse::<f32>().expect("Invalid pregain float value"))
569569
.unwrap_or(PlayerConfig::default().normalisation_pregain);
570-
let normalisation_threshold = NormalisationData::db_to_ratio(
571-
matches
572-
.opt_str("normalisation-threshold")
573-
.map(|threshold| {
570+
let normalisation_threshold = matches
571+
.opt_str("normalisation-threshold")
572+
.map(|threshold| {
573+
NormalisationData::db_to_ratio(
574574
threshold
575575
.parse::<f32>()
576-
.expect("Invalid threshold float value")
577-
})
578-
.unwrap_or(PlayerConfig::default().normalisation_threshold),
579-
);
576+
.expect("Invalid threshold float value"),
577+
)
578+
})
579+
.unwrap_or(PlayerConfig::default().normalisation_threshold);
580580
let normalisation_attack = matches
581581
.opt_str("normalisation-attack")
582-
.map(|attack| attack.parse::<f32>().expect("Invalid attack float value"))
583-
.unwrap_or(PlayerConfig::default().normalisation_attack * MILLIS)
584-
/ MILLIS;
582+
.map(|attack| attack.parse::<f32>().expect("Invalid attack float value") / MILLIS)
583+
.unwrap_or(PlayerConfig::default().normalisation_attack);
585584
let normalisation_release = matches
586585
.opt_str("normalisation-release")
587-
.map(|release| release.parse::<f32>().expect("Invalid release float value"))
588-
.unwrap_or(PlayerConfig::default().normalisation_release * MILLIS)
589-
/ MILLIS;
586+
.map(|release| release.parse::<f32>().expect("Invalid release float value") / MILLIS)
587+
.unwrap_or(PlayerConfig::default().normalisation_release);
590588
let normalisation_knee = matches
591589
.opt_str("normalisation-knee")
592590
.map(|knee| knee.parse::<f32>().expect("Invalid knee float value"))

0 commit comments

Comments
 (0)