From: Kostya Shishkov Date: Thu, 9 Oct 2025 16:11:50 +0000 (+0200) Subject: use clamp() where appropriate X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=b575a91275e881b8382b2cadf38c1750508bfe64;p=nihav-player.git use clamp() where appropriate --- diff --git a/sndplay/src/main.rs b/sndplay/src/main.rs index 78f8fcf..f829f63 100644 --- a/sndplay/src/main.rs +++ b/sndplay/src/main.rs @@ -112,7 +112,7 @@ fn output_vol_i16(device: &AudioDevice, tmp: &mut Vec, src: &[i16], mute: b let vol = i32::from(volume); for &sample in src.iter() { let nsamp = vol * i32::from(sample) / 100; - tmp.push(nsamp.min(32767).max(-32768) as i16); + tmp.push(nsamp.clamp(-32768, 32767) as i16); } } else { tmp.clear(); @@ -129,7 +129,7 @@ fn output_vol_u8(device: &AudioDevice, tmp: &mut Vec, src: &[u8], mute: boo for sample in src.chunks_exact(2) { let sample = (u16::from(sample[0]) + u16::from(sample[1]) * 256) as i16; let nsamp = vol * i32::from(sample) / 100; - tmp.push(nsamp.min(32767).max(-32768) as i16); + tmp.push(nsamp.clamp(-32768, 32767) as i16); } } else { tmp.clear(); diff --git a/videoplayer/src/audiodec.rs b/videoplayer/src/audiodec.rs index 1f5c52e..726758e 100644 --- a/videoplayer/src/audiodec.rs +++ b/videoplayer/src/audiodec.rs @@ -130,7 +130,7 @@ impl AudioCallback for AudioOutput { out[..copylen].copy_from_slice(&queue.queue[queue.start..][..copylen]); } else { for (dst, &src) in out[..copylen].iter_mut().zip(queue.queue[queue.start..].iter()) { - *dst = (i32::from(src) * volume / 100).max(-32768).min(32767) as i16; + *dst = (i32::from(src) * volume / 100).clamp(-32768, 32767) as i16; } } queue.drain(copylen);