Upgrade to librespot 0.3.0

- logarithmic volume conversion is now done by librespot
- use default normalisation threshold
This commit is contained in:
Henrik Friedrichsen
2021-10-14 23:41:00 +02:00
parent d446471779
commit 0c69e991b8
4 changed files with 228 additions and 240 deletions

431
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -24,9 +24,9 @@ fern = "0.6"
futures = { version = "0.3", features = ["compat"] }
futures_01 = { version = "0.1", package = "futures" }
lazy_static = "1.3.0"
librespot-core = { version = "0.2.0", features = ["apresolve"] }
librespot-playback = "0.2.0"
librespot-protocol = "0.2.0"
librespot-core = "0.3.0"
librespot-playback = "0.3.0"
librespot-protocol = "0.3.0"
log = "0.4.13"
notify-rust = { version = "4", optional = true }
rspotify = { version = "0.10.0", features = ["blocking"] }

View File

@@ -27,7 +27,7 @@ pub struct ConfigValues {
pub backend: Option<String>,
pub backend_device: Option<String>,
pub volnorm: Option<bool>,
pub volnorm_pregain: Option<f32>,
pub volnorm_pregain: Option<f64>,
pub notify: Option<bool>,
pub bitrate: Option<u32>,
pub album_column: Option<bool>,

View File

@@ -4,7 +4,8 @@ use librespot_core::config::SessionConfig;
use librespot_core::session::Session;
use librespot_core::session::SessionError;
use librespot_playback::config::PlayerConfig;
use librespot_playback::player::NormalisationData;
use librespot_playback::mixer::softmixer::SoftMixer;
use librespot_playback::mixer::MixerConfig;
use log::{debug, error, info};
use librespot_playback::audio_backend;
@@ -181,9 +182,6 @@ impl Spotify {
bitrate: bitrate.unwrap_or(Bitrate::Bitrate320),
normalisation: cfg.values().volnorm.unwrap_or(false),
normalisation_pregain: cfg.values().volnorm_pregain.unwrap_or(0.0),
normalisation_threshold: NormalisationData::db_to_ratio(
PlayerConfig::default().normalisation_threshold,
),
..Default::default()
};
@@ -192,9 +190,9 @@ impl Spotify {
.expect("Could not create session");
user_tx.map(|tx| tx.send(session.username()));
let create_mixer = librespot_playback::mixer::find(Some("softvol".to_owned()))
let create_mixer = librespot_playback::mixer::find(Some(SoftMixer::NAME))
.expect("could not create softvol mixer");
let mixer = create_mixer(None);
let mixer = create_mixer(MixerConfig::default());
mixer.set_volume(volume);
let backend = audio_backend::find(cfg.values().backend.clone()).unwrap();
@@ -354,27 +352,10 @@ impl Spotify {
self.cfg.state().volume
}
fn log_scale(volume: u16) -> u16 {
// https://www.dr-lex.be/info-stuff/volumecontrols.html#ideal2
// a * exp(b * x)
const A: f64 = 1.0 / 1000.0;
const B: f64 = 6.908;
let volume_percent = volume as f64 / u16::max_value() as f64;
let log_volume = A * (B * volume_percent).exp();
let result = log_volume * u16::max_value() as f64;
// u16 overflow check
if result > u16::max_value() as f64 {
u16::max_value()
} else {
result as u16
}
}
pub fn set_volume(&self, volume: u16) {
info!("setting volume to {}", volume);
self.cfg.with_state_mut(|mut s| s.volume = volume);
self.send_worker(WorkerCommand::SetVolume(Self::log_scale(volume)));
self.send_worker(WorkerCommand::SetVolume(volume));
}
pub fn preload(&self, track: &Playable) {