Skip to content

Commit efec96b

Browse files
committed
Put it all together
1 parent e1ea400 commit efec96b

File tree

12 files changed

+152
-314
lines changed

12 files changed

+152
-314
lines changed

playback/src/audio_backend/gstreamer.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ use std::sync::Arc;
1313

1414
use super::{Open, Sink, SinkAsBytes, SinkError, SinkResult};
1515

16-
use crate::{
17-
config::AudioFormat, convert::Converter, decoder::AudioPacket, NUM_CHANNELS,
18-
};
16+
use crate::{config::AudioFormat, convert::Converter, decoder::AudioPacket, NUM_CHANNELS};
1917

2018
pub struct GstreamerSink {
2119
appsrc: gst_app::AppSrc,

playback/src/audio_backend/jackaudio.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ impl Open for JackSink {
4242
if format != AudioFormat::F32 {
4343
warn!("JACK currently does not support {format:?} output");
4444
}
45-
info!("Using JACK sink with format {:?}, sample rate: {sample_rate}", AudioFormat::F32);
45+
info!(
46+
"Using JACK sink with format {:?}, sample rate: {sample_rate}",
47+
AudioFormat::F32
48+
);
4649

4750
let client_name = client_name.unwrap_or_else(|| "librespot".to_string());
4851
let (client, _status) =

playback/src/audio_backend/portaudio.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,15 @@ impl<'a> Sink for PortAudioSink<'a> {
119119
}
120120

121121
match self {
122-
Self::F32(stream, parameters, sample_rate) => start_sink!(ref mut stream, ref parameters, ref sample_rate),
123-
Self::S32(stream, parameters, sample_rate) => start_sink!(ref mut stream, ref parameters, ref sample_rate),
124-
Self::S16(stream, parameters, sample_rate) => start_sink!(ref mut stream, ref parameters, ref sample_rate),
122+
Self::F32(stream, parameters, sample_rate) => {
123+
start_sink!(ref mut stream, ref parameters, ref sample_rate)
124+
}
125+
Self::S32(stream, parameters, sample_rate) => {
126+
start_sink!(ref mut stream, ref parameters, ref sample_rate)
127+
}
128+
Self::S16(stream, parameters, sample_rate) => {
129+
start_sink!(ref mut stream, ref parameters, ref sample_rate)
130+
}
125131
};
126132

127133
Ok(())

playback/src/audio_backend/rodio.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ pub fn mk_rodio(device: Option<String>, format: AudioFormat, sample_rate: u32) -
2323
}
2424

2525
#[cfg(feature = "rodiojack-backend")]
26-
pub fn mk_rodiojack(device: Option<String>, format: AudioFormat, sample_rate: u32) -> Box<dyn Sink> {
26+
pub fn mk_rodiojack(
27+
device: Option<String>,
28+
format: AudioFormat,
29+
sample_rate: u32,
30+
) -> Box<dyn Sink> {
2731
Box::new(open(
2832
cpal::host_from_id(cpal::HostId::Jack).unwrap(),
2933
device,
@@ -166,7 +170,12 @@ fn create_sink(
166170
Ok((sink, stream))
167171
}
168172

169-
pub fn open(host: cpal::Host, device: Option<String>, format: AudioFormat, sample_rate: u32) -> RodioSink {
173+
pub fn open(
174+
host: cpal::Host,
175+
device: Option<String>,
176+
format: AudioFormat,
177+
sample_rate: u32,
178+
) -> RodioSink {
170179
info!(
171180
"Using Rodio sink with format {format:?} and cpal host: {}",
172181
host.id().name()

playback/src/config.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{mem, str::FromStr, time::Duration};
22

33
pub use crate::dither::{mk_ditherer, DithererBuilder, TriangularDitherer};
4-
use crate::{convert::i24, player::duration_to_coefficient, RESAMPLER_INPUT_SIZE, SAMPLE_RATE};
4+
use crate::{convert::i24, RESAMPLER_INPUT_SIZE, SAMPLE_RATE};
55

66
// Reciprocals allow us to multiply instead of divide during interpolation.
77
const HZ48000_RESAMPLE_FACTOR_RECIPROCAL: f64 = SAMPLE_RATE as f64 / 48_000.0;
@@ -152,10 +152,12 @@ impl FromStr for SampleRate {
152152
fn from_str(s: &str) -> Result<Self, Self::Err> {
153153
use SampleRate::*;
154154

155+
let lowercase_input = s.to_lowercase();
156+
155157
// Match against both the actual
156158
// stringified value and how most
157159
// humans would write a sample rate.
158-
match s.to_uppercase().as_ref() {
160+
match lowercase_input.as_str() {
159161
"hz44100" | "44100hz" | "44100" | "44.1khz" => Ok(Hz44100),
160162
"hz48000" | "48000hz" | "48000" | "48khz" => Ok(Hz48000),
161163
"hz88200" | "88200hz" | "88200" | "88.2khz" => Ok(Hz88200),
@@ -348,6 +350,9 @@ pub struct PlayerConfig {
348350
pub gapless: bool,
349351
pub passthrough: bool,
350352

353+
pub interpolation_quality: InterpolationQuality,
354+
pub sample_rate: SampleRate,
355+
351356
pub normalisation: bool,
352357
pub normalisation_type: NormalisationType,
353358
pub normalisation_method: NormalisationMethod,
@@ -368,12 +373,17 @@ impl Default for PlayerConfig {
368373
bitrate: Bitrate::default(),
369374
gapless: true,
370375
normalisation: false,
376+
interpolation_quality: InterpolationQuality::default(),
377+
sample_rate: SampleRate::default(),
371378
normalisation_type: NormalisationType::default(),
372379
normalisation_method: NormalisationMethod::default(),
373380
normalisation_pregain_db: 0.0,
374381
normalisation_threshold_dbfs: -2.0,
375-
normalisation_attack_cf: duration_to_coefficient(Duration::from_millis(5)),
376-
normalisation_release_cf: duration_to_coefficient(Duration::from_millis(100)),
382+
// Dummy value. We can't use the default because
383+
// no matter what it's dependent on the sample rate.
384+
normalisation_attack_cf: 0.0,
385+
// Same with release.
386+
normalisation_release_cf: 0.0,
377387
normalisation_knee_db: 5.0,
378388
passthrough: false,
379389
ditherer: Some(mk_ditherer::<TriangularDitherer>),

playback/src/mixer/alsamixer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::player::{db_to_ratio, ratio_to_db};
1+
use crate::{db_to_ratio, ratio_to_db};
22

33
use super::mappings::{LogMapping, MappedCtrl, VolumeMapping};
44
use super::{Mixer, MixerConfig, VolumeCtrl};

playback/src/mixer/mappings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::VolumeCtrl;
2-
use crate::player::db_to_ratio;
2+
use crate::db_to_ratio;
33

44
pub trait MappedCtrl {
55
fn to_mapped(&self, volume: u16) -> f64;

playback/src/mixer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ pub trait Mixer: Send {
1313
fn set_volume(&self, volume: u16);
1414
fn volume(&self) -> u16;
1515

16-
fn get_soft_volume(&self) -> Box<dyn VolumeGetter + Send> {
16+
fn get_soft_volume(&self) -> Box<dyn VolumeGetter> {
1717
Box::new(NoOpVolume)
1818
}
1919
}
2020

21-
pub trait VolumeGetter {
21+
pub trait VolumeGetter: Send {
2222
fn attenuation_factor(&self) -> f64;
2323
}
2424

playback/src/mixer/softmixer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Mixer for SoftMixer {
3535
.store(mapped_volume.to_bits(), Ordering::Relaxed)
3636
}
3737

38-
fn get_soft_volume(&self) -> Box<dyn VolumeGetter + Send> {
38+
fn get_soft_volume(&self) -> Box<dyn VolumeGetter> {
3939
Box::new(SoftVolume(self.volume.clone()))
4040
}
4141
}

0 commit comments

Comments
 (0)