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();
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();
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);