core/frame: add proper function for audio frame truncation
authorKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 29 Oct 2021 12:07:55 +0000 (14:07 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 29 Oct 2021 12:07:55 +0000 (14:07 +0200)
nihav-core/src/frame.rs

index 5499de1001b40b36446bec2cd8d99902bcf24d1e..31cf8e81991a519d26827e13913175a6d3cd1dd6 100644 (file)
@@ -390,6 +390,17 @@ impl NABufferType {
             _ => 0,
         }
     }
+    /// Truncates audio frame duration if possible.
+    pub fn truncate_audio(&mut self, len: usize) {
+        match *self {
+            NABufferType::AudioU8(ref mut ab)     => ab.truncate(len),
+            NABufferType::AudioI16(ref mut ab)    => ab.truncate(len),
+            NABufferType::AudioI32(ref mut ab)    => ab.truncate(len),
+            NABufferType::AudioF32(ref mut ab)    => ab.truncate(len),
+            NABufferType::AudioPacked(ref mut ab) => ab.truncate(len),
+            _ => {},
+        };
+    }
     /// Returns the distance between starts of two channels.
     pub fn get_audio_stride(&self) -> usize {
         match *self {