From: Kostya Shishkov Date: Wed, 27 Nov 2019 14:04:14 +0000 (+0100) Subject: core/soundcvt: use wrapping mul in sample width extension X-Git-Url: https://git.nihav.org/?p=nihav.git;a=commitdiff_plain;h=ff8cb3aa6ed9cafb4378401406d0081fbba079bf core/soundcvt: use wrapping mul in sample width extension --- diff --git a/nihav-core/src/soundcvt/mod.rs b/nihav-core/src/soundcvt/mod.rs index b9030f3..9db0b79 100644 --- a/nihav-core/src/soundcvt/mod.rs +++ b/nihav-core/src/soundcvt/mod.rs @@ -98,10 +98,10 @@ impl FromFmt for u8 { fn cvt_from(val: u8) -> u8 { val } } impl FromFmt for i16 { - fn cvt_from(val: u8) -> i16 { ((val as i16) - 128) * 0x101 } + fn cvt_from(val: u8) -> i16 { ((val as i16) - 128).wrapping_mul(0x101) } } impl FromFmt for i32 { - fn cvt_from(val: u8) -> i32 { ((val as i32) - 128) * 0x01010101 } + fn cvt_from(val: u8) -> i32 { ((val as i32) - 128).wrapping_mul(0x01010101) } } impl FromFmt for f32 { fn cvt_from(val: u8) -> f32 { ((val as f32) - 128.0) / 128.0 } @@ -114,7 +114,7 @@ impl FromFmt for i16 { fn cvt_from(val: i16) -> i16 { val } } impl FromFmt for i32 { - fn cvt_from(val: i16) -> i32 { (val as i32) * 0x10001 } + fn cvt_from(val: i16) -> i32 { (val as i32).wrapping_mul(0x10001) } } impl FromFmt for f32 { fn cvt_from(val: i16) -> f32 { (val as f32) / 32768.0 } @@ -182,7 +182,6 @@ fn read_packed(src: &NAAudioBuffer, idx: usize, dst: &mut Vec, fm for el in dst.iter_mut() { let src = &data[offset..]; *el = if !fmt.float { -println!("fmt = {} bytes, be: {}", fmt.bits, fmt.be); match (bytes, fmt.be) { (1, _) => src[0].cvt_into(), (2, true) => (read_u16be(src).unwrap() as i16).cvt_into(),