let iqfac = (fac_base - 0.5) / (consts::PI / 2.0);
let iqfac_m = (fac_base + 0.5) / (consts::PI / 2.0);
let mut tmp: [f32; TNS_MAX_ORDER] = [0.0; TNS_MAX_ORDER];
- for i in 0..self.order {
+ for el in tmp.iter_mut().take(self.order) {
let val = br.read(coef_bits)? as i8;
- let c = if (val & sign_mask) != 0 { val | neg_mask } else { val } as f32;
- tmp[i] = (if c >= 0.0 { c / iqfac } else { c / iqfac_m }).sin();
+ let c = f32::from(if (val & sign_mask) != 0 { val | neg_mask } else { val });
+ *el = (if c >= 0.0 { c / iqfac } else { c / iqfac_m }).sin();
}
// convert to LPC coefficients
let mut b: [f32; TNS_MAX_ORDER + 1] = [0.0; TNS_MAX_ORDER + 1];
- for m in 1..(self.order + 1) {
+ for m in 1..=self.order {
for i in 1..m {
b[i] = self.coef[i - 1] + tmp[m - 1] * self.coef[m - i - 1];
}
}
fn decode_scale_factor_data(&mut self, br: &mut BitReader, codebooks: &Codebooks) -> DecoderResult<()> {
let mut noise_pcm_flag = true;
- let mut scf_normal = self.global_gain as i16;
+ let mut scf_normal = i16::from(self.global_gain);
let mut scf_intensity = 0i16;
let mut scf_noise = 0i16;
for g in 0..self.info.window_groups {
for sfb in 0..self.info.max_sfb {
if self.sfb_cb[g][sfb] != ZERO_HCB {
if self.is_intensity(g, sfb) {
- let diff = br.read_cb(&codebooks.scale_cb)? as i16;
+ 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));
self.scales[g][sfb] = (scf_intensity - INTENSITY_SCALE_MIN) as u8;
- } else {
- if self.sfb_cb[g][sfb] == NOISE_HCB {
- if noise_pcm_flag {
- noise_pcm_flag = false;
- scf_noise = (br.read(9)? as i16) - 256 + (self.global_gain as i16) - 90;
- } else {
- scf_noise += br.read_cb(&codebooks.scale_cb)? as i16;
- }
- validate!((scf_noise >= NOISE_SCALE_MIN) && (scf_noise < NOISE_SCALE_MIN + 256));
- self.scales[g][sfb] = (scf_noise - NOISE_SCALE_MIN) as u8;
+ } else if self.sfb_cb[g][sfb] == NOISE_HCB {
+ if noise_pcm_flag {
+ noise_pcm_flag = false;
+ scf_noise = (br.read(9)? as i16) - 256 + i16::from(self.global_gain) - 90;
} else {
- scf_normal += br.read_cb(&codebooks.scale_cb)? as i16;
- validate!((scf_normal >= 0) && (scf_normal < 255));
- self.scales[g][sfb] = scf_normal as u8;
+ scf_noise += i16::from(br.read_cb(&codebooks.scale_cb)?);
}
+ validate!((scf_noise >= NOISE_SCALE_MIN) && (scf_noise < NOISE_SCALE_MIN + 256));
+ self.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));
+ self.scales[g][sfb] = scf_normal as u8;
}
}
}
base = requant(self.coeffs[k], scale);
}
if base > 0.0 {
- base += pdata.pulse_amp[pno] as f32;
+ base += f32::from(pdata.pulse_amp[pno]);
} else {
- base -= pdata.pulse_amp[pno] as f32;
+ base -= f32::from(pdata.pulse_amp[pno]);
}
self.coeffs[k] = iquant(base) * scale;
}
}
fn get_scale(scale: u8) -> f32 {
- 2.0f32.powf(0.25 * ((scale as f32) - 100.0 - 56.0))
+ 2.0f32.powf(0.25 * (f32::from(scale) - 100.0 - 56.0))
}
fn iquant(val: f32) -> f32 {
if val < 0.0 {
let val = AAC_QUADS[cw][i];
if val != 0 {
if br.read_bool()? {
- out[i] = iquant(-val as f32) * scale;
+ out[i] = iquant(-f32::from(val)) * scale;
} else {
- out[i] = iquant( val as f32) * scale;
+ out[i] = iquant( f32::from(val)) * scale;
}
}
}
} else {
for i in 0..4 {
- out[i] = iquant((AAC_QUADS[cw][i] - 1) as f32) * scale;
+ out[i] = iquant(f32::from(AAC_QUADS[cw][i] - 1)) * scale;
}
}
}
y += read_escape(br, y > 0)?;
}
}
- out[0] = iquant(x as f32) * scale;
- out[1] = iquant(y as f32) * scale;
+ out[0] = iquant(f32::from(x)) * scale;
+ out[1] = iquant(f32::from(y)) * scale;
}
Ok(())
}
if self.ics[0].is_intensity(g, sfb) {
let invert = (self.ms_mask_present == 1) && self.ms_used[g][sfb];
let dir = self.ics[0].get_intensity_dir(g, sfb) ^ invert;
- let scale = 0.5f32.powf(0.25 * ((self.ics[0].scales[g][sfb] as f32) + (INTENSITY_SCALE_MIN as f32)));
+ let scale = 0.5f32.powf(0.25 * (f32::from(self.ics[0].scales[g][sfb]) + f32::from(INTENSITY_SCALE_MIN)));
if !dir {
for i in start..end {
self.ics[1].coeffs[i] = scale * self.ics[0].coeffs[i];
return Err(DecoderError::NotImplemented);
}
let chmap_str = DEFAULT_CHANNEL_MAP[self.m4ainfo.channels];
- if chmap_str.len() == 0 { return Err(DecoderError::NotImplemented); }
+ if chmap_str.is_empty() { return Err(DecoderError::NotImplemented); }
self.chmap = NAChannelMap::from_str(chmap_str).unwrap();
Ok(())
impl GASubbandInfo {
fn find(srate: u32) -> GASubbandInfo {
- for i in 0..AAC_SUBBAND_INFO.len() {
- if srate >= AAC_SUBBAND_INFO[i].min_srate {
- return AAC_SUBBAND_INFO[i];
+ for sbi in AAC_SUBBAND_INFO.iter() {
+ if srate >= sbi.min_srate {
+ return *sbi;
}
}
unreachable!("")
}
fn find_idx(srate: u32) -> usize {
- for i in 0..AAC_SUBBAND_INFO.len() {
- if srate >= AAC_SUBBAND_INFO[i].min_srate {
+ for (i, sbi) in AAC_SUBBAND_INFO.iter().enumerate() {
+ if srate >= sbi.min_srate {
return i;
}
}
}
fn synth(&mut self, dsp: &mut DSP) {
let mut flag = 0;
- let mut band = 0;
- for (data, delay) in self.data.chunks_mut(256).zip(self.delay.chunks_mut(256)) {
+ for (band, (data, delay)) in self.data.chunks_mut(256).zip(self.delay.chunks_mut(256)).enumerate() {
if (flag & 1) != 0 {
for i in 0..128 {
let t0 = data[i];
dsp.apply_gains(data, delay, &mut self.gain_data, self.block_no, band);
delay.copy_from_slice(&dsp.tmp[256..512]);
flag ^= 1;
- band += 1;
}
self.block_no ^= 1;
}
fn read_coeffs_mode0(br: &mut BitReader, dst: &mut [f32], quant: usize, scale: f32) -> DecoderResult<()> {
let bits = ATRAC3_MODE0_BITS[quant];
if bits > 0 {
- for i in 0..dst.len() {
+ for el in dst.iter_mut() {
let val = br.read_s(bits)? as f32;
- dst[i] = val * scale;
+ *el = val * scale;
}
} else {
- for i in (0..dst.len()).step_by(2) {
+ for out in dst.chunks_mut(2) {
let val = br.read(4)? as usize;
- dst[i + 0] = ATRAC3_MODE0_CB[val >> 2] * scale;
- dst[i + 1] = ATRAC3_MODE0_CB[val & 3] * scale;
+ out[0] = ATRAC3_MODE0_CB[val >> 2] * scale;
+ out[1] = ATRAC3_MODE0_CB[val & 3] * scale;
}
}
Ok(())
];
fn read_coeffs_mode1(br: &mut BitReader, cb: &Codebook<u8>, dst: &mut [f32], scale: f32) -> DecoderResult<()> {
- for i in (0..dst.len()).step_by(2) {
+ for out in dst.chunks_mut(2) {
let val = br.read_cb(cb)? as usize;
- dst[i + 0] = ATRAC3_MODE1_CB[val * 2 + 0] * scale;
- dst[i + 1] = ATRAC3_MODE1_CB[val * 2 + 1] * scale;
+ out[0] = ATRAC3_MODE1_CB[val * 2 + 0] * scale;
+ out[1] = ATRAC3_MODE1_CB[val * 2 + 1] * scale;
}
Ok(())
}
fn read_coeffs_other(br: &mut BitReader, cb: &Codebook<u8>, dst: &mut [f32], scale: f32) -> DecoderResult<()> {
- for i in 0..dst.len() {
+ for el in dst.iter_mut() {
let val = (br.read_cb(cb)? as i8) + 1;
let sign = (val & 1) != 0;
- let coef = (if sign { -(val >> 1) } else { val >> 1 }) as f32;
- dst[i] = coef * scale;
+ let coef = f32::from(if sign { -(val >> 1) } else { val >> 1 });
+ *el = coef * scale;
}
Ok(())
}
if self.weighting_delay[1] == 7 {
pw = [1.0; 2];
} else {
- let w = (self.weighting_delay[1] as f32) / 7.0;
+ let w = f32::from(self.weighting_delay[1]) / 7.0;
let iw = (2.0 - w * w).sqrt();
if self.weighting_delay[0] == 0 {
pw = [w, iw];
if self.weighting_delay[3] == 7 {
cw = [1.0; 2];
} else {
- let w = (self.weighting_delay[3] as f32) / 7.0;
+ let w = f32::from(self.weighting_delay[3]) / 7.0;
let iw = (2.0 - w * w).sqrt();
if self.weighting_delay[2] == 0 {
cw = [w, iw];
use nihav_core::io::codebook::*;
use nihav_core::formats;
use nihav_core::codecs::*;
-use std::fmt;
-use std::ops::{Add, Sub};
struct CLVDCCodeReader { }
struct CLVACCodeReader { }
impl CodebookDescReader<i8> for CLVDCCodeReader {
fn bits(&mut self, idx: usize) -> u8 { CLV_DC_BITS[idx] }
- fn code(&mut self, idx: usize) -> u32 { CLV_DC_CODES[idx] as u32 }
+ fn code(&mut self, idx: usize) -> u32 { u32::from(CLV_DC_CODES[idx]) }
fn sym (&mut self, idx: usize) -> i8 { (idx as i8) - 63 }
fn len(&mut self) -> usize { CLV_DC_BITS.len() }
}
impl CodebookDescReader<u16> for CLVACCodeReader {
fn bits(&mut self, idx: usize) -> u8 { CLV_AC_BITS[idx] }
- fn code(&mut self, idx: usize) -> u32 { CLV_AC_CODES[idx] as u32 }
+ fn code(&mut self, idx: usize) -> u32 { u32::from(CLV_AC_CODES[idx]) }
fn sym (&mut self, idx: usize) -> u16 { CLV_AC_SYMS[idx] }
fn len(&mut self) -> usize { CLV_AC_BITS.len() }
}
impl CodebookDescReader<u8> for CLVFlagsCodeReader {
fn bits(&mut self, idx: usize) -> u8 { self.bits[idx] }
- fn code(&mut self, idx: usize) -> u32 { self.codes[idx] as u32 }
+ fn code(&mut self, idx: usize) -> u32 { u32::from(self.codes[idx]) }
fn sym (&mut self, idx: usize) -> u8 { idx as u8 }
fn len(&mut self) -> usize { self.bits.len() }
}
impl CodebookDescReader<u16> for CLVSym16CodeReader {
fn bits(&mut self, idx: usize) -> u8 { self.bits[idx] }
- fn code(&mut self, idx: usize) -> u32 { self.codes[idx] as u32 }
+ fn code(&mut self, idx: usize) -> u32 { u32::from(self.codes[idx]) }
fn sym (&mut self, idx: usize) -> u16 { self.syms[idx] }
fn len(&mut self) -> usize { self.bits.len() }
}
mvd: Option<(&'static [u8], &'static [u16], &'static [u16])>, mv_esc: u16,
bias: Option<(&'static [u8], &'static [u16], &'static [u16])>, bias_esc: u16) -> Self {
let flags_cb = if let Some((bits, codes)) = flgd {
- let mut coderead = CLVFlagsCodeReader { bits: bits, codes: codes };
+ let mut coderead = CLVFlagsCodeReader { bits, codes };
Some(Codebook::new(&mut coderead, CodebookMode::MSB).unwrap())
} else {
None
};
let mv_cb = if let Some((bits, codes, syms)) = mvd {
- let mut coderead = CLVSym16CodeReader { bits: bits, codes: codes, syms: syms };
+ let mut coderead = CLVSym16CodeReader { bits, codes, syms };
Some(Codebook::new(&mut coderead, CodebookMode::MSB).unwrap())
} else {
None
};
let bias_cb = if let Some((bits, codes, syms)) = bias {
- let mut coderead = CLVSym16CodeReader { bits: bits, codes: codes, syms: syms };
+ let mut coderead = CLVSym16CodeReader { bits, codes, syms };
Some(Codebook::new(&mut coderead, CodebookMode::MSB).unwrap())
} else {
None
};
- LevelCodes { flags_cb: flags_cb, mv_cb: mv_cb, mv_esc: mv_esc, bias_cb: bias_cb, bias_esc: bias_esc }
- }
-}
-
-#[derive(Debug,Clone,Copy)]
-pub struct MV {
- x: i16,
- y: i16,
-}
-
-impl MV {
- pub fn new(x: i16, y: i16) -> Self { MV{ x: x, y: y } }
- pub fn pred(a: MV, b: MV, c: MV) -> Self {
- let x;
- if a.x < b.x {
- if b.x < c.x {
- x = b.x;
- } else {
- if a.x < c.x { x = c.x; } else { x = a.x; }
- }
- } else {
- if b.x < c.x {
- if a.x < c.x { x = a.x; } else { x = c.x; }
- } else {
- x = b.x;
- }
- }
- let y;
- if a.y < b.y {
- if b.y < c.y {
- y = b.y;
- } else {
- if a.y < c.y { y = c.y; } else { y = a.y; }
- }
- } else {
- if b.y < c.y {
- if a.y < c.y { y = a.y; } else { y = c.y; }
- } else {
- y = b.y;
- }
- }
- MV { x: x, y: y }
- }
-}
-
-pub const ZERO_MV: MV = MV { x: 0, y: 0 };
-
-impl Add for MV {
- type Output = MV;
- fn add(self, other: MV) -> MV { MV { x: self.x + other.x, y: self.y + other.y } }
-}
-
-impl Sub for MV {
- type Output = MV;
- fn sub(self, other: MV) -> MV { MV { x: self.x - other.x, y: self.y - other.y } }
-}
-
-impl fmt::Display for MV {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{},{}", self.x, self.y)
+ LevelCodes { flags_cb, mv_cb, mv_esc, bias_cb, bias_esc }
}
}
let t7 = ((blk[0] - blk[4]) << dshift) + (1 << (shift - 1));
let t8 = t0 + t2;
let t9 = t0 - t2;
- let tA = 181 * (t9 + (t1 - t3)) + 0x80 >> 8;
- let tB = 181 * (t9 - (t1 - t3)) + 0x80 >> 8;
+ let tA = (181 * (t9 + (t1 - t3)) + 0x80) >> 8;
+ let tB = (181 * (t9 - (t1 - t3)) + 0x80) >> 8;
let tC = t1 + t3;
blk[0] = (t6 + t5 + t8) >> shift;
#[allow(non_snake_case)]
#[allow(clippy::erasing_op)]
+#[allow(clippy::identity_op)]
fn dct_col(blk: &mut [i32; 64], col: usize) {
let dshift = 8;
let shift = 14;
let t7 = ((blk[0*8 + col] - blk[4*8 + col]) << dshift) + (1 << (shift - 1));
let t8 = t0 + t2;
let t9 = t0 - t2;
- let tA = 181 * (t9 + (t1 - t3)) + 0x80 >> 8;
- let tB = 181 * (t9 - (t1 - t3)) + 0x80 >> 8;
+ let tA = (181 * (t9 + (t1 - t3)) + 0x80) >> 8;
+ let tB = (181 * (t9 - (t1 - t3)) + 0x80) >> 8;
let tC = t1 + t3;
blk[0*8 + col] = (t6 + t5 + t8) >> shift;
fn clv_dct_dc(blk: &mut [i32; 64]) {
let dval = blk[0] >> 3;
- for i in 0..64 { blk[i] = dval; }
+ for el in blk.iter_mut() { *el = dval; }
}
fn put_blocks(buf: &mut NAVideoBuffer<u8>, xpos: usize, ypos: usize, blk: &[[i32;64]; 6]) {
for j in 0..8 {
for k in 0..8 {
let mut v = blk[0][k + j * 8] + 128;
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxy + k] = v as u8;
}
for k in 0..8 {
let mut v = blk[1][k + j * 8] + 128;
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxy + k + 8] = v as u8;
}
idxy += stridey;
for j in 0..8 {
for k in 0..8 {
let mut v = blk[2][k + j * 8] + 128;
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxy + k] = v as u8;
}
for k in 0..8 {
let mut v = blk[3][k + j * 8] + 128;
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxy + k + 8] = v as u8;
}
idxy += stridey;
for j in 0..8 {
for k in 0..8 {
let mut v = blk[4][k + j * 8] + 128;
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxu + k] = v as u8;
}
for k in 0..8 {
let mut v = blk[5][k + j * 8] + 128;
- if v < 0 { v = 0; } if v > 255 { v = 255; }
+ if v < 0 { v = 0; } else if v > 255 { v = 255; }
framebuf[idxv + k] = v as u8;
}
idxu += strideu;
let dst = &mut dbuf[doff..][..size];
let src = &sbuf[soff..][..size];
for i in 0..size {
- let val = (src[i] as i16) + bias;
+ let val = i16::from(src[i]) + bias;
if val < 0x00 { dst[i] = 0x00; }
else if val > 0xFF { dst[i] = 0xFF; }
else { dst[i] = val as u8; }
let mut idx = 1;
let mut eob = false;
- blk[0] = br.read_cb(dc_cb)? as i32;
+ blk[0] = i32::from(br.read_cb(dc_cb)?);
if !has_ac { return Ok(()); }
let (level, skip) = if val != CLV_AC_ESCAPE {
eob = ((val >> 12) & 1) != 0;
let run = ((val >> 4) & 0xFF) as usize;
- let lev = (val & 0xF) as i32;
+ let lev = i32::from(val & 0xF);
if br.read_bool()? {
(-lev, run)
} else {
let mv = if let Some(ref cb) = lc[level].mv_cb {
let mv_code = br.read_cb(cb)?;
if mv_code != lc[level].mv_esc {
- MV::new(((mv_code & 0xFF) as i8) as i16, (mv_code as i16) >> 8)
+ MV::new(i16::from((mv_code & 0xFF) as i8), (mv_code as i16) >> 8)
} else {
let x = br.read_s(8)? as i16;
let y = br.read_s(8)? as i16;
} else {
0
};
- let mut ti = TileInfo { flags: flags, mv: mv, bias: bias, child: [None, None, None, None] };
+ let mut ti = TileInfo { flags, mv, bias, child: [None, None, None, None] };
if ti.flags != 0 {
for i in 0..4 {
if (ti.flags & (1 << i)) != 0 {
ClearVideoDecoder {
info: dummy_info,
- dc_cb: dc_cb, ac_cb: ac_cb,
+ dc_cb, ac_cb,
frmmgr: HAMShuffler::new(),
- is_rm: is_rm,
+ is_rm,
ylev: [
LevelCodes::new(Some((CLV_FLAGSY_0_BITS, CLV_FLAGSY_0_CODES)),
Some((CLV_MVY_0_BITS, CLV_MVY_0_CODES, CLV_MVY_0_SYMS)), CLV_MVY_0_ESCAPE,
let mut blks: [[i32; 64]; 6] = [[0; 64]; 6];
let mut has_ac: [bool; 6] = [false; 6];
- for i in 0..6 { has_ac[i] = br.read_bool()? }
+ for flag in has_ac.iter_mut() { *flag = br.read_bool()?; }
for i in 0..4 {
decode_dct_block(br, &mut blks[i], ac_quant, has_ac[i], &self.dc_cb, &self.ac_cb)?;
let mut br = BitReader::new(&src[(off + 1)..], src.len() - (off + 1), BitReaderMode::BE);
let vinfo = self.info.get_properties().get_video_info().unwrap();
- let bufret = alloc_video_buffer(vinfo, self.tsize);
- if let Err(_) = bufret { return Err(DecoderError::InvalidData); }
- let bufinfo = bufret.unwrap();
+ let bufinfo = alloc_video_buffer(vinfo, self.tsize)?;
let mut buf = bufinfo.get_vbuf().unwrap();
if is_intra {
];
pub fn generic_register_all_codecs(rd: &mut RegisteredDecoders) {
- for decoder in DECODERS.into_iter() {
+ for decoder in DECODERS.iter() {
rd.add_decoder(decoder.clone());
}
}
fn get_duration(ainfo: &NAAudioInfo, duration: Option<u64>, data_size: usize) -> u64 {
if duration == None {
let size_bits = (data_size as u64) * 8;
- let blk_size = (ainfo.get_channels() as u64) * (ainfo.get_format().get_bits() as u64);
+ let blk_size = u64::from(ainfo.get_channels()) * u64::from(ainfo.get_format().get_bits());
size_bits / blk_size
} else {
- duration.unwrap() as u64
+ duration.unwrap()
}
}
use std::f32::consts::PI;
#[derive(Clone,Copy,PartialEq)]
+#[allow(clippy::enum_variant_names)]
enum SiproMode {
Mode16k,
Mode8_5k,
}
impl SiproMode {
- fn is16k(&self) -> bool { *self == SiproMode::Mode16k }
+ fn is16k(self) -> bool { self == SiproMode::Mode16k }
}
const SIPRO_MODE_FROM_IDX: [SiproMode; 4] = [
fn update_gain_16k(&mut self, sf: usize) {
let mut energy: f64 = 0.0;
for i in 0..80 {
- energy += (self.fix_vec[i] as f64) * (self.fix_vec[i] as f64);
+ energy += f64::from(self.fix_vec[i]) * f64::from(self.fix_vec[i]);
}
- let ehist = ((0.8 * self.energy_hist[0] + 0.6 * self.energy_hist[1]) as f64) - 71.30899869919435856603;
+ let ehist = f64::from(0.8 * self.energy_hist[0] + 0.6 * self.energy_hist[1]) - 71.30899869919435856603;
let rms = 8.94427190999915878559 * (10.0f64.ln() / 20.0 * ehist).exp() / (0.01 + energy).sqrt();
let gain = SIPRO_GAIN_CB_16K[self.gc_index[sf]] * (rms as f32);
}
self.energy_hist[3] = 20.0 * gain1.log10();
- let gain = ((gain1 as f64) * ((sum as f64) * (10.0f64).ln() * 0.05).exp() / (self.avg_energy as f64).sqrt()) as f32;
+ let gain = (f64::from(gain1) * (f64::from(sum) * (10.0f64).ln() * 0.05).exp() / f64::from(self.avg_energy).sqrt()) as f32;
let exc = &mut self.excitation[EXCITATION_OFFSET + sf * 48..][..48];
for i in 0..48 {
exc[i] = exc[i] * gain0 + self.fix_vec[i] * gain;
fn lsp2poly(lsp: &[f32], poly: &mut [f64], order: usize) {
poly[0] = 1.0;
- poly[1] = -2.0 * (lsp[0] as f64);
+ poly[1] = -2.0 * f64::from(lsp[0]);
for i in 1..order {
- poly[i + 1] = -2.0 * (lsp[2 * i] as f64) * poly[i] + 2.0 * poly[i - 1];
+ poly[i + 1] = -2.0 * f64::from(lsp[2 * i]) * poly[i] + 2.0 * poly[i - 1];
for j in (2..i+1).rev() {
- poly[j] += -2.0 * (lsp[2 * i] as f64) * poly[j - 1] + poly[j - 2];
+ poly[j] += -2.0 * f64::from(lsp[2 * i]) * poly[j - 1] + poly[j - 2];
}
- poly[1] += -2.0 * (lsp[2 * i] as f64);
+ poly[1] += -2.0 * f64::from(lsp[2 * i]);
}
}
lsp2poly(&lsp[0..], &mut a[0..], 5);
lsp2poly(&lsp[1..], &mut b[1..], 4);
- let ascale = (1.0 + lsp[9]) as f64;
- let bscale = (1.0 - lsp[9]) as f64;
+ let ascale = f64::from(1.0 + lsp[9]);
+ let bscale = f64::from(1.0 - lsp[9]);
for i in 1..5 {
let ta = ascale * a[i];
let tb = bscale * (b[i + 1] - b[i - 1]);
self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(),
1,
SND_F32P_FORMAT, 0);
- self.info = info.replace_info(NACodecTypeInfo::Audio(self.ainfo.clone()));
+ self.info = info.replace_info(NACodecTypeInfo::Audio(self.ainfo));
Ok(())
} else {
Err(DecoderError::InvalidData)
xsincos[k].im = -factor.sin();
}
let fft = FFTBuilder::new_fft(size/4, false);
- IMDCTContext { xsincos: xsincos, size: size, fft: fft }
+ IMDCTContext { xsincos, size, fft }
}
#[allow(non_snake_case)]
fn do_imdct(&mut self, coeffs: &[i32; BLOCK_LEN], tmp: &mut IMDCTWorkspace) {
impl Syncinfo {
fn read(br: &mut BitReader) -> DecoderResult<Self> {
let syncword = br.read(16)?;
- validate!(syncword == ((MAGIC_BYTE0 as u32) * 256) + (MAGIC_BYTE1 as u32));
+ validate!(syncword == (u32::from(MAGIC_BYTE0) * 256) + u32::from(MAGIC_BYTE1));
let crc1 = br.read(16)? as u16;
let fscod = br.read(2)? as usize;
let frmsizecod = br.read(6)? as usize;
- Ok(Syncinfo { crc1: crc1, fscod: fscod as u8, frmsizecod: frmsizecod as u8,
+ Ok(Syncinfo { crc1, fscod: fscod as u8, frmsizecod: frmsizecod as u8,
samplerate: SAMPLE_RATES[fscod], frame_size: FRAME_SIZES[fscod][frmsizecod] * 2 })
}
fn is_valid(&self) -> bool {
}
impl ACMode {
- fn get_num_channels(&self) -> usize {
- match *self {
+ fn get_num_channels(self) -> usize {
+ match self {
ACMode::DualMono => 2,
ACMode::Mono => 1,
ACMode::Stereo => 2,
ACMode::Mode3_2 => 5,
}
}
- fn get_channel_map_str(&self) -> &'static str {
- match *self {
+ fn get_channel_map_str(self) -> &'static str {
+ match self {
ACMode::DualMono => "C,C",
ACMode::Mono => "C",
ACMode::Stereo => "L,R",
ACMode::Mode3_2 => "L,C,R,Ls,Rs",
}
}
- fn get_channel_map(&self, has_lfe: bool) -> NAChannelMap {
+ fn get_channel_map(self, has_lfe: bool) -> NAChannelMap {
let mut chmap = NAChannelMap::from_str(self.get_channel_map_str()).unwrap();
if has_lfe {
chmap.add_channel(NAChannelType::LFE);
}
chmap
}
- fn is_3_x(&self) -> bool {
- match *self {
+ fn is_3_x(self) -> bool {
+ match self {
ACMode::Mode3_0 |
ACMode::Mode3_1 |
ACMode::Mode3_2 => true,
_ => false,
}
}
- fn is_surround(&self) -> bool {
- match *self {
+ fn is_surround(self) -> bool {
+ match self {
ACMode::Mode2_1 |
ACMode::Mode3_1 |
ACMode::Mode2_2 |
Ok(BSI{
bsid, shift, bsmod, acmod, lfeon,
cmixlev, surmixlev, dsurmod,
- mixinfo: mixinfo, mixinfo2: mixinfo2,
+ mixinfo, mixinfo2,
copysmth, origbs, timecod1, timecod2, has_addb,
})
}
let bndpsd = &mut self.bndpsd;
for bin in start..end {
- psd[bin] = 3072 - ((exps[bin] as i16) << 7);
+ psd[bin] = 3072 - (i16::from(exps[bin]) << 7);
}
let mut bin = start;
let mut lastbin;
loop {
lastbin = ((TS102366_BAND_START[band] as usize) + (TS102366_BAND_SIZE[band] as usize)).min(end);
- bndpsd[band] = psd[bin] as i32;
+ bndpsd[band] = i32::from(psd[bin]);
bin += 1;
while bin < lastbin {
- bndpsd[band] = logadd(bndpsd[band], psd[bin] as i32);
+ bndpsd[band] = logadd(bndpsd[band], i32::from(psd[bin]));
bin += 1;
}
band += 1;
}
fn compute_mask(&mut self, mask: &mut [i32; MAX_BANDS], fscod: usize, sgain: u16, fdecay: u8, sdecay: u8,
dbknee: u16, cplfleak: u16, cplsleak: u16, shift: u8) {
- let fgain = TS102366_FAST_GAIN[self.fgaincod] as i32;
+ let fgain = i32::from(TS102366_FAST_GAIN[self.fgaincod]);
let bndstart = TS102366_BIN_TO_BAND[self.startmant] as usize;
let bndend = (TS102366_BIN_TO_BAND[self.endmant - 1] as usize) + 1;
lowcomp = calc_lowcomp(lowcomp, self.bndpsd[band], self.bndpsd[band + 1], band);
}
fast_leak = self.bndpsd[band] - fgain;
- slow_leak = self.bndpsd[band] - (sgain as i32);
+ slow_leak = self.bndpsd[band] - i32::from(sgain);
excite[band] = fast_leak - lowcomp;
- if not_lfe_case {
- if self.bndpsd[band] <= self.bndpsd[band + 1] {
- sband = band + 1;
- break;
- }
+ if not_lfe_case && (self.bndpsd[band] <= self.bndpsd[band + 1]) {
+ sband = band + 1;
+ break;
}
}
for band in sband..bndend.min(22) {
if (bndend != 7) || (band != 6) {
lowcomp = calc_lowcomp(lowcomp, self.bndpsd[band], self.bndpsd[band + 1], band);
}
- fast_leak = (fast_leak - (fdecay as i32)).max(self.bndpsd[band] - (fgain as i32));
- slow_leak = (slow_leak - (sdecay as i32)).max(self.bndpsd[band] - (sgain as i32));
+ fast_leak = (fast_leak - i32::from(fdecay)).max(self.bndpsd[band] - fgain);
+ slow_leak = (slow_leak - i32::from(sdecay)).max(self.bndpsd[band] - i32::from(sgain));
excite[band] = slow_leak.max(fast_leak - lowcomp);
}
begin = 22;
} else {
begin = bndstart;
- fast_leak = cplfleak as i32;
- slow_leak = cplsleak as i32;
+ fast_leak = i32::from(cplfleak);
+ slow_leak = i32::from(cplsleak);
}
for band in begin..bndend {
- fast_leak = (fast_leak - (fdecay as i32)).max(self.bndpsd[band] - (fgain as i32));
- slow_leak = (slow_leak - (sdecay as i32)).max(self.bndpsd[band] - (sgain as i32));
+ fast_leak = (fast_leak - i32::from(fdecay)).max(self.bndpsd[band] - fgain);
+ slow_leak = (slow_leak - i32::from(sdecay)).max(self.bndpsd[band] - i32::from(sgain));
excite[band] = fast_leak.max(slow_leak);
}
for band in bndstart..bndend {
- if self.bndpsd[band] < (dbknee as i32) {
- excite[band] += ((dbknee as i32) - self.bndpsd[band]) >> 2;
+ if self.bndpsd[band] < i32::from(dbknee) {
+ excite[band] += (i32::from(dbknee) - self.bndpsd[band]) >> 2;
}
- mask[band] = excite[band].max(TS102366_HTH[fscod][band >> shift] as i32);
+ mask[band] = excite[band].max(i32::from(TS102366_HTH[fscod][band >> shift]));
}
}
fn apply_delta_info(&mut self, mask: &mut [i32; MAX_BANDS]) {
for seg in 0..self.deltnseg {
band += self.deltoffst[seg] as usize;
let delta = if self.deltba[seg] >= 4 {
- ((self.deltba[seg] as i32) - 3) << 7
+ (i32::from(self.deltba[seg]) - 3) << 7
} else {
- ((self.deltba[seg] as i32) - 4) << 7
+ (i32::from(self.deltba[seg]) - 4) << 7
};
if band + self.deltlen[seg] > MAX_BANDS { break; }
for _ in 0..self.deltlen[seg] {
}
}
fn calc_snr_offset(&mut self, csnroffst: u8) {
- self.snroffset = ((((csnroffst as i32) - 15) << 4) + (self.fsnroffst as i32)) << 2;
+ self.snroffset = (((i32::from(csnroffst) - 15) << 4) + i32::from(self.fsnroffst)) << 2;
}
fn compute_bap(&mut self, mask: &mut [i32; MAX_BANDS], floor: u16) {
let end = self.endmant;
let mut lastbin;
loop {
lastbin = ((TS102366_BAND_START[band] as usize) + (TS102366_BAND_SIZE[band] as usize)).min(end);
- mask[band] = (mask[band] - self.snroffset - (floor as i32)).max(0) & 0x1FE0;
- mask[band] += floor as i32;
+ mask[band] = (mask[band] - self.snroffset - i32::from(floor)).max(0) & 0x1FE0;
+ mask[band] += i32::from(floor);
while bin < lastbin {
- let addr = (((self.psd[bin] as i32) - mask[band]) >> 5).min(63).max(0) as usize;
+ let addr = ((i32::from(self.psd[bin]) - mask[band]) >> 5).min(63).max(0) as usize;
self.bap[bin] = TS102366_BAPTAB[addr];
bin += 1;
}
validate!(self.bap[bin] < 15);
let nbits = TS102366_BAP_BITS[(self.bap[bin] as usize) - 6];
let val = br.read(nbits)? as i16;
- ((val << (16 - nbits)) as i32) << 9
+ i32::from(val << (16 - nbits)) << 9
},
};
self.mant[bin] >>= self.exps[bin];
let c = acc - add;
let addr = (c.abs() >> 1).min(255);
if c >= 0 {
- acc + (TS102366_LATAB[addr as usize] as i32)
+ acc + i32::from(TS102366_LATAB[addr as usize])
} else {
- add + (TS102366_LATAB[addr as usize] as i32)
+ add + i32::from(TS102366_LATAB[addr as usize])
}
}
fn overlap(delay: &mut [f32; BLOCK_LEN], src: &[f32; BLOCK_LEN * 2], out: &mut [f32]) {
{
let dly = &delay;
- for ((d, s), o) in dly.into_iter().zip(src.into_iter()).zip(out.iter_mut()) {
+ for ((d, s), o) in dly.iter().zip(src.iter()).zip(out.iter_mut()) {
*o = (*d + *s) * 2.0;
}
}
if self.cplinu {
self.chdata[CPL_CHANNEL].compute_bndpsd();
self.chdata[CPL_CHANNEL].compute_mask(&mut mask, fscod, sgain, fdecay, sdecay, dbknee,
- ((self.cplfleak as u16) << 8) + 768, ((self.cplsleak as u16) << 8) + 768, bsi.shift);
+ (u16::from(self.cplfleak) << 8) + 768, (u16::from(self.cplsleak) << 8) + 768, bsi.shift);
self.chdata[CPL_CHANNEL].apply_delta_info(&mut mask);
self.chdata[CPL_CHANNEL].calc_snr_offset(self.csnroffst);
self.chdata[CPL_CHANNEL].compute_bap(&mut mask, floor);
for band in self.cplbegf..self.cplendf {
let cband = band - self.cplbegf;
let comant = self.chdata[ch].cplcomant[cband];
- let mut cotemp = (if self.chdata[ch].cplcoexp[cband] == 15 { comant << 1 } else { comant + 16 }) as i32;
+ let mut cotemp = i32::from(if self.chdata[ch].cplcoexp[cband] == 15 { comant << 1 } else { comant + 16 });
if (acmod == ACMode::Stereo) && (ch == 1) && self.phsflginu && self.phsflg[pband] {
cotemp = -cotemp;
}
let exp = self.chdata[ch].cplcoexp[cband] + 3 * self.chdata[ch].mstrcplco + 5 - 3;
let start = band * 12 + 37;
for bin in 0..12 {
- self.chdata[ch].mant[start + bin] = self.chdata[CPL_CHANNEL].mant[start + bin] * cotemp >> exp;
+ self.chdata[ch].mant[start + bin] = (self.chdata[CPL_CHANNEL].mant[start + bin] * cotemp) >> exp;
}
//todo dither
}
let bsi = BSI::read(&mut br)?;
if bsi.has_addb {
- let len = br.read(6)? as u32;
+ let len = br.read(6)?;
br.skip((len + 1) * 8)?;
}
self.ablk.synth_audio_block(&mut self.imdct512, &mut self.imdct256, &mut self.tmp, ch, &mut self.delay[ch], dst);
} else {
self.delay[ch] = [0.0; BLOCK_LEN];
- for i in 0..BLOCK_LEN { dst[i] = 0.0; }
+ for el in dst.iter_mut().take(BLOCK_LEN) { *el = 0.0; }
}
}
if bsi.lfeon {
self.ablk.synth_audio_block(&mut self.imdct512, &mut self.imdct256, &mut self.tmp, LFE_CHANNEL, &mut self.delay[LFE_CHANNEL], dst);
} else {
self.delay[LFE_CHANNEL] = [0.0; BLOCK_LEN];
- for i in 0..BLOCK_LEN { dst[i] = 0.0; }
+ for el in dst.iter_mut().take(BLOCK_LEN) { *el = 0.0; }
}
}
}
}
let stream_no = (tag[0] - b'0') * 10 + (tag[1] - b'0');
let str = strmgr.get_stream(stream_no as usize);
- if let None = str { return Err(InvalidData); }
+ if str.is_none() { return Err(InvalidData); }
let stream = str.unwrap();
if size == 0 {
self.movi_size -= 8;
return Ok((size, true));
}
- for i in 0..CHUNKS.len() {
- if RIFFTag::Chunk(tag) == CHUNKS[i].tag {
- let psize = (CHUNKS[i].parse)(self, strmgr, size)?;
+ for chunk in CHUNKS.iter() {
+ if RIFFTag::Chunk(tag) == chunk.tag {
+ let psize = (chunk.parse)(self, strmgr, size)?;
if psize != size { return Err(InvalidData); }
if (psize & 1) == 1 { self.src.read_skip(1)?; }
return Ok((size + 8, false));
}
- if RIFFTag::List(tag, ltag) == CHUNKS[i].tag {
+ if RIFFTag::List(tag, ltag) == chunk.tag {
let mut rest_size = size - 4;
- let psize = (CHUNKS[i].parse)(self, strmgr, rest_size)?;
+ let psize = (chunk.parse)(self, strmgr, rest_size)?;
if psize > rest_size { return Err(InvalidData); }
rest_size -= psize;
while rest_size > 0 {
let (psize, _) = self.parse_chunk(strmgr, end_tag, rest_size, depth+1)?;
if psize > rest_size { return Err(InvalidData); }
rest_size -= psize;
- if (psize & 1) == 1 {
- if rest_size > 0 {
- rest_size -= 1;
- }
+ if ((psize & 1) == 1) && (rest_size > 0) {
+ rest_size -= 1;
}
}
self.src.read_skip(size - 4)?;
}
if (size & 1) == 1 { self.src.read_skip(1)?; }
- return Ok((size + 8, false));
+ Ok((size + 8, false))
}
fn read_header(&mut self, strmgr: &mut StreamManager) -> DemuxerResult<()> {
fn read_extradata(&mut self, size: usize) -> DemuxerResult<Option<Vec<u8>>> {
if size == 0 { return Ok(None); }
- let mut edvec: Vec<u8> = Vec::with_capacity(size);
- edvec.resize(size, 0);
+ let mut edvec: Vec<u8> = vec![0; size];
self.src.read_buf(&mut edvec)?;
Ok(Some(edvec))
}
];
fn is_list_tag(tag: u32) -> bool {
- for i in 0..CHUNKS.len() {
- if let RIFFTag::List(ltag, _) = CHUNKS[i].tag {
+ for chunk in CHUNKS.iter() {
+ if let RIFFTag::List(ltag, _) = chunk.tag {
if tag == ltag {
return true;
}
}
fn parse_strf(dmx: &mut AVIDemuxer, strmgr: &mut StreamManager, size: usize) -> DemuxerResult<usize> {
- if let None = dmx.sstate.strm_type { return Err(InvalidData); }
+ if dmx.sstate.strm_type.is_none() { return Err(InvalidData); }
match dmx.sstate.strm_type.unwrap() {
StreamType::Video => parse_strf_vids(dmx, strmgr, size),
StreamType::Audio => parse_strf_auds(dmx, strmgr, size),
Some(name) => name,
};
let vinfo = NACodecInfo::new(cname, vci, edata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Video, dmx.sstate.strm_no as u32, vinfo, dmx.tb_num, dmx.tb_den));
- if let None = res { return Err(MemoryError); }
+ let res = strmgr.add_stream(NAStream::new(StreamType::Video, u32::from(dmx.sstate.strm_no), vinfo, dmx.tb_num, dmx.tb_den));
+ if res.is_none() { return Err(MemoryError); }
dmx.sstate.reset();
Ok(size)
}
Some(name) => name,
};
let ainfo = NACodecInfo::new(cname, NACodecTypeInfo::Audio(ahdr), edata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Audio, dmx.sstate.strm_no as u32, ainfo, dmx.tb_num, dmx.tb_den));
- if let None = res { return Err(MemoryError); }
+ let res = strmgr.add_stream(NAStream::new(StreamType::Audio, u32::from(dmx.sstate.strm_no), ainfo, dmx.tb_num, dmx.tb_den));
+ if res.is_none() { return Err(MemoryError); }
dmx.sstate.reset();
Ok(size)
}
fn parse_strf_xxxx(dmx: &mut AVIDemuxer, strmgr: &mut StreamManager, size: usize) -> DemuxerResult<usize> {
let edata = dmx.read_extradata(size)?;
let info = NACodecInfo::new("unknown", NACodecTypeInfo::None, edata);
- let res = strmgr.add_stream(NAStream::new(StreamType::Data, dmx.sstate.strm_no as u32, info, dmx.tb_num, dmx.tb_den));
- if let None = res { return Err(MemoryError); }
+ let res = strmgr.add_stream(NAStream::new(StreamType::Data, u32::from(dmx.sstate.strm_no), info, dmx.tb_num, dmx.tb_den));
+ if res.is_none() { return Err(MemoryError); }
dmx.sstate.reset();
Ok(size)
}
}
#[cfg(feature="demuxer_avi")]
+#[allow(clippy::cast_lossless)]
mod avi;
-const DEMUXERS: &[&'static DemuxerCreator] = &[
+const DEMUXERS: &[&DemuxerCreator] = &[
#[cfg(feature="demuxer_avi")]
&avi::AVIDemuxerCreator {},
];
pub fn generic_register_all_demuxers(rd: &mut RegisteredDemuxers) {
- for demuxer in DEMUXERS.into_iter() {
+ for demuxer in DEMUXERS.iter() {
rd.add_demuxer(*demuxer);
}
}
extern crate nihav_core;
#[cfg(feature="decoders")]
+#[allow(clippy::unreadable_literal)]
+#[allow(clippy::too_many_arguments)]
+#[allow(clippy::excessive_precision)]
pub mod codecs;
#[cfg(feature="demuxers")]