]> git.nihav.org Git - nihav-player.git/commitdiff
use clamp() where appropriate
authorKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 9 Oct 2025 16:11:50 +0000 (18:11 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 9 Oct 2025 16:22:45 +0000 (18:22 +0200)
sndplay/src/main.rs
videoplayer/src/audiodec.rs

index 78f8fcfe8cc19a0c5fb55935fa199d57d0a7af30..f829f635610ca6f48ef36e902d50838e743a5156 100644 (file)
@@ -112,7 +112,7 @@ fn output_vol_i16(device: &AudioDevice, tmp: &mut Vec<i16>, 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<i16>, 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();
index 1f5c52ecc3142b016b743b12f772346c1f5c69a2..726758ef468ae7913c39ac2c8548d67d3de3bc19 100644 (file)
@@ -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);