X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;ds=sidebyside;f=nihav-ms%2Fsrc%2Fcodecs%2Fimaadpcmenc.rs;h=f142646c20a358a9d6d177521549801c2df39303;hb=refs%2Fheads%2Fmaster;hp=15e76fb251a7473bcff2b1ca80fb0a4c3a58e234;hpb=6f2630992fe340ad1a122ec10c649f756e478185;p=nihav.git diff --git a/nihav-ms/src/codecs/imaadpcmenc.rs b/nihav-ms/src/codecs/imaadpcmenc.rs index 15e76fb..eee51b8 100644 --- a/nihav-ms/src/codecs/imaadpcmenc.rs +++ b/nihav-ms/src/codecs/imaadpcmenc.rs @@ -96,7 +96,6 @@ impl IMAADPCMEncoder { nw.write(nib)?; } } - drop(nw); } else { self.nodes.reserve(self.block_len); self.nibs.resize(self.channels, Vec::new()); @@ -107,12 +106,12 @@ impl IMAADPCMEncoder { let mut state = [TrellisNode::default(); 16]; for ch in 0..self.channels { self.nodes.clear(); - for i in 0..16 { + for (i, state) in state.iter_mut().enumerate() { let step = (((self.first[ch].step + i) as isize) - 8).max(0).min(IMA_MAX_STEP as isize) as usize; - state[i].state.predictor = self.first[ch].predictor; - state[i].state.step = step; - state[i].error = 0; - state[i].nib = step as u8; + state.state.predictor = self.first[ch].predictor; + state.state.step = step; + state.error = 0; + state.nib = step as u8; } self.nodes.push(state); let mut sidx = ch + step; @@ -164,7 +163,6 @@ impl IMAADPCMEncoder { nw.write(self.nibs[ch][i])?; } } - drop(nw); } self.samples.drain(..self.block_len * self.channels); @@ -203,6 +201,9 @@ impl NAEncoder for IMAADPCMEncoder { if outinfo.block_len == 0 { outinfo.block_len = DEFAULT_BLOCK_LEN; } + if outinfo.block_len == 1 && encinfo.tb_den != outinfo.sample_rate { + outinfo.block_len = ((u64::from(outinfo.sample_rate) * u64::from(encinfo.tb_num) / u64::from(encinfo.tb_den) + 3) & !3) as usize; + } if outinfo.block_len < 2 { outinfo.block_len = 2; } @@ -215,6 +216,7 @@ impl NAEncoder for IMAADPCMEncoder { } } } + fn get_capabilities(&self) -> u64 { ENC_CAPS_CBR } fn init(&mut self, stream_id: u32, encinfo: EncodeParameters) -> EncoderResult { match encinfo.format { NACodecTypeInfo::None => Err(EncoderError::FormatError),