From 2d1e0773a5c845db33041796ea74d8ca12710ced Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Fri, 29 Oct 2021 14:49:09 +0200 Subject: [PATCH] use proper audio buffer truncation function --- nihav-llaudio/src/codecs/tta.rs | 3 +-- nihav-qt/src/codecs/alac.rs | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/nihav-llaudio/src/codecs/tta.rs b/nihav-llaudio/src/codecs/tta.rs index 03eb515..e88793e 100644 --- a/nihav-llaudio/src/codecs/tta.rs +++ b/nihav-llaudio/src/codecs/tta.rs @@ -289,7 +289,6 @@ impl NADecoder for TTADecoder { if not_last { self.framelen } else { - adata.truncate((self.nsamples % self.framelen) as usize); self.nsamples % self.framelen } }, @@ -300,12 +299,12 @@ impl NADecoder for TTADecoder { if not_last { self.framelen } else { - adata.truncate((self.nsamples % self.framelen) as usize); self.nsamples % self.framelen } }, _ => unreachable!(), }; + abuf.truncate_audio(duration as usize); let mut frm = NAFrame::new_from_pkt(pkt, info, abuf); frm.set_duration(Some(u64::from(duration))); diff --git a/nihav-qt/src/codecs/alac.rs b/nihav-qt/src/codecs/alac.rs index bdcdad7..b29e9a2 100644 --- a/nihav-qt/src/codecs/alac.rs +++ b/nihav-qt/src/codecs/alac.rs @@ -356,7 +356,7 @@ impl NADecoder for ALACDecoder { if let NACodecTypeInfo::Audio(_) = info.get_properties() { let src = pkt.get_buffer(); let channels = self.chmap.num_channels(); - let abuf = alloc_audio_buffer(self.ainfo, self.frame_len, self.chmap.clone())?; + let mut abuf = alloc_audio_buffer(self.ainfo, self.frame_len, self.chmap.clone())?; let mut br = BitReader::new(&src, BitReaderMode::BE); @@ -390,7 +390,6 @@ impl NADecoder for ALACDecoder { _ => return Err(DecoderError::InvalidData), }; } - adata.truncate(self.cur_len); } else if let Some(mut adata) = abuf.get_abuf_i32() { let shift = 32 - self.bits; let stride = adata.get_stride(); @@ -420,10 +419,10 @@ impl NADecoder for ALACDecoder { _ => return Err(DecoderError::InvalidData), }; } - adata.truncate(self.cur_len); } else { return Err(DecoderError::Bug); } + abuf.truncate_audio(self.cur_len); let mut frm = NAFrame::new_from_pkt(pkt, info.replace_info(NACodecTypeInfo::Audio(self.ainfo)), abuf); frm.set_duration(Some(self.cur_len as u64)); -- 2.39.5