feat(rodio): change SymphoniaDecoder output from i16 to f32

Change SampleBuffer<i16> to SampleBuffer<f32> in the vendored rodio
decoder. This preserves 24-bit audio data (f32 has 24 bits of
significand) instead of truncating to 16-bit at decode time.

Affects: symphonia.rs (SampleBuffer, Iterator::Item)
         mod.rs (Decoder, LoopedDecoder, DecoderImpl Iterator::Item)
This commit is contained in:
vicrodh committed 2026-02-05 16:16:34 -06:00
1 parent c0508c8050
commit ba828866ef
2 files changed
+10 -10

No files matched your search

+5 -5
View File
@@ -62,7 +62,7 @@ where
impl<R: Read + Seek> DecoderImpl<R> {
#[inline]
fn next(&mut self) -> Option<i16> {
fn next(&mut self) -> Option<f32> {
match self {
#[cfg(all(feature = "wav", not(feature = "symphonia-wav")))]
DecoderImpl::Wav(source) => source.next(),
@@ -385,10 +385,10 @@ impl<R> Iterator for Decoder<R>
where
R: Read + Seek,
{
type Item = i16;
type Item = f32;
#[inline]
fn next(&mut self) -> Option<i16> {
fn next(&mut self) -> Option<f32> {
self.0.next()
}
@@ -431,10 +431,10 @@ impl<R> Iterator for LoopedDecoder<R>
where
R: Read + Seek,
{
type Item = i16;
type Item = f32;
#[inline]
fn next(&mut self) -> Option<i16> {
fn next(&mut self) -> Option<f32> {
if let Some(sample) = self.0.next() {
Some(sample)
} else {
+5 -5
View File
@@ -27,7 +27,7 @@ pub(crate) struct SymphoniaDecoder {
current_frame_offset: usize,
format: Box<dyn FormatReader>,
total_duration: Option<Time>,
buffer: SampleBuffer<i16>,
buffer: SampleBuffer<f32>,
spec: SignalSpec,
}
@@ -143,9 +143,9 @@ impl SymphoniaDecoder {
}
#[inline]
fn get_buffer(decoded: AudioBufferRef, spec: &SignalSpec) -> SampleBuffer<i16> {
fn get_buffer(decoded: AudioBufferRef, spec: &SignalSpec) -> SampleBuffer<f32> {
let duration = units::Duration::from(decoded.capacity() as u64);
let mut buffer = SampleBuffer::<i16>::new(duration, *spec);
let mut buffer = SampleBuffer::<f32>::new(duration, *spec);
buffer.copy_interleaved_ref(decoded);
buffer
}
@@ -264,10 +264,10 @@ fn skip_back_a_tiny_bit(
}
impl Iterator for SymphoniaDecoder {
type Item = i16;
type Item = f32;
#[inline]
fn next(&mut self) -> Option<i16> {
fn next(&mut self) -> Option<f32> {
if self.current_frame_offset >= self.buffer.len() {
let packet = self.format.next_packet().ok()?;
let mut decoded = self.decoder.decode(&packet);