From: Kostya Shishkov Date: Tue, 1 Sep 2020 10:53:11 +0000 (+0200) Subject: core/frame: add truncate() for NAAudioBuffer X-Git-Url: https://git.nihav.org/?p=nihav.git;a=commitdiff_plain;h=640b1eb06b5c5e0678bc35d2e2e297e4b3bda540 core/frame: add truncate() for NAAudioBuffer --- 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 NAAudioBuffer { } /// 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);