Skip to content

Commit 5930695

Browse files
authored
mp3, vorbis: Remove sample clamping. (#434)
Remove the [-1.0, 1.0] sample clamping from MP3 and Vorbis decoders to align with FFmpeg behavior and enable accurate peak detection for audio analysis tools. Background: - FFmpeg (the de facto standard) does not clamp decoder output - The AAC decoder in Symphonia already does not clamp - Clamping prevents accurate peak detection for audio analysis tools that need to detect clipping (samples exceeding 0 dBFS) Fixes: #433 Co-authored-by: m_igashi <@M_Igashi>
1 parent 16c641f commit 5930695

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

symphonia-bundle-mp3/src/synthesis.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ pub fn synthesis(state: &mut SynthesisState, n_frames: usize, in_samples: &[f32]
322322
}
323323
}
324324

325-
// Clamp and copy the PCM samples from o_vec to the output buffer.
325+
// Copy the PCM samples from o_vec to the output buffer.
326326
let offset = b << 5;
327327

328328
for (o, s) in out[offset..offset + 32].iter_mut().zip(&o_vec) {
329-
*o = s.clamp(-1.0, 1.0);
329+
*o = *s;
330330
}
331331

332332
// Shift the v_vec FIFO. The value v_front is the index of the 64 sample slot in v_vec

symphonia-codec-vorbis/src/dsp.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ impl DspChannel {
131131
buf[self.bs0 / 2..].copy_from_slice(&self.imdct[end..self.bs1 / 2]);
132132
}
133133

134-
// Clamp the output samples.
135-
for s in buf.iter_mut() {
136-
*s = s.clamp(-1.0, 1.0);
137-
}
138134
}
139135

140136
// Save right-half of IMDCT buffer for later.

0 commit comments

Comments
 (0)