data: vec![0.into(); rec_size * channels],
}
}
- fn get_cur_size(&self) -> usize { self.end - self.start }
+ fn get_cur_size(&self) -> usize {
+ let size = self.end - self.start;
+ if !self.ileaved {
+ size
+ } else {
+ size / self.channels
+ }
+ }
fn get_cur_avail(&self) -> usize { self.stride - self.end }
fn get_potentially_avail(&self) -> usize { self.stride - self.get_cur_size() }
fn read(&mut self, src: &NAAudioBuffer<T>) {
return;
}
}
- for (dst, src) in self.data.chunks_exact_mut(self.stride).zip(src.get_data().chunks_exact(src.get_stride())) {
- dst[self.end..][..to_copy].copy_from_slice(&src[..to_copy]);
- }
+ match (src.get_step() != 1, self.ileaved) {
+ (false, false) => {
+ for (dst, src) in self.data.chunks_exact_mut(self.stride).zip(src.get_data().chunks_exact(src.get_stride())) {
+ dst[self.end..][..to_copy].copy_from_slice(&src[..to_copy]);
+ }
+ },
+ (true, false) => {
+ for (i, chunk) in src.get_data().chunks_exact(src.get_step()).enumerate() {
+ for (ch, &samp) in chunk.iter().enumerate() {
+ self.data[self.stride * ch + self.end + i] = samp;
+ }
+ }
+ }
+ (true, true) => {
+ let sdata = src.get_data();
+ self.data[self.end..][..to_copy].copy_from_slice(&sdata[..to_copy]);
+ },
+ _ => unimplemented!(),
+ };
self.end += to_copy;
}
fn write(&mut self, dbuf: &mut NAAudioBuffer<T>) {
- let dst_len = dbuf.get_length();
+ let mut dst_len = dbuf.get_length();
let dst_stride = dbuf.get_stride();
+ let dst_step = dbuf.get_step();
let dst = dbuf.get_data_mut().unwrap();
- for (dst, src) in dst.chunks_mut(dst_stride).zip(self.data.chunks_exact(self.stride)) {
- dst[..dst_len].copy_from_slice(&src[self.start..][..dst_len]);
- }
+ match (self.ileaved, dst_step != 1) {
+ (false, false) => {
+ for (dst, src) in dst.chunks_mut(dst_stride).zip(self.data.chunks_exact(self.stride)) {
+ dst[..dst_len].copy_from_slice(&src[self.start..][..dst_len]);
+ }
+ },
+ (true, true) => {
+ dst_len *= self.channels;
+ dst[..dst_len].copy_from_slice(&self.data[self.start..][..dst_len]);
+ },
+ _ => unimplemented!(),
+ };
self.start += dst_len;
}
fn renorm(&mut self) {