forge
Explore
Log in

Don't you dare go Hollow

Clear new warnings and clippy

Browse files at this commit

380bb54f43878731e1b81b6907193d72add989a6Ahmet Kaan GümüşParent: bc04ed9
  • fix
    • clear new warnings and clippy
Show full message
fix: clear new warnings and clippy
crates/ec-aac/src/sbr_chain.rsmodified+8 -8
@@ -442,7 +442,7 @@ impl SbrChain {
442 qmfdump_energies("post_patch", tables.kx as usize, &hf);442 qmfdump_energies("post_patch", tables.kx as usize, &hf);
443 }443 }
444 let (env_energy, noise_energy) =444 let (env_energy, noise_energy) =
445- sbr_env::dequantize_frame(&header, &data.channels, ch, coupling);445+ sbr_env::dequantize_frame(&data.channels, ch, coupling);
446 // sbr_env::adjust works in QMF-slot units; the parsed borders446 // sbr_env::adjust works in QMF-slot units; the parsed borders
447 // are in the coarser envelope-time-slot units (see RATE above).447 // are in the coarser envelope-time-slot units (see RATE above).
448 let scaled = SbrChannel {448 let scaled = SbrChannel {
@@ -470,8 +470,8 @@ impl SbrChain {
470 v470 v
471 })471 })
472 .collect();472 .collect();
473- for m in 0..m_max {473+ for (m, band) in hf.iter().enumerate().take(m_max) {
474- state.hf_tail[m] = hf[m][num_slots.saturating_sub(HF_ADJ)..].to_vec();474+ state.hf_tail[m] = band[num_slots.saturating_sub(HF_ADJ)..].to_vec();
475 }475 }
476 sbr_env::adjust(476 sbr_env::adjust(
477 &mut xh,477 &mut xh,
@@ -490,12 +490,12 @@ impl SbrChain {
490 let i_temp = state.y_carry.first().map(Vec::len).unwrap_or(0).min(num_slots);490 let i_temp = state.y_carry.first().map(Vec::len).unwrap_or(0).min(num_slots);
491 let t_end = (scaled.t_env.last().copied().unwrap_or(0).max(0) as usize).min(xh[0].len());491 let t_end = (scaled.t_env.last().copied().unwrap_or(0).max(0) as usize).min(xh[0].len());
492 let mut hf: Vec<Vec<Complex<f64>>> = vec![vec![Complex::ZERO; num_slots]; m_max];492 let mut hf: Vec<Vec<Complex<f64>>> = vec![vec![Complex::ZERO; num_slots]; m_max];
493- for m in 0..m_max {493+ for (m, band) in hf.iter_mut().enumerate().take(m_max) {
494- for i in 0..i_temp {494+ for (i, slot) in band.iter_mut().enumerate().take(i_temp) {
495- hf[m][i] = state.y_carry[m][i];495+ *slot = state.y_carry[m][i];
496 }496 }
497- for i in i_temp..num_slots {497+ for (i, slot) in band.iter_mut().enumerate().take(num_slots).skip(i_temp) {
498- hf[m][i] = xh[m][i];498+ *slot = xh[m][i];
499 }499 }
500 }500 }
501 state.y_carry = (0..m_max)501 state.y_carry = (0..m_max)
crates/ec-aac/src/sbr_env.rsmodified+4 -3
@@ -75,7 +75,6 @@ pub fn dequant_noise_pair(q0_raw: i32, pan_raw: i32) -> (f64, f64) {
75 /// de-mixing through [`dequant_pair`]/[`dequant_noise_pair`] when75 /// de-mixing through [`dequant_pair`]/[`dequant_noise_pair`] when
76 /// `coupling` makes `channels[1]` a balance channel against `channels[0]`.76 /// `coupling` makes `channels[1]` a balance channel against `channels[0]`.
77 pub fn dequantize_frame(77 pub fn dequantize_frame(
78- header: &SbrHeader,
79 channels: &[SbrChannel],78 channels: &[SbrChannel],
80 ch: usize,79 ch: usize,
81 coupling: bool,80 coupling: bool,
@@ -173,7 +172,9 @@ fn noise_fraction_debug() -> bool {
173 std::env::var("EC_AAC_SBR_NOISE_FRACTION").is_ok()172 std::env::var("EC_AAC_SBR_NOISE_FRACTION").is_ok()
174 }173 }
175 174
176-static NOISE_FRACTION: std::sync::OnceLock<std::sync::Mutex<Vec<(usize, f64, f64, f64)>>> =175+type NoiseFractionRows = Vec<(usize, f64, f64, f64)>;
176+
177+static NOISE_FRACTION: std::sync::OnceLock<std::sync::Mutex<NoiseFractionRows>> =
177 std::sync::OnceLock::new();178 std::sync::OnceLock::new();
178 179
179 /// Diagnostic (`EC_AAC_SBR_NOISE_FRACTION`): per absolute QMF band,180 /// Diagnostic (`EC_AAC_SBR_NOISE_FRACTION`): per absolute QMF band,
@@ -559,7 +560,7 @@ mod tests {
559 let e: f64 = hf[m].iter().map(|c| c.norm_sqr()).sum::<f64>() / slots as f64;560 let e: f64 = hf[m].iter().map(|c| c.norm_sqr()).sum::<f64>() / slots as f64;
560 if m == mid {561 if m == mid {
561 // S_M^2 = E_orig/(1+Q) = 4, boost capped at 1.5849^2 at most.562 // S_M^2 = E_orig/(1+Q) = 4, boost capped at 1.5849^2 at most.
562- assert!(e >= 4.0 - 1e-9 && e <= 4.0 * BOOST_MAX * BOOST_MAX + 1e-6, "mid {e}");563+ assert!((4.0 - 1e-9..=4.0 * BOOST_MAX * BOOST_MAX + 1e-6).contains(&e), "mid {e}");
563 // Phase walks 0,90,180,270 degrees per slot.564 // Phase walks 0,90,180,270 degrees per slot.
564 assert!((hf[m][0].re - hf[m][0].norm_sqr().sqrt()).abs() < 1e-9 && hf[m][1].re.abs() < 1e-9);565 assert!((hf[m][0].re - hf[m][0].norm_sqr().sqrt()).abs() < 1e-9 && hf[m][1].re.abs() < 1e-9);
565 } else {566 } else {
crates/ec-aac/src/sbr_hf.rsmodified+1 -1
@@ -153,7 +153,7 @@ pub fn build_patches(tables: &BandTables) -> Vec<Patch> {
153 }153 }
154 last_k = k;154 last_k = k;
155 last_msb = msb;155 last_msb = msb;
156- let mut odd = 0i64;156+ let mut odd;
157 let mut i = k;157 let mut i = k;
158 loop {158 loop {
159 sb = fm[i];159 sb = fm[i];
crates/ec-aac/src/sbr_payload.rsmodified+0 -1
@@ -650,7 +650,6 @@ impl SbrParser {
650 let mut channels = Vec::with_capacity(n_channels);650 let mut channels = Vec::with_capacity(n_channels);
651 for ch in 0..n_channels {651 for ch in 0..n_channels {
652 let balance = is_cpe && coupling && ch == 1;652 let balance = is_cpe && coupling && ch == 1;
653- let num_env = grids[ch].num_env;
654 let amp_res = amp_res_of(header.amp_res, &grids[ch]);653 let amp_res = amp_res_of(header.amp_res, &grids[ch]);
655 let e_q = e_q_all[ch].clone();654 let e_q = e_q_all[ch].clone();
656 let q_q = q_q_all[ch].clone();655 let q_q = q_q_all[ch].clone();
crates/ec-aac/src/sbr_qmf.rsmodified+6 -10
@@ -82,9 +82,9 @@ impl QmfAnalysis64 {
82 let row = k * 128;82 let row = k * 128;
83 let mut re = 0.0f64;83 let mut re = 0.0f64;
84 let mut im = 0.0f64;84 let mut im = 0.0f64;
85- for n in 0..128 {85+ for (n, &u_n) in u.iter().enumerate() {
86- re += u[n] * self.cos_tab[row + n];86+ re += u_n * self.cos_tab[row + n];
87- im += u[n] * self.sin_tab[row + n];87+ im += u_n * self.sin_tab[row + n];
88 }88 }
89 *slot = Complex::new(re, im);89 *slot = Complex::new(re, im);
90 }90 }
@@ -160,9 +160,9 @@ impl Analysis {
160 for (k, slot) in out.iter_mut().enumerate() {160 for (k, slot) in out.iter_mut().enumerate() {
161 let row = k * 64;161 let row = k * 64;
162 let (mut re, mut im) = (0.0f64, 0.0f64);162 let (mut re, mut im) = (0.0f64, 0.0f64);
163- for n in 0..64 {163+ for (n, &u_n) in u.iter().enumerate() {
164- re += u[n] * self.cos_tab[row + n];164+ re += u_n * self.cos_tab[row + n];
165- im += u[n] * self.sin_tab[row + n];165+ im += u_n * self.sin_tab[row + n];
166 }166 }
167 *slot = Complex::new(re, im);167 *slot = Complex::new(re, im);
168 }168 }
@@ -512,10 +512,6 @@ mod tests {
512 /// checked against `f_calib(p) + (q-p)/256` (`1/256` being512 /// checked against `f_calib(p) + (q-p)/256` (`1/256` being
513 /// `SYNTHESIS_BANDS`'s own `omega_step/(2*pi)` band spacing) rather than513 /// `SYNTHESIS_BANDS`'s own `omega_step/(2*pi)` band spacing) rather than
514 /// a hand-derived absolute constant.514 /// a hand-derived absolute constant.
515- ///
516-
517-
518-
519 /// (Round-43, Task 1 conviction) The tone-excitation gain above515 /// (Round-43, Task 1 conviction) The tone-excitation gain above
520 /// (0.595853 amplitude / ~0.355 energy) was calibrated with a single516 /// (0.595853 amplitude / ~0.355 energy) was calibrated with a single
521 /// SLOWLY ROTATING phasor -- narrowband within its own subband's517 /// SLOWLY ROTATING phasor -- narrowband within its own subband's
crates/ec-h264/src/enc/vlc.rsmodified+2 -2
@@ -266,8 +266,8 @@ mod tests {
266 }266 }
267 let mut w = BitWriter::new();267 let mut w = BitWriter::new();
268 let mut tcs = [0u8; 4];268 let mut tcs = [0u8; 4];
269- for j in 0..4 {269+ for (j, tc) in tcs.iter_mut().enumerate() {
270- tcs[j] = write_residual_block(270+ *tc = write_residual_block(
271 &mut w,271 &mut w,
272 &super::super::entropy::sub_block_4x4(&c8, j),272 &super::super::entropy::sub_block_4x4(&c8, j),
273 16,273 16,
crates/ec-opus/src/silk_enc.rsmodified+10 -10
@@ -464,8 +464,8 @@ fn quantize_stage2(
464 // mean (silk.rs's nlsf_decode: weights come from the *stage-1* nlsf,464 // mean (silk.rs's nlsf_decode: weights come from the *stage-1* nlsf,
465 // not the final decoded one, so this is not circular).465 // not the final decoded one, so this is not circular).
466 let mut cb1_q15 = [0i16; MAX_LPC_ORDER];466 let mut cb1_q15 = [0i16; MAX_LPC_ORDER];
467- for i in 0..order {467+ for (i, slot) in cb1_q15.iter_mut().enumerate().take(order) {
468- cb1_q15[i] = (cb.cb1_q8[cb1_index * order + i] as i16) << 7;468+ *slot = (cb.cb1_q8[cb1_index * order + i] as i16) << 7;
469 }469 }
470 let w_qw = nlsf_vq_weights_laroia(&cb1_q15[..order]);470 let w_qw = nlsf_vq_weights_laroia(&cb1_q15[..order]);
471 471
@@ -610,7 +610,7 @@ pub(crate) fn estimate_pitch(frame: &[f32], fs_khz: i32, nb_subfr: usize) -> Opt
610 // Per-subframe lags: local search around the global lag.610 // Per-subframe lags: local search around the global lag.
611 let sub_len = frame.len() / nb_subfr.max(1);611 let sub_len = frame.len() / nb_subfr.max(1);
612 let mut per_sub = [0i32; MAX_NB_SUBFR];612 let mut per_sub = [0i32; MAX_NB_SUBFR];
613- for k in 0..nb_subfr {613+ for (k, slot) in per_sub.iter_mut().enumerate().take(nb_subfr) {
614 let start = k * sub_len;614 let start = k * sub_len;
615 let end = (start + sub_len).min(frame.len());615 let end = (start + sub_len).min(frame.len());
616 let sub = &frame[start..end];616 let sub = &frame[start..end];
@@ -625,7 +625,7 @@ pub(crate) fn estimate_pitch(frame: &[f32], fs_khz: i32, nb_subfr: usize) -> Opt
625 sk_lag = lag;625 sk_lag = lag;
626 }626 }
627 }627 }
628- per_sub[k] = sk_lag as i32;628+ *slot = sk_lag as i32;
629 }629 }
630 630
631 // Match the per-subframe lags against the decoder's contour tables.631 // Match the per-subframe lags against the decoder's contour tables.
@@ -660,7 +660,7 @@ pub(crate) fn estimate_pitch(frame: &[f32], fs_khz: i32, nb_subfr: usize) -> Opt
660 let lag = best_lag as i32;660 let lag = best_lag as i32;
661 let mut best_contour = 0usize;661 let mut best_contour = 0usize;
662 let mut best_contour_err = i64::MAX;662 let mut best_contour_err = i64::MAX;
663- for col in 0..n_cols {663+ for (col, _) in table[0].iter().enumerate().take(n_cols) {
664 let mut err = 0i64;664 let mut err = 0i64;
665 for (k, per_sub_k) in per_sub.iter().enumerate().take(nb_subfr) {665 for (k, per_sub_k) in per_sub.iter().enumerate().take(nb_subfr) {
666 let predicted = lag + table[k][col] as i32;666 let predicted = lag + table[k][col] as i32;
@@ -773,8 +773,8 @@ mod tests {
773 let order = 16;773 let order = 16;
774 // A plausible ascending NLSF vector in Q15.774 // A plausible ascending NLSF vector in Q15.
775 let mut nlsf = [0i16; MAX_LPC_ORDER];775 let mut nlsf = [0i16; MAX_LPC_ORDER];
776- for i in 0..order {776+ for (i, slot) in nlsf.iter_mut().enumerate().take(order) {
777- nlsf[i] = ((i as i32 + 1) * 32768 / (order as i32 + 1)) as i16;777+ *slot = ((i as i32 + 1) * 32768 / (order as i32 + 1)) as i16;
778 }778 }
779 let a_q12 = nlsf2a(&nlsf, order);779 let a_q12 = nlsf2a(&nlsf, order);
780 let lpc: Vec<f64> = a_q12.iter().map(|&c| c as f64 / 4096.0).collect();780 let lpc: Vec<f64> = a_q12.iter().map(|&c| c as f64 / 4096.0).collect();
@@ -862,10 +862,10 @@ mod tests {
862 let resp = |a: &[f64], order: usize, w: f64| -> f64 {862 let resp = |a: &[f64], order: usize, w: f64| -> f64 {
863 let mut re = 1.0;863 let mut re = 1.0;
864 let mut im = 0.0;864 let mut im = 0.0;
865- for k in 0..order {865+ for (k, &a_k) in a.iter().enumerate().take(order) {
866 let theta = -(k as f64 + 1.0) * w;866 let theta = -(k as f64 + 1.0) * w;
867- re += a[k] / 4096.0 * theta.cos();867+ re += a_k / 4096.0 * theta.cos();
868- im += a[k] / 4096.0 * theta.sin();868+ im += a_k / 4096.0 * theta.sin();
869 }869 }
870 1.0 / (re * re + im * im).sqrt().max(1e-6)870 1.0 / (re * re + im * im).sqrt().max(1e-6)
871 };871 };
crates/ec-vorbis/src/encode.rsmodified+26 -16
@@ -299,12 +299,14 @@ impl VorbisEncoder {
299 let headers = write_headers(299 let headers = write_headers(
300 &config,300 &config,
301 channels,301 channels,
302- &long,302+ HeaderSetup {
303- &short,303+ long: &long,
304- &floor_book,304+ short: &short,
305- &class_book,305+ floor_book: &floor_book,
306- &residue_books,306+ class_book: &class_book,
307- &coupling,307+ residue_books: &residue_books,
308+ coupling: &coupling,
309+ },
308 );310 );
309 let params = CodecParameters {311 let params = CodecParameters {
310 codec: CodecId::Vorbis,312 codec: CodecId::Vorbis,
@@ -1117,17 +1119,25 @@ fn absolute_threshold(hz: f64) -> f64 {
1117 (spl - 96.0).clamp(-120.0, -80.0)1119 (spl - 96.0).clamp(-120.0, -80.0)
1118 }1120 }
1119 1121
1122+struct HeaderSetup<'a> {
1123+ long: &'a BlockConfig,
1124+ short: &'a BlockConfig,
1125+ floor_book: &'a CodebookSpec,
1126+ class_book: &'a CodebookSpec,
1127+ residue_books: &'a [CodebookSpec],
1128+ coupling: &'a [(usize, usize)],
1129+}
1130+
1120 /// The three header packets, in order.1131 /// The three header packets, in order.
1121-fn write_headers(1132+fn write_headers(config: &EncoderConfig, channels: usize, setup: HeaderSetup<'_>) -> Vec<Vec<u8>> {
1122- config: &EncoderConfig,1133+ let HeaderSetup {
1123- channels: usize,1134+ long,
1124- long: &BlockConfig,1135+ short,
1125- short: &BlockConfig,1136+ floor_book,
1126- floor_book: &CodebookSpec,1137+ class_book,
1127- class_book: &CodebookSpec,1138+ residue_books,
1128- residue_books: &[CodebookSpec],1139+ coupling,
1129- coupling: &[(usize, usize)],1140+ } = setup;
1130-) -> Vec<Vec<u8>> {
1131 let mut ident = vec![1u8];1141 let mut ident = vec![1u8];
1132 ident.extend_from_slice(b"vorbis");1142 ident.extend_from_slice(b"vorbis");
1133 ident.extend_from_slice(&0u32.to_le_bytes());1143 ident.extend_from_slice(&0u32.to_le_bytes());
shims/oxideav-ac3/src/lib.rsmodified+2 -5
@@ -195,11 +195,8 @@ mod tests {
195 enc.push_pcm_f32(&pcm).unwrap();195 enc.push_pcm_f32(&pcm).unwrap();
196 enc.finish();196 enc.finish();
197 let mut bitstream = Vec::new();197 let mut bitstream = Vec::new();
198- loop {198+ while let Ok(packet) = enc.next_packet() {
199- match enc.next_packet() {199+ bitstream.extend_from_slice(&packet);
200- Ok(packet) => bitstream.extend_from_slice(&packet),
201- Err(_) => break,
202- }
203 }200 }
204 201
205 let mut registry = CodecRegistry::new();202 let mut registry = CodecRegistry::new();