Skip to content

Commit ea9fe49

Browse files
hobokennYaLTeR
authored andcommitted
capture: Use wrapping multiplication for sample pairs
It was overflowing because of the bugged gauss charge sound in the Steam version.
1 parent c2175be commit ea9fe49

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/modules/capture/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,12 @@ pub unsafe fn on_s_transfer_stereo_16(marker: MainThreadMarker, end: i32) {
427427
.zip(buf.chunks_exact_mut(4))
428428
{
429429
// Clamping as done in Snd_WriteLinearBlastStereo16().
430-
let l16 = ((sample.left * volume) >> 8).min(32767).max(-32768) as i16;
431-
let r16 = ((sample.right * volume) >> 8).min(32767).max(-32768) as i16;
430+
let l16 = ((sample.left.wrapping_mul(volume)) >> 8)
431+
.min(32767)
432+
.max(-32768) as i16;
433+
let r16 = ((sample.right.wrapping_mul(volume)) >> 8)
434+
.min(32767)
435+
.max(-32768) as i16;
432436

433437
buf[0..2].copy_from_slice(&l16.to_le_bytes());
434438
buf[2..4].copy_from_slice(&r16.to_le_bytes());

0 commit comments

Comments
 (0)