diff --git a/playback/src/audio_backend/alsa.rs b/playback/src/audio_backend/alsa.rs index 0f0fd370..bd2b4bf5 100644 --- a/playback/src/audio_backend/alsa.rs +++ b/playback/src/audio_backend/alsa.rs @@ -452,6 +452,7 @@ impl Sink for AlsaSink { } impl SinkAsBytes for AlsaSink { + #[inline] fn write_bytes(&mut self, data: &[u8]) -> SinkResult<()> { let mut start_index = 0; let data_len = data.len(); diff --git a/playback/src/audio_backend/gstreamer.rs b/playback/src/audio_backend/gstreamer.rs index d4260073..b9087e3d 100644 --- a/playback/src/audio_backend/gstreamer.rs +++ b/playback/src/audio_backend/gstreamer.rs @@ -171,6 +171,7 @@ impl Drop for GstreamerSink { } impl SinkAsBytes for GstreamerSink { + #[inline] fn write_bytes(&mut self, data: &[u8]) -> SinkResult<()> { if let Some(async_error) = &*self.async_error.lock() { return Err(SinkError::OnWrite(async_error.to_string())); diff --git a/playback/src/audio_backend/mod.rs b/playback/src/audio_backend/mod.rs index 739938d3..f8f43e3f 100644 --- a/playback/src/audio_backend/mod.rs +++ b/playback/src/audio_backend/mod.rs @@ -46,6 +46,7 @@ fn mk_sink(device: Option, format: AudioFormat // reuse code for various backends macro_rules! sink_as_bytes { () => { + #[inline] fn write(&mut self, packet: AudioPacket, converter: &mut Converter) -> SinkResult<()> { use crate::convert::i24; use zerocopy::IntoBytes; diff --git a/playback/src/audio_backend/pipe.rs b/playback/src/audio_backend/pipe.rs index 5d8369e5..8dfd21ea 100644 --- a/playback/src/audio_backend/pipe.rs +++ b/playback/src/audio_backend/pipe.rs @@ -96,6 +96,7 @@ impl Sink for StdoutSink { } impl SinkAsBytes for StdoutSink { + #[inline] fn write_bytes(&mut self, data: &[u8]) -> SinkResult<()> { self.output .as_deref_mut() diff --git a/playback/src/audio_backend/pulseaudio.rs b/playback/src/audio_backend/pulseaudio.rs index 90649f94..0cc0850a 100644 --- a/playback/src/audio_backend/pulseaudio.rs +++ b/playback/src/audio_backend/pulseaudio.rs @@ -137,6 +137,7 @@ impl Sink for PulseAudioSink { } impl SinkAsBytes for PulseAudioSink { + #[inline] fn write_bytes(&mut self, data: &[u8]) -> SinkResult<()> { let sink = self.sink.as_mut().ok_or(PulseError::NotConnected)?; diff --git a/playback/src/audio_backend/subprocess.rs b/playback/src/audio_backend/subprocess.rs index 90eed675..c624718b 100644 --- a/playback/src/audio_backend/subprocess.rs +++ b/playback/src/audio_backend/subprocess.rs @@ -139,6 +139,7 @@ impl Sink for SubprocessSink { } impl SinkAsBytes for SubprocessSink { + #[inline] fn write_bytes(&mut self, data: &[u8]) -> SinkResult<()> { // We get one attempted restart per write. // We don't want to get stuck in a restart loop. diff --git a/playback/src/convert.rs b/playback/src/convert.rs index 1fbaab39..31e710da 100644 --- a/playback/src/convert.rs +++ b/playback/src/convert.rs @@ -42,7 +42,6 @@ impl Converter { const SHIFT_S24: u8 = 23; // 24-bit: 2^23 = 8388608 const SHIFT_S32: u8 = 31; // 32-bit: 2^31 = 2147483648 - /// Additional bit shifts needed to scale from 16-bit to higher bit depths. /// These are the differences between the base shift amounts above. const SHIFT_16_TO_24: u8 = Self::SHIFT_S24 - Self::SHIFT_S16; // 23 - 15 = 8 @@ -52,12 +51,12 @@ impl Converter { const SCALE_S24: f64 = (1_u64 << Self::SHIFT_S24) as f64; /// Scale audio samples with optimal dithering strategy for Spotify's 16-bit source material. - /// + /// /// Since Spotify audio is always 16-bit depth, this function: /// 1. When dithering: applies noise at 16-bit level, preserves fractional precision, /// then scales to target format and rounds once at the end /// 2. When not dithering: scales directly from normalized float to target format - /// + /// /// The `shift` parameter specifies how many extra bits to shift beyond /// the base 16-bit scaling (0 for 16-bit, 8 for 24-bit, 16 for 32-bit). #[inline] @@ -85,11 +84,11 @@ impl Converter { #[inline] pub fn clamping_scale_s24(&mut self, sample: f64) -> f64 { let int_value = self.scale(sample, Self::SHIFT_16_TO_24); - + // In two's complement, there are more negative than positive values. let min = -Self::SCALE_S24; let max = Self::SCALE_S24 - 1.0; - + int_value.clamp(min, max) } diff --git a/playback/src/decoder/mod.rs b/playback/src/decoder/mod.rs index f980b680..e77d6e9e 100644 --- a/playback/src/decoder/mod.rs +++ b/playback/src/decoder/mod.rs @@ -36,6 +36,7 @@ pub enum AudioPacket { } impl AudioPacket { + #[inline] pub fn samples(&self) -> AudioPacketResult<&[f64]> { match self { AudioPacket::Samples(s) => Ok(s), @@ -43,6 +44,7 @@ impl AudioPacket { } } + #[inline] pub fn raw(&self) -> AudioPacketResult<&[u8]> { match self { AudioPacket::Raw(d) => Ok(d), @@ -50,6 +52,7 @@ impl AudioPacket { } } + #[inline] pub fn is_empty(&self) -> bool { match self { AudioPacket::Samples(s) => s.is_empty(), diff --git a/playback/src/decoder/symphonia_decoder.rs b/playback/src/decoder/symphonia_decoder.rs index eadb7302..63d49d0f 100644 --- a/playback/src/decoder/symphonia_decoder.rs +++ b/playback/src/decoder/symphonia_decoder.rs @@ -131,6 +131,7 @@ impl SymphoniaDecoder { } } + #[inline] fn ts_to_ms(&self, ts: u64) -> u32 { match self.decoder.codec_params().time_base { Some(time_base) => { diff --git a/playback/src/mixer/mod.rs b/playback/src/mixer/mod.rs index 86252217..89d03235 100644 --- a/playback/src/mixer/mod.rs +++ b/playback/src/mixer/mod.rs @@ -25,6 +25,7 @@ pub trait VolumeGetter { } impl VolumeGetter for NoOpVolume { + #[inline] fn attenuation_factor(&self) -> f64 { 1.0 } diff --git a/playback/src/mixer/softmixer.rs b/playback/src/mixer/softmixer.rs index efb7365d..189fc151 100644 --- a/playback/src/mixer/softmixer.rs +++ b/playback/src/mixer/softmixer.rs @@ -48,6 +48,7 @@ impl SoftMixer { struct SoftVolume(Arc); impl VolumeGetter for SoftVolume { + #[inline] fn attenuation_factor(&self) -> f64 { f64::from_bits(self.0.load(Ordering::Relaxed)) } diff --git a/playback/src/player.rs b/playback/src/player.rs index 0e65f554..bcb6b121 100644 --- a/playback/src/player.rs +++ b/playback/src/player.rs @@ -279,10 +279,12 @@ impl PlayerEvent { pub type PlayerEventChannel = mpsc::UnboundedReceiver; +#[inline] pub fn db_to_ratio(db: f64) -> f64 { f64::powf(10.0, db / DB_VOLTAGE_RATIO) } +#[inline] pub fn ratio_to_db(ratio: f64) -> f64 { ratio.log10() * DB_VOLTAGE_RATIO }