X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-core%2Fsrc%2Fsoundcvt%2Fmod.rs;h=9db0b797d45aa79a70141f4123abf9bdf5569a32;hb=2890938d5fde1e6d3706e1480857f455815fd4dc;hp=f206ba23300331644fc46298172bc2abe5657f44;hpb=47f26235350744ebf034ff18467e449a249f7703;p=nihav.git diff --git a/nihav-core/src/soundcvt/mod.rs b/nihav-core/src/soundcvt/mod.rs index f206ba2..9db0b79 100644 --- a/nihav-core/src/soundcvt/mod.rs +++ b/nihav-core/src/soundcvt/mod.rs @@ -16,12 +16,14 @@ enum ChannelOp { Passthrough, Reorder(Vec), Remix(Vec), + DupMono(Vec), } impl ChannelOp { fn is_remix(&self) -> bool { match *self { ChannelOp::Remix(_) => true, + ChannelOp::DupMono(_) => true, _ => false, } } @@ -52,6 +54,12 @@ fn remix_i32(ch_op: &ChannelOp, src: &Vec, dst: &mut Vec) { *out = sum as i32; } } + if let ChannelOp::DupMono(ref dup_mat) = ch_op { + let src = src[0]; + for (out, copy) in dst.iter_mut().zip(dup_mat.iter()) { + *out = if *copy { src } else { 0 }; + } + } } fn remix_f32(ch_op: &ChannelOp, src: &Vec, dst: &mut Vec) { @@ -65,6 +73,12 @@ fn remix_f32(ch_op: &ChannelOp, src: &Vec, dst: &mut Vec) { *out = sum; } } + if let ChannelOp::DupMono(ref dup_mat) = ch_op { + let src = src[0]; + for (out, copy) in dst.iter_mut().zip(dup_mat.iter()) { + *out = if *copy { src } else { 0.0 }; + } + } } fn read_samples(src: &NAAudioBuffer, mut idx: usize, dst: &mut Vec) { @@ -84,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 } @@ -100,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 } @@ -255,9 +269,20 @@ Result { } else if needs_reorder { let reorder_mat = calculate_reorder_matrix(src_chmap, dst_chmap); ChannelOp::Reorder(reorder_mat) - } else { + } else if src_chmap.num_channels() > 1 { let remix_mat = calculate_remix_matrix(src_chmap, dst_chmap); ChannelOp::Remix(remix_mat) + } else { + let mut dup_mat: Vec = Vec::with_capacity(dst_chmap.num_channels()); + for i in 0..dst_chmap.num_channels() { + let ch = dst_chmap.get_channel(i); + if ch.is_left() || ch.is_right() || ch == NAChannelType::C { + dup_mat.push(true); + } else { + dup_mat.push(false); + } + } + ChannelOp::DupMono(dup_mat) }; let src_fmt = src_info.get_format();