core/frame: add truncate() for NAAudioBuffer
authorKostya Shishkov <kostya.shishkov@gmail.com>
Tue, 1 Sep 2020 10:53:11 +0000 (12:53 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 5 Sep 2020 12:09:56 +0000 (14:09 +0200)
nihav-core/src/frame.rs

index 9423b0ee8e475e5a87086a808fdb37cc9d4a1517..f7a318a98021c69cbb7cd6a05f251490739876c1 100644 (file)
@@ -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);