1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-05 10:49:40 +02:00

perf(playback): optimize audio conversion with 16-bit dithering and bit shifts

Since Spotify audio is always 16-bit depth, optimize the conversion pipeline:
- Always dither at 16-bit level regardless of output format
- Preserve fractional precision until final rounding for better requantization
- Replace floating-point multiplication with compile-time bit shifts
- Add comprehensive inlining to eliminate function call overhead
- Specialize 24-bit clamping to remove runtime branching

This maintains proper dithering of the original 16-bit quantization artifacts
while maximizing performance through bit-shift operations and eliminating
unnecessary runtime calculations.
This commit is contained in:
Roderick van Domburg 2025-08-14 00:31:59 +02:00
parent 218eced556
commit f59766af7e
No known key found for this signature in database
GPG key ID: 607FA06CB5236AE0
3 changed files with 61 additions and 38 deletions

View file

@ -64,6 +64,7 @@ impl Ditherer for TriangularDitherer {
Self::NAME
}
#[inline]
fn noise(&mut self) -> f64 {
self.distribution.sample(&mut self.cached_rng)
}
@ -98,6 +99,7 @@ impl Ditherer for GaussianDitherer {
Self::NAME
}
#[inline]
fn noise(&mut self) -> f64 {
self.distribution.sample(&mut self.cached_rng)
}
@ -130,6 +132,7 @@ impl Ditherer for HighPassDitherer {
Self::NAME
}
#[inline]
fn noise(&mut self) -> f64 {
let new_noise = self.distribution.sample(&mut self.cached_rng);
let high_passed_noise = new_noise - self.previous_noises[self.active_channel];