Passthrough,
Reorder(Vec<usize>),
Remix(Vec<f32>),
+ DupMono(Vec<bool>),
}
impl ChannelOp {
fn is_remix(&self) -> bool {
match *self {
ChannelOp::Remix(_) => true,
+ ChannelOp::DupMono(_) => true,
_ => false,
}
}
*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<f32>, dst: &mut Vec<f32>) {
*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<T:Copy>(src: &NAAudioBuffer<T>, mut idx: usize, dst: &mut Vec<T>) {
fn cvt_from(val: u8) -> u8 { val }
}
impl FromFmt<u8> 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<u8> 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<u8> for f32 {
fn cvt_from(val: u8) -> f32 { ((val as f32) - 128.0) / 128.0 }
fn cvt_from(val: i16) -> i16 { val }
}
impl FromFmt<i16> 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<i16> for f32 {
fn cvt_from(val: i16) -> f32 { (val as f32) / 32768.0 }
} 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<bool> = 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();