diff options
author | Kostya Shishkov <kostya.shishkov@gmail.com> | 2020-10-12 18:40:28 +0200 |
---|---|---|
committer | Kostya Shishkov <kostya.shishkov@gmail.com> | 2020-10-12 18:40:28 +0200 |
commit | 9a5f37d5d943cbf76313f7fd87b496f6de1f65a7 (patch) | |
tree | 4756a6f5cce432e6b535d4eaf029a5d2fc1b935c | |
parent | 9085eaaf97847df9e3bdcd40979a847d0f4b382b (diff) | |
download | nihav-9a5f37d5d943cbf76313f7fd87b496f6de1f65a7.tar.gz |
core/soundcvt: fix convertsion of certain sample types
-rw-r--r-- | nihav-core/src/soundcvt/mod.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/nihav-core/src/soundcvt/mod.rs b/nihav-core/src/soundcvt/mod.rs index b218e4a..f107925 100644 --- a/nihav-core/src/soundcvt/mod.rs +++ b/nihav-core/src/soundcvt/mod.rs @@ -97,10 +97,10 @@ impl FromFmt<u8> for u8 { fn cvt_from(val: u8) -> u8 { val } } impl FromFmt<u8> for i16 { - fn cvt_from(val: u8) -> i16 { (i16::from(val) - 128).wrapping_mul(0x101) } + fn cvt_from(val: u8) -> i16 { u16::from(val ^ 0x80).wrapping_mul(0x101) as i16} } impl FromFmt<u8> for i32 { - fn cvt_from(val: u8) -> i32 { (i32::from(val) - 128).wrapping_mul(0x01010101) } + fn cvt_from(val: u8) -> i32 { u32::from(val ^ 0x80).wrapping_mul(0x01010101) as i32 } } impl FromFmt<u8> for f32 { fn cvt_from(val: u8) -> f32 { (f32::from(val) - 128.0) / 128.0 } @@ -113,7 +113,7 @@ impl FromFmt<i16> for i16 { fn cvt_from(val: i16) -> i16 { val } } impl FromFmt<i16> for i32 { - fn cvt_from(val: i16) -> i32 { i32::from(val).wrapping_mul(0x10001) } + fn cvt_from(val: i16) -> i32 { (i32::from(val) & 0xFFFF) | (i32::from(val) << 16) } } impl FromFmt<i16> for f32 { fn cvt_from(val: i16) -> f32 { f32::from(val) / 32768.0 } @@ -136,7 +136,7 @@ impl FromFmt<f32> for u8 { fn cvt_from(val: f32) -> u8 { ((val * 128.0) + 128.0).min(255.0).max(0.0) as u8 } } impl FromFmt<f32> for i16 { - fn cvt_from(val: f32) -> i16 { (val * 32768.0).min(16383.0).max(-16384.0) as i16 } + fn cvt_from(val: f32) -> i16 { (val * 32768.0).min(32767.0).max(-32768.0) as i16 } } impl FromFmt<f32> for i32 { fn cvt_from(val: f32) -> i32 { (val * 31.0f32.exp2()) as i32 } |