aboutsummaryrefslogtreecommitdiffstats
path: root/nihav-core/src/frame.rs
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2020-09-01 12:53:11 +0200
committerKostya Shishkov <kostya.shishkov@gmail.com>2020-09-05 14:09:56 +0200
commit640b1eb06b5c5e0678bc35d2e2e297e4b3bda540 (patch)
tree0aefdbee7cbc7b5ede9f65e1a8e5bada64cdd256 /nihav-core/src/frame.rs
parent3983a2bb88a405cd581a0456a6f49471cb52f78f (diff)
downloadnihav-640b1eb06b5c5e0678bc35d2e2e297e4b3bda540.tar.gz
core/frame: add truncate() for NAAudioBuffer
Diffstat (limited to 'nihav-core/src/frame.rs')
-rw-r--r--nihav-core/src/frame.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs
index 9423b0e..f7a318a 100644
--- a/nihav-core/src/frame.rs
+++ b/nihav-core/src/frame.rs
@@ -251,6 +251,12 @@ impl<T: Clone> NAAudioBuffer<T> {
}
/// Return the length of frame in samples.
pub fn get_length(&self) -> usize { self.len }
+ /// Truncates buffer length if possible.
+ ///
+ /// In case when new length is larger than old length nothing is done.
+ pub fn truncate(&mut self, new_len: usize) {
+ self.len = self.len.min(new_len);
+ }
fn print_contents(&self, datatype: &str) {
println!("Audio buffer with {} data, stride {}, step {}", datatype, self.stride, self.step);