for out in dst.chunks_mut(4) {
let cw = br.read_cb(cb)? as usize;
if unsigned {
- for i in 0..4 {
- let val = AAC_QUADS[cw][i];
+ for (&val, dst) in AAC_QUADS[cw].iter().zip(out.iter_mut()) {
if val != 0 {
- if br.read_bool()? {
- out[i] = -CBRT_TAB[val as usize] * scale;
- } else {
- out[i] = CBRT_TAB[val as usize] * scale;
- }
+ *dst = if br.read_bool()? {
+ -CBRT_TAB[val as usize] * scale
+ } else {
+ CBRT_TAB[val as usize] * scale
+ };
}
}
} else {
- for i in 0..4 {
- let val = AAC_QUADS[cw][i] - 1;
- if val < 0 {
- out[i] = -CBRT_TAB[val.unsigned_abs() as usize] * scale;
- } else {
- out[i] = CBRT_TAB[val.unsigned_abs() as usize] * scale;
- }
+ for (&qval, dst) in AAC_QUADS[cw].iter().zip(out.iter_mut()) {
+ let val = qval - 1;
+ *dst = if val < 0 {
+ -CBRT_TAB[val.unsigned_abs() as usize] * scale
+ } else {
+ CBRT_TAB[val.unsigned_abs() as usize] * scale
+ };
}
}
}
if (sfb_cb[g][sfb] == INTENSITY_HCB) || (sfb_cb[g][sfb] == INTENSITY_HCB2) {
let diff = i16::from(br.read_cb(&codebooks.scale_cb)?);
scf_intensity += diff;
- validate!((scf_intensity >= INTENSITY_SCALE_MIN) && (scf_intensity < INTENSITY_SCALE_MIN + 256));
+ validate!((INTENSITY_SCALE_MIN..INTENSITY_SCALE_MIN + 256).contains(&scf_intensity));
scales[g][sfb] = (scf_intensity - INTENSITY_SCALE_MIN) as u8;
} else if sfb_cb[g][sfb] == NOISE_HCB {
if noise_pcm_flag {
} else {
scf_noise += i16::from(br.read_cb(&codebooks.scale_cb)?);
}
- validate!((scf_noise >= NOISE_SCALE_MIN) && (scf_noise < NOISE_SCALE_MIN + 256));
+ validate!((NOISE_SCALE_MIN..NOISE_SCALE_MIN + 256).contains(&scf_noise));
scales[g][sfb] = (scf_noise - NOISE_SCALE_MIN) as u8;
} else {
scf_normal += i16::from(br.read_cb(&codebooks.scale_cb)?);
- validate!((scf_normal >= 0) && (scf_normal < 255));
+ validate!((0..255).contains(&scf_normal));
scales[g][sfb] = scf_normal as u8;
}
}
}
}
fn read_object_type(br: &mut BitReader) -> DecoderResult<M4AType> {
- let otypeidx;
- if br.peek(5) == 31 {
+ let otypeidx = if br.peek(5) == 31 {
br.skip(5)?;
- otypeidx = (br.read(6)? as usize) + 32;
- } else {
- otypeidx = br.read(5)? as usize;
- }
+ (br.read(6)? as usize) + 32
+ } else {
+ br.read(5)? as usize
+ };
if otypeidx >= M4A_TYPES.len() {
Ok(M4AType::Unknown)
} else {
if (self.otype == M4AType::SBR) || (self.otype == M4AType::PS) {
let ext_srate = Self::read_sampling_frequency(&mut br)?;
self.otype = Self::read_object_type(&mut br)?;
- let ext_chans;
- if self.otype == M4AType::ER_BSAC {
- ext_chans = Self::read_channel_config(&mut br)?;
- } else {
- ext_chans = 0;
- }
+ let ext_chans = if self.otype == M4AType::ER_BSAC {
+ Self::read_channel_config(&mut br)?
+ } else { 0 };
self.sbr_ps_info = Some((ext_srate, ext_chans));
}
use coeff_read::*;
mod info;
use info::*;
+#[allow(clippy::needless_range_loop)]
mod sbr;
use sbr::{SBRHeader, SBRCodebooks, SBRState, SBRChannel, SBRDSP, sbr_read_sce, sbr_read_cpe};
#[allow(clippy::excessive_precision)]
self.ew_buf[w * 128 + i] += src[i] * short_win[i];
}
} else { // to be left-windowed
- for i in 0..128 {
- self.ew_buf[i] = src[i];
- }
+ self.ew_buf[..128].copy_from_slice(&src[..128]);
}
for i in 0..128 {
self.ew_buf[w * 128 + i + 128] += src[i + 128] * short_win[127 - i];
}
},
EIGHT_SHORT_SEQUENCE => {
- for i in 0..SHORT_WIN_POINT0 {
- dst[i] = delay[i];
- }
+ dst[..SHORT_WIN_POINT0].copy_from_slice(&delay[..SHORT_WIN_POINT0]);
for i in SHORT_WIN_POINT0..SHORT_WIN_POINT1 {
let j = i - SHORT_WIN_POINT0;
dst[i] = delay[i] + self.ew_buf[j] * left_short_win[j];
}
- for i in SHORT_WIN_POINT1..1024 {
- let j = i - SHORT_WIN_POINT0;
- dst[i] = self.ew_buf[j];
- }
+ dst[SHORT_WIN_POINT1..1024].copy_from_slice(
+ &self.ew_buf[SHORT_WIN_POINT1-SHORT_WIN_POINT0..1024-SHORT_WIN_POINT0]);
},
LONG_STOP_SEQUENCE => {
- for i in 0..SHORT_WIN_POINT0 {
- dst[i] = delay[i];
- }
+ dst[..SHORT_WIN_POINT0].copy_from_slice(&delay[..SHORT_WIN_POINT0]);
for i in SHORT_WIN_POINT0..SHORT_WIN_POINT1 {
dst[i] = delay[i] + self.tmp[i] * left_short_win[i - SHORT_WIN_POINT0];
}
- for i in SHORT_WIN_POINT1..1024 {
- dst[i] = self.tmp[i];
- }
+ dst[SHORT_WIN_POINT1..1024].copy_from_slice(&self.tmp[SHORT_WIN_POINT1..1024]);
},
_ => unreachable!(""),
};
// save delay
match seq {
ONLY_LONG_SEQUENCE | LONG_STOP_SEQUENCE => {
- for i in 0..1024 {
- delay[i] = self.tmp[i + 1024] * long_win[1023 - i];
+ for (dst, (&src, &win)) in delay.iter_mut()
+ .zip(self.tmp[1024..].iter().zip(long_win.iter().rev())) {
+ *dst = src * win;
}
},
EIGHT_SHORT_SEQUENCE => {
- for i in 0..SHORT_WIN_POINT1 { // last part is already windowed
- delay[i] = self.ew_buf[i + 512+64];
- }
- for i in SHORT_WIN_POINT1..1024 {
- delay[i] = 0.0;
+ // last part is already windowed
+ delay[..SHORT_WIN_POINT1].copy_from_slice(&self.ew_buf[512+64..][..SHORT_WIN_POINT1]);
+ for el in delay[SHORT_WIN_POINT1..].iter_mut() {
+ *el = 0.0;
}
},
LONG_START_SEQUENCE => {
- for i in 0..SHORT_WIN_POINT0 {
- delay[i] = self.tmp[i + 1024];
- }
+ delay[..SHORT_WIN_POINT0].copy_from_slice(&self.tmp[1024..][..SHORT_WIN_POINT0]);
for i in SHORT_WIN_POINT0..SHORT_WIN_POINT1 {
delay[i] = self.tmp[i + 1024] * short_win[127 - (i - SHORT_WIN_POINT0)];
}
- for i in SHORT_WIN_POINT1..1024 {
- delay[i] = 0.0;
+ for el in delay[SHORT_WIN_POINT1..].iter_mut() {
+ *el = 0.0;
}
},
_ => unreachable!(""),
}
Ok(())
}
+#[allow(clippy::collapsible_else_if)]
fn read_envelope(br: &mut BitReader, chan: &mut SBRChannel, coupled: bool, cbs: &SBRCodebooks, state: &SBRState) -> DecoderResult<()> {
let (f_cb, t_cb) = if coupled {
if chan.amp_res {
}
}
+#[allow(clippy::comparison_chain)]
fn calculate_master_frequencies(f: &mut [usize; SBR_BANDS], k0: usize, k2: usize, hdr: &SBRHeader) -> usize {
if hdr.freq_scale == 0 {
let (dk, num_bands) = if !hdr.alter_scale {
// convert to LPC coefficients
let mut b: [f32; TNS_MAX_ORDER + 1] = [0.0; TNS_MAX_ORDER + 1];
for m in 1..=self.order {
+ #[allow(clippy::needless_range_loop)]
for i in 1..m {
b[i] = self.coef[i - 1] + tmp[m - 1] * self.coef[m - i - 1];
}
- for i in 1..m {
- self.coef[i - 1] = b[i];
- }
+ self.coef[..m-1].copy_from_slice(&b[1..m]);
self.coef[m - 1] = tmp[m - 1];
}
}
let mut state = [0.0f32; 64];
let mut sidx = 32;
if !self.coeffs[w][f].direction {
- for m in start..end {
+ for coef in coeffs[start..end].iter_mut() {
for i in 0..order {
- coeffs[m] -= state[(sidx + i) & 63] * lpc[i];
+ *coef -= state[(sidx + i) & 63] * lpc[i];
}
sidx = (sidx + 63) & 63;
- state[sidx] = coeffs[m];
+ state[sidx] = *coef;
}
} else {
- for m in (start..end).rev() {
+ for coef in coeffs[start..end].iter_mut().rev() {
for i in 0..order {
- coeffs[m] -= state[(sidx + i) & 63] * lpc[i];
+ *coef -= state[(sidx + i) & 63] * lpc[i];
}
sidx = (sidx + 63) & 63;
- state[sidx] = coeffs[m];
+ state[sidx] = *coef;
}
}
}
mod mpeg4asp;
#[cfg(feature="decoder_aac")]
-#[allow(clippy::comparison_chain)]
#[allow(clippy::excessive_precision)]
-#[allow(clippy::manual_memcpy)]
-#[allow(clippy::useless_let_if_seq)]
mod aac;
#[cfg(feature="decoder_mpa")]
#[allow(clippy::excessive_precision)]
cbs: Tables,
}
+#[allow(clippy::needless_late_init)]
impl FrameDecoder {
pub fn new() -> Self {
Self {
self.slice_start = 0;
}
+ #[allow(clippy::collapsible_if)]
+ #[allow(clippy::collapsible_else_if)]
pub fn decode_mb(&mut self, src: &[u8], mb: &mut Macroblock, colo_not_coded: bool, mb_x: usize, pred: &mut PredState, qinfo: &QuantInfo) -> DecoderResult<()> {
let mut br = BitReader::new(src, BitReaderMode::BE);
br.skip(self.bitpos as u32)?;
/* ignore alpha part for gray shape */
let quant = self.quant as i8 + dquant;
- validate!(quant >= 0 && quant < 64);
+ validate!((0..64).contains(&quant));
let quant = quant as u8;
mb.quant = quant;
}
}
+#[allow(clippy::needless_late_init)]
pub fn dequant_intra_block(block: &mut [i16; 64], ac_scale: u8, qinfo: &QuantInfo) {
if qinfo.quant_type {
for (coef, &weight) in block.iter_mut().zip(qinfo.intra_mat.iter()).skip(1) {
}
}
+#[allow(clippy::needless_late_init)]
pub fn dequant_inter(mb: &mut Macroblock, qinfo: &QuantInfo) {
let ac_scale = mb.quant;
let mut cbp = mb.cbp;
let samplecode = br.read(-qbits as u8)? as usize;
match qbits {
-5 => {
- for i in 0..3 {
- dst[i][band] = unquant(GROUP3[samplecode][i], 3, scale);
+ for (i, &level) in GROUP3[samplecode].iter().enumerate() {
+ dst[i][band] = unquant(level, 3, scale);
}
},
-7 => {
- for i in 0..3 {
- dst[i][band] = unquant(GROUP5[samplecode][i], 5, scale);
+ for (i, &level) in GROUP5[samplecode].iter().enumerate() {
+ dst[i][band] = unquant(level, 5, scale);
}
},
-10 => {
- for i in 0..3 {
- dst[i][band] = unquant(GROUP9[samplecode][i], 9, scale);
+ for (i, &level) in GROUP9[samplecode].iter().enumerate() {
+ dst[i][band] = unquant(level, 9, scale);
}
},
_ => unreachable!(),
bound -= 1;
}
- for band in 0..sblimit {
- self.alloc[0][band] = br.read(ba_bits[band])? as u8;
+ for (band, &bits) in ba_bits[..sblimit].iter().enumerate() {
+ self.alloc[0][band] = br.read(bits)? as u8;
if band < bound {
- self.alloc[1][band] = br.read(ba_bits[band])? as u8;
+ self.alloc[1][band] = br.read(bits)? as u8;
} else {
self.alloc[1][band] = self.alloc[0][band];
}
tmp: [f32; SAMPLES / 2],
}
+#[allow(clippy::needless_range_loop)]
impl MP3Data {
pub fn new() -> Self {
Self {
}
Ok(())
}
+ #[allow(clippy::manual_range_contains)]
pub fn synth(&mut self, coeffs: &mut [[f32; SAMPLES]; 2], output: &mut [[[f32; 32]; 36]; 2], mode: u8, mode_ext: u8) {
let channels = if mode == 3 { 1 } else { 2 };
let granules = if self.mpeg1 { 2 } else { 1 };
extern crate nihav_codec_support;
#[cfg(feature="decoders")]
-#[allow(clippy::collapsible_if)]
-#[allow(clippy::collapsible_else_if)]
-#[allow(clippy::needless_range_loop)]
-#[allow(clippy::needless_late_init)]
-#[allow(clippy::manual_range_contains)]
#[allow(clippy::upper_case_acronyms)]
mod codecs;