aboutsummaryrefslogtreecommitdiffstats
path: root/nihav-core/src/frame.rs
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2019-11-16 18:32:28 +0100
committerKostya Shishkov <kostya.shishkov@gmail.com>2019-11-16 18:32:28 +0100
commit01e2d49645edae06053dfd64142fae861ec0a945 (patch)
treef7a952e0abd905b5a58f4b5316c750cfedc74509 /nihav-core/src/frame.rs
parenta92a51132747ee570a7c9b2d45fddcfc82cb659b (diff)
downloadnihav-01e2d49645edae06053dfd64142fae861ec0a945.tar.gz
core/frame: introduce stride for planar audio buffers
Diffstat (limited to 'nihav-core/src/frame.rs')
-rw-r--r--nihav-core/src/frame.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs
index 25c3856..d51d226 100644
--- a/nihav-core/src/frame.rs
+++ b/nihav-core/src/frame.rs
@@ -146,6 +146,7 @@ pub struct NAAudioBuffer<T> {
info: NAAudioInfo,
data: NABufferRef<Vec<T>>,
offs: Vec<usize>,
+ stride: usize,
chmap: NAChannelMap,
len: usize,
}
@@ -155,6 +156,7 @@ impl<T: Clone> NAAudioBuffer<T> {
if idx >= self.offs.len() { 0 }
else { self.offs[idx] }
}
+ pub fn get_stride(&self) -> usize { self.stride }
pub fn get_info(&self) -> NAAudioInfo { self.info }
pub fn get_chmap(&self) -> NAChannelMap { self.chmap.clone() }
pub fn get_data(&self) -> &Vec<T> { self.data.as_ref() }
@@ -164,7 +166,7 @@ impl<T: Clone> NAAudioBuffer<T> {
data.clone_from(self.data.as_ref());
let mut offs: Vec<usize> = Vec::with_capacity(self.offs.len());
offs.clone_from(&self.offs);
- NAAudioBuffer { info: self.info, data: NABufferRef::new(data), offs, chmap: self.get_chmap(), len: self.len }
+ NAAudioBuffer { info: self.info, data: NABufferRef::new(data), offs, chmap: self.get_chmap(), len: self.len, stride: self.stride }
}
pub fn get_length(&self) -> usize { self.len }
}
@@ -172,7 +174,7 @@ impl<T: Clone> NAAudioBuffer<T> {
impl NAAudioBuffer<u8> {
pub fn new_from_buf(info: NAAudioInfo, data: NABufferRef<Vec<u8>>, chmap: NAChannelMap) -> Self {
let len = data.len();
- NAAudioBuffer { info, data, chmap, offs: Vec::new(), len }
+ NAAudioBuffer { info, data, chmap, offs: Vec::new(), len, stride: 0 }
}
}
@@ -424,13 +426,14 @@ pub fn alloc_audio_buffer(ainfo: NAAudioInfo, nsamples: usize, chmap: NAChannelM
let len = nsamples.checked_mul(ainfo.channels as usize);
if len == None { return Err(AllocatorError::TooLargeDimensions); }
let length = len.unwrap();
+ let stride = nsamples;
for i in 0..ainfo.channels {
- offs.push((i as usize) * nsamples);
+ offs.push((i as usize) * stride);
}
if ainfo.format.is_float() {
if ainfo.format.get_bits() == 32 {
let data: Vec<f32> = vec![0.0; length];
- let buf: NAAudioBuffer<f32> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples };
+ let buf: NAAudioBuffer<f32> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples, stride };
Ok(NABufferType::AudioF32(buf))
} else {
Err(AllocatorError::TooLargeDimensions)
@@ -438,11 +441,11 @@ pub fn alloc_audio_buffer(ainfo: NAAudioInfo, nsamples: usize, chmap: NAChannelM
} else {
if ainfo.format.get_bits() == 8 && !ainfo.format.is_signed() {
let data: Vec<u8> = vec![0; length];
- let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples };
+ let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples, stride };
Ok(NABufferType::AudioU8(buf))
} else if ainfo.format.get_bits() == 16 && ainfo.format.is_signed() {
let data: Vec<i16> = vec![0; length];
- let buf: NAAudioBuffer<i16> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples };
+ let buf: NAAudioBuffer<i16> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples, stride };
Ok(NABufferType::AudioI16(buf))
} else {
Err(AllocatorError::TooLargeDimensions)
@@ -453,7 +456,7 @@ pub fn alloc_audio_buffer(ainfo: NAAudioInfo, nsamples: usize, chmap: NAChannelM
if len == None { return Err(AllocatorError::TooLargeDimensions); }
let length = ainfo.format.get_audio_size(len.unwrap() as u64);
let data: Vec<u8> = vec![0; length];
- let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples };
+ let buf: NAAudioBuffer<u8> = NAAudioBuffer { data: NABufferRef::new(data), info: ainfo, offs, chmap, len: nsamples, stride: 0 };
Ok(NABufferType::AudioPacked(buf))
}
}