]> git.nihav.org Git - nihav.git/commitdiff
nihav_mpeg: fix or update clippy warnings
authorKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 8 Nov 2024 18:28:09 +0000 (19:28 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 9 Nov 2024 14:31:47 +0000 (15:31 +0100)
12 files changed:
nihav-mpeg/src/codecs/aac/coeff_read.rs
nihav-mpeg/src/codecs/aac/info.rs
nihav-mpeg/src/codecs/aac/mod.rs
nihav-mpeg/src/codecs/aac/sbr/bs.rs
nihav-mpeg/src/codecs/aac/sbr/mod.rs
nihav-mpeg/src/codecs/aac/tools.rs
nihav-mpeg/src/codecs/mod.rs
nihav-mpeg/src/codecs/mpeg4asp/bitstream.rs
nihav-mpeg/src/codecs/mpeg4asp/dsp.rs
nihav-mpeg/src/codecs/mpegaudio/mp2code.rs
nihav-mpeg/src/codecs/mpegaudio/mp3code.rs
nihav-mpeg/src/lib.rs

index 81a1d367a1c3cd76d105df986db01d706a32d660..8fc485371a8d13ef52d66775e5788f200bca9483 100644 (file)
@@ -69,24 +69,23 @@ fn decode_quads(br: &mut BitReader, cb: &Codebook<u16>, unsigned: bool, scale: f
     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
+                    };
             }
         }
     }
@@ -157,7 +156,7 @@ pub fn decode_scale_factor_data(br: &mut BitReader, scales: &mut [[u8; MAX_SFBS]
                 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 {
@@ -166,11 +165,11 @@ pub fn decode_scale_factor_data(br: &mut BitReader, scales: &mut [[u8; MAX_SFBS]
                     } 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;
                 }
             }
index 648b3562d47d4895f75164d7c4b78ef9ba8f351f..a9607d618a16bdd40f6f1ffebd7557e3723a4956 100644 (file)
@@ -106,13 +106,12 @@ impl M4AInfo {
         }
     }
     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 {
@@ -146,12 +145,9 @@ impl M4AInfo {
         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));
         }
 
index e37e812357489f9d39a7eca502e8d32de7909aa0..fb15d955142be0e73f0e19a410578e44c5bbab52 100644 (file)
@@ -11,6 +11,7 @@ mod coeff_read;
 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)]
@@ -481,9 +482,7 @@ impl DSP {
                         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];
@@ -505,55 +504,45 @@ impl DSP {
                     }
                 },
             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!(""),
index dbce7276c553aabf6c8de221087ec9fe03215b45..651351721a3653002fc653cf3b9d19bb7b54233d 100644 (file)
@@ -225,6 +225,7 @@ fn read_invf(br: &mut BitReader, chan: &mut SBRChannel, state: &SBRState) -> Dec
     }
     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 {
index d2477b98a45a5735d5c83a2b1c58a487158a2e23..cfd0c2c3cc124b9b0b72e8d90772f8f307629a9c 100644 (file)
@@ -348,6 +348,7 @@ fn generate_vdk(v_dk: &mut [usize], k0: usize, k1: usize, num_bands: usize) {
     }
 }
 
+#[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 {
index 17c404230c3d361995b5b293fa0dac99d276fa8f..e00a85b0c4a4c20cf5ac116c5a29ed10eac166f6 100644 (file)
@@ -108,12 +108,11 @@ impl TNSCoeffs {
             // 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];
             }
         }
@@ -153,20 +152,20 @@ impl TNSData {
         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;
             }
         }
     }
index 9d488089d85346992421b167a2b6af4f0d6ab96e..62184b1ed515d415f2c996c47d48ee364dccfe5a 100644 (file)
@@ -13,10 +13,7 @@ macro_rules! validate {
 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)]
index b82226bd3800cfffe8cd4ed81d003c22b7f46d27..ac3f79ba2db4581247b1943f527db70aec5e927c 100644 (file)
@@ -488,6 +488,7 @@ pub struct FrameDecoder {
     cbs:                    Tables,
 }
 
+#[allow(clippy::needless_late_init)]
 impl FrameDecoder {
     pub fn new() -> Self {
         Self {
@@ -685,6 +686,8 @@ unimplemented!();
         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)?;
@@ -831,7 +834,7 @@ unimplemented!();
         /* 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;
 
index 33532752fb74060f349d35c3b3690713bc086eb5..1367bd62771e67387b1425cdb0510ae3a4942979 100644 (file)
@@ -272,6 +272,7 @@ impl DSP {
     }
 }
 
+#[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) {
@@ -297,6 +298,7 @@ pub fn dequant_intra_block(block: &mut [i16; 64], ac_scale: u8, qinfo: &QuantInf
     }
 }
 
+#[allow(clippy::needless_late_init)]
 pub fn dequant_inter(mb: &mut Macroblock, qinfo: &QuantInfo) {
     let ac_scale = mb.quant;
     let mut cbp = mb.cbp;
index 1c08a4e3446a004c55fa261b4688947534b80bfa..b9a5d22f341b62795f33de14f8718018aefe22dd 100644 (file)
@@ -27,18 +27,18 @@ fn read3samples(br: &mut BitReader, qbits: i8, scale: f32, band: usize, dst: &mu
         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!(),
@@ -159,10 +159,10 @@ impl MP2Data {
                 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];
                 }
index c00696cb42aec894c9d9088f7d42d45f008bc4b3..2ee78e51acfd0dc0fe8fc2a736b0f3c9ca3793cf 100644 (file)
@@ -234,6 +234,7 @@ pub struct MP3Data {
         tmp:            [f32; SAMPLES / 2],
 }
 
+#[allow(clippy::needless_range_loop)]
 impl MP3Data {
     pub fn new() -> Self {
         Self {
@@ -534,6 +535,7 @@ impl MP3Data {
         }
         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 };
index 5e161257870397bcabac056b91819c27bf8fcdfd..d3a00e911ea75eda537eb979144d7cf7c1d5493a 100644 (file)
@@ -3,11 +3,6 @@ extern crate nihav_core;
 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;