Skip to content

Commit e6366b6

Browse files
committed
feat: add support for S24 output format and improve dithering
1 parent bd57228 commit e6366b6

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ and [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
77

88
## Unreleased
99

10+
### Added
11+
- [player] Support S24 output format (24-bit signed integer stored on 4 bytes)
12+
1013
### Changed
1114
- [deps] Switched from rustls to system native TLS
1215

16+
### Fixed
17+
- [dither] Correctly round dithered samples for lower noise floor
18+
1319
## [v0.19.1] - 2025-07-27
1420

1521
### Fixed

src/player.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,14 +653,14 @@ impl Player {
653653
})
654654
.or_else(|| {
655655
// Set a default dithering level
656-
use cpal::SampleFormat::{I8, I16, I32, I64, U8, U16, U32, U64};
656+
use cpal::SampleFormat::{I8, I16, I24, I32, I64, U8, U16, U32, U64};
657657
let bits = match device_config.sample_format() {
658658
// Very low fidelity, e.g., legacy or telephony
659659
I8 | U8 => 7.0,
660660
// Most DACs handling 16-bit do not achieve a true 16-bit SINAD
661661
I16 | U16 => 15.5,
662662
// Good delta-sigma DACs max out around 20–21 bits; 19.5 is safe
663-
I32 | U32 => 19.5,
663+
I24 | I32 | U32 => 19.5,
664664
// No DAC supports more, this is purely for internal formats
665665
I64 | U64 => 24.0,
666666
// Floating point usually gets quantized later - don't dither here
@@ -734,10 +734,12 @@ impl Player {
734734
///
735735
/// Only includes the three most common sample formats:
736736
/// * I16 - 16-bit signed integer
737+
/// * I24 - 24-bit signed integer (stored in 4 bytes)
737738
/// * I32 - 32-bit signed integer
738739
/// * F32 - 32-bit floating point
739-
const SAMPLE_FORMATS: [cpal::SampleFormat; 3] = [
740+
const SAMPLE_FORMATS: [cpal::SampleFormat; 4] = [
740741
cpal::SampleFormat::I16,
742+
cpal::SampleFormat::I24,
741743
cpal::SampleFormat::I32,
742744
cpal::SampleFormat::F32,
743745
];
@@ -754,6 +756,7 @@ impl Player {
754756
/// - 44.1 kHz (CD audio, streaming services)
755757
/// - 48 kHz (professional audio, video production)
756758
/// - I16 (16-bit integer)
759+
/// - I24 (24-bit integer stored in 4 bytes)
757760
/// - I32 (32-bit integer)
758761
/// - F32 (32-bit float)
759762
/// * Stereo output (2 channels)

0 commit comments

Comments
 (0)