X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-duck%2Fsrc%2Fcodecs%2Fon2avc.rs;h=17f2d5ec75e760e1649628df9047fcefdbaff36b;hb=f65c6fb45c243e937e06b17f2d22aadb61349bd7;hp=29ead41d3c1ec9ebf7dd3106fef30495d0e6bf23;hpb=78fb6560c73965d834b215fb0b49505ae5443288;p=nihav.git diff --git a/nihav-duck/src/codecs/on2avc.rs b/nihav-duck/src/codecs/on2avc.rs index 29ead41..17f2d5e 100644 --- a/nihav-duck/src/codecs/on2avc.rs +++ b/nihav-duck/src/codecs/on2avc.rs @@ -210,21 +210,36 @@ impl AVCDecoder { let mut cur_band = 0; let mut scale = 0; let mut first = true; - for wg in self.win_grp.iter().take(self.windows) { - if *wg { + for wg in 0..self.windows { + if self.win_grp[wg] { for _ in 0..bands { if self.cbs[cur_band] == 0 { - self.scales[cur_band] = 0; - } else { - if first { - scale = br.read(7)? as i16; - first = false - } else { - scale += i16::from(br.read_cb(&self.codebooks.scale_cb)?); - validate!((scale >= 0) && (scale < 128)); + let mut all_zero = true; + let mut band2 = cur_band; + for wg2 in wg + 1..self.windows { + if self.win_grp[wg2] { + break; + } + band2 += bands; + if self.cbs[band2] != 0 { + all_zero = false; + break; + } + } + if all_zero { + self.scales[cur_band] = 0; + cur_band += 1; + continue; } - self.scales[cur_band] = scale as u8; } + if first { + scale = br.read(7)? as i16; + first = false; + } else { + scale += i16::from(br.read_cb(&self.codebooks.scale_cb)?); + validate!((scale >= 0) && (scale < 128)); + } + self.scales[cur_band] = scale as u8; cur_band += 1; } } else { @@ -346,17 +361,7 @@ impl AVCDecoder { } }, 2 | 7 => { - self.imdct_long.imdct(coeffs, &mut self.tmp); - for i in 0..SHORT_WIN_POINT0 { - dst[i] = delay[i]; - } - overlap(&mut dst[SHORT_WIN_POINT0..SHORT_WIN_POINT1], - &self.tmp[SHORT_WIN_POINT0..SHORT_WIN_POINT1], - &delay[SHORT_WIN_POINT0..SHORT_WIN_POINT1], AVC_WIN_SHORT); - for i in SHORT_WIN_POINT1..COEFFS { - dst[i] = self.tmp[i - SHORT_WIN_POINT1 + 128]; - } - delay.copy_from_slice(&self.tmp[COEFFS..]); + self.imdct_long.imdct_half(coeffs, &mut self.ew_buf); }, 3 => { for (ain, aout) in coeffs.chunks(128).zip(self.tmp.chunks_mut(256)) { @@ -387,76 +392,52 @@ impl AVCDecoder { for i in 0..SHORT_WIN_POINT1 { delay[i] = self.ew_buf[SHORT_WIN_POINT1 + i]; } - for i in SHORT_WIN_POINT1..COEFFS { - delay[i] = 0.0; + for i in COEFFS/2..COEFFS { + delay[i] = delay[COEFFS - 1 - i]; } }, 4 => { - for i in 0..SHORT_WIN_POINT0 { - dst[i] = delay[i]; - } if !self.use_generic { synth1024(&mut self.dsp, coeffs, &mut self.ew_buf, &mut self.tmp, self.is_40khz); } else { synth_generic(coeffs, &mut self.ew_buf, &mut self.tmp, self.is_40khz, 1024); } - overlap_half(&mut dst[SHORT_WIN_POINT0..SHORT_WIN_POINT1], - &self.ew_buf[0..64], - &delay[SHORT_WIN_POINT0..SHORT_WIN_POINT1], AVC_WIN_SHORT); - for i in SHORT_WIN_POINT1..COEFFS { - dst[i] = self.ew_buf[i - SHORT_WIN_POINT1 + 64]; - } - for i in 0..COEFFS/2 { - delay[i] = self.ew_buf[COEFFS/2 + i]; - } - for i in COEFFS/2..COEFFS { - delay[i] = delay[COEFFS - 1 - i]; - } - }, + }, 5 => { - for i in 0..SHORT_WIN_POINT0 { - dst[i] = delay[i]; - } if !self.use_generic { synth512(&mut self.dsp, coeffs, &mut self.ew_buf, &mut self.tmp, self.is_40khz); } else { synth_generic(coeffs, &mut self.ew_buf, &mut self.tmp, self.is_40khz, 512); } - self.imdct_mid.imdct(&coeffs[512..], &mut self.ew_buf[512..]); - overlap(&mut dst[SHORT_WIN_POINT0..SHORT_WIN_POINT1], - &self.ew_buf[SHORT_WIN_POINT0..SHORT_WIN_POINT1], - &delay[SHORT_WIN_POINT0..SHORT_WIN_POINT1], AVC_WIN_SHORT); - for i in SHORT_WIN_POINT1..COEFFS { - dst[i] = self.ew_buf[i]; - } - *delay = [0.0; COEFFS]; - for i in 0..SHORT_WIN_POINT1 { - delay[i] = self.ew_buf[i]; - } + self.imdct_mid.imdct_half(&coeffs[512..], &mut self.ew_buf[512..]); }, 6 => { - for i in 0..SHORT_WIN_POINT0 { - dst[i] = delay[i]; - } - self.imdct_mid.imdct(coeffs, &mut self.ew_buf); + self.imdct_mid.imdct_half(coeffs, &mut self.ew_buf); if !self.use_generic { synth512(&mut self.dsp, &coeffs[512..], &mut self.ew_buf[512..], &mut self.tmp, self.is_40khz); } else { synth_generic(&coeffs[512..], &mut self.ew_buf[512..], &mut self.tmp, self.is_40khz, 512); } - overlap(&mut dst[SHORT_WIN_POINT0..SHORT_WIN_POINT1], - &self.ew_buf[SHORT_WIN_POINT0..SHORT_WIN_POINT1], - &delay[SHORT_WIN_POINT0..SHORT_WIN_POINT1], AVC_WIN_SHORT); - for i in SHORT_WIN_POINT1..COEFFS { - dst[i] = self.ew_buf[i]; - } - *delay = [0.0; COEFFS]; - for i in 0..SHORT_WIN_POINT1 { - delay[i] = self.ew_buf[i]; - } }, _ => unreachable!(), }; + if (self.cur_win == 2) || (self.cur_win >= 4) { + for i in 0..SHORT_WIN_POINT0 { + dst[i] = delay[i]; + } + overlap_half(&mut dst[SHORT_WIN_POINT0..SHORT_WIN_POINT1], + &self.ew_buf[0..64], + &delay[SHORT_WIN_POINT0..SHORT_WIN_POINT1], AVC_WIN_SHORT); + for i in SHORT_WIN_POINT1..COEFFS { + dst[i] = self.ew_buf[i - SHORT_WIN_POINT1 + 64]; + } + for i in 0..COEFFS/2 { + delay[i] = self.ew_buf[COEFFS/2 + i]; + } + for i in COEFFS/2..COEFFS { + delay[i] = delay[COEFFS - 1 - i]; + } + } } }