forge
Explore
Log in

Don't you dare go Hollow

U11: ec-amr delete dead items and dead fields flagged by rustc, replace blanket allows with narrow ones, WB frame sizes read from container (one table)

Browse files at this commit

cdccbc2f662cc4e4dda0e2d99d7faf0ca5577064Ahmet Kaan GümüşParent: 52a5142
crates/ec-amr/src/nb/basic.rsmodified+2 -183
@@ -2,7 +2,6 @@
22 //! opencore-amr C-equivalent basic_op. Word16 = i16, Word32 = i32.
33 //! Plain functions have no overflow flag; `*_o` variants additionally set `*ovf = true`
44 //! when the result saturated. `round_` is C `round`/`pv_round`.
5-#![allow(dead_code)]
65
76 pub const MAX_16: i16 = 0x7fff;
87 pub const MIN_16: i16 = -0x8000;
@@ -13,38 +12,10 @@ use super::tables::{INV_SQRT_TBL, LOG2_TBL, POW2_TBL, SQRT_L_TBL};
1312
1413 // ---------------------------------------------------------------- 16-bit
1514
16-/// C add (add_16). Saturating.
17-#[inline]
18-pub fn add_o(a: i16, b: i16, ovf: &mut bool) -> i16 {
19- let s = a as i32 + b as i32;
20- if s > 0x7fff {
21- *ovf = true;
22- MAX_16
23- } else if s < -32768 {
24- *ovf = true;
25- MIN_16
26- } else {
27- s as i16
28- }
29-}
3015 #[inline]
3116 pub fn add(a: i16, b: i16) -> i16 {
3217 (a as i32 + b as i32).clamp(-32768, 32767) as i16
3318 }
34-/// C sub. Saturating.
35-#[inline]
36-pub fn sub_o(a: i16, b: i16, ovf: &mut bool) -> i16 {
37- let s = a as i32 - b as i32;
38- if s > 0x7fff {
39- *ovf = true;
40- MAX_16
41- } else if s < -32768 {
42- *ovf = true;
43- MIN_16
44- } else {
45- s as i16
46- }
47-}
4819 #[inline]
4920 pub fn sub(a: i16, b: i16) -> i16 {
5021 (a as i32 - b as i32).clamp(-32768, 32767) as i16
@@ -77,24 +48,6 @@ pub fn mult(a: i16, b: i16) -> i16 {
7748 p as i16
7849 }
7950 }
80-/// (a*b + 0x4000)>>15 saturated.
81-#[inline]
82-pub fn mult_r_o(a: i16, b: i16, ovf: &mut bool) -> i16 {
83- let p = (a as i32 * b as i32 + 0x4000) >> 15;
84- if p > 0x7fff {
85- *ovf = true;
86- MAX_16
87- } else if p < -32768 {
88- *ovf = true;
89- MIN_16
90- } else {
91- p as i16
92- }
93-}
94-#[inline]
95-pub fn mult_r(a: i16, b: i16) -> i16 {
96- mult_r_o(a, b, &mut false)
97-}
9851
9952 /// C shl (left shift with saturation; negative count shifts right, count <= -15 gives 0).
10053 #[inline]
@@ -159,18 +112,6 @@ pub fn shr_r(var1: i16, var2: i16) -> i16 {
159112 out
160113 }
161114 }
162-#[inline]
163-pub fn shr_r_o(var1: i16, var2: i16, ovf: &mut bool) -> i16 {
164- if var2 > 15 {
165- 0
166- } else {
167- let mut out = shr_o(var1, var2, ovf);
168- if var2 > 0 && (var1 as i32 & (1 << (var2 - 1))) != 0 {
169- out = out.wrapping_add(1);
170- }
171- out
172- }
173-}
174115
175116 // ---------------------------------------------------------------- 32-bit
176117
@@ -189,16 +130,6 @@ pub fn l_add(a: i32, b: i32) -> i32 {
189130 a.saturating_add(b)
190131 }
191132 #[inline]
192-pub fn l_sub_o(a: i32, b: i32, ovf: &mut bool) -> i32 {
193- match a.checked_sub(b) {
194- Some(v) => v,
195- None => {
196- *ovf = true;
197- if a < 0 { MIN_32 } else { MAX_32 }
198- }
199- }
200-}
201-#[inline]
202133 pub fn l_sub(a: i32, b: i32) -> i32 {
203134 a.saturating_sub(b)
204135 }
@@ -212,11 +143,6 @@ pub fn l_mult(a: i16, b: i16) -> i32 {
212143 MAX_32
213144 }
214145 }
215-/// Plain 16x16 product, no doubling or saturation.
216-#[inline]
217-pub fn l_mult0(a: i16, b: i16) -> i32 {
218- (a as i32).wrapping_mul(b as i32)
219-}
220146 /// C L_mac: opencore semantics (0x4000_0000 product gives MAX_32).
221147 #[inline]
222148 pub fn l_mac_o(acc: i32, a: i16, b: i16, ovf: &mut bool) -> i32 {
@@ -232,39 +158,10 @@ pub fn l_mac_o(acc: i32, a: i16, b: i16, ovf: &mut bool) -> i32 {
232158 pub fn l_mac(acc: i32, a: i16, b: i16) -> i32 {
233159 l_mac_o(acc, a, b, &mut false)
234160 }
235-/// C L_msu = L_sub(acc, L_mult(a,b)).
236-#[inline]
237-pub fn l_msu_o(acc: i32, a: i16, b: i16, ovf: &mut bool) -> i32 {
238- l_sub_o(acc, l_mult(a, b), ovf)
239-}
240161 #[inline]
241162 pub fn l_msu(acc: i32, a: i16, b: i16) -> i32 {
242163 l_sub(acc, l_mult(a, b))
243164 }
244-#[inline]
245-pub fn l_negate(a: i32) -> i32 {
246- if a == MIN_32 { MAX_32 } else { -a }
247-}
248-#[inline]
249-pub fn l_abs(a: i32) -> i32 {
250- if a == MIN_32 { MAX_32 } else { a.abs() }
251-}
252-#[inline]
253-pub fn l_deposit_h(a: i16) -> i32 {
254- (a as i32) << 16
255-}
256-#[inline]
257-pub fn l_deposit_l(a: i16) -> i32 {
258- a as i32
259-}
260-#[inline]
261-pub fn extract_h(a: i32) -> i16 {
262- (a >> 16) as i16
263-}
264-#[inline]
265-pub fn extract_l(a: i32) -> i16 {
266- a as i16
267-}
268165 /// C L_shl: left shift with saturation (negative count: arithmetic right, count <= -31 gives 0).
269166 #[inline]
270167 pub fn l_shl_o(x: i32, n: i16, ovf: &mut bool) -> i32 {
@@ -324,16 +221,6 @@ pub fn l_shr_r(x: i32, n: i16) -> i32 {
324221 pub fn round_(x: i32) -> i16 {
325222 (l_add(x, 0x8000) >> 16) as i16
326223 }
327-/// L_mac then round.
328-#[inline]
329-pub fn mac_r(acc: i32, a: i16, b: i16) -> i16 {
330- round_(l_mac(acc, a, b))
331-}
332-/// L_msu then round.
333-#[inline]
334-pub fn msu_r(acc: i32, a: i16, b: i16) -> i16 {
335- round_(l_msu(acc, a, b))
336-}
337224
338225 /// Normalisation shift count for 16-bit (0 for 0 input).
339226 #[inline]
@@ -395,37 +282,6 @@ pub fn div_s(var1: i16, var2: i16) -> i16 {
395282
396283 // ---------------------------------------------------------------- 32-bit via hi/lo
397284
398-/// C L_Extract: split into (hi, lo) with lo in 0..0x7fff.
399-#[inline]
400-pub fn l_extract(x: i32, hi: &mut i16, lo: &mut i16) {
401- let h = (x >> 16) as i16;
402- *hi = h;
403- *lo = ((x >> 1) - ((h as i32) << 15)) as i16;
404-}
405-/// C L_Comp: inverse of l_extract.
406-#[inline]
407-pub fn l_comp(hi: i16, lo: i16) -> i32 {
408- l_mac(l_deposit_h(hi), lo, 1)
409-}
410-/// C Mpy_32: (hi1/lo1) * (hi2/lo2), result in Q31 (saturating as in C).
411-#[inline]
412-pub fn mpy_32(h1: i16, l1: i16, h2: i16, l2: i16) -> i32 {
413- let mut p = h1 as i32 * h2 as i32;
414- p = if p != 0x4000_0000 { p << 1 } else { MAX_32 };
415- let p32 = (h1 as i32 * l2 as i32) >> 15;
416- let s = p.wrapping_add(p32 << 1);
417- let mut sum = s;
418- if (p ^ p32) > 0 && ((s ^ p) >> 31) != 0 {
419- sum = if (p >> 31) != 0 { MIN_32 } else { MAX_32 };
420- }
421- let p = sum;
422- let p32 = (l1 as i32 * h2 as i32) >> 15;
423- let s = p.wrapping_add(p32 << 1);
424- if (p ^ p32) > 0 && ((s ^ p) >> 31) != 0 {
425- return if (p >> 31) != 0 { MIN_32 } else { MAX_32 };
426- }
427- s
428-}
429285 /// C Mpy_32_16: (hi/lo) * var2.
430286 #[inline]
431287 pub fn mpy_32_16(hi: i16, lo: i16, v: i16) -> i32 {
@@ -438,35 +294,6 @@ pub fn mpy_32_16(hi: i16, lo: i16, v: i16) -> i32 {
438294 }
439295 s
440296 }
441-/// C Mac_32: acc + (h1/l1)*(h2/l2).
442-#[inline]
443-pub fn mac_32(acc: i32, h1: i16, l1: i16, h2: i16, l2: i16) -> i32 {
444- let mut a = l_mac(acc, h1, h2);
445- a = l_mac(a, mult(h1, l2), 1);
446- l_mac(a, mult(l1, h2), 1)
447-}
448-/// C Mac_32_16: acc + (hi/lo)*var2.
449-#[inline]
450-pub fn mac_32_16(acc: i32, hi: i16, lo: i16, v: i16) -> i32 {
451- let a = l_mac(acc, hi, v);
452- l_mac(a, mult(lo, v), 1)
453-}
454-/// C Div_32: L_num / (denom_hi/denom_lo), result Q31.
455-#[inline]
456-pub fn div_32(l_num: i32, d_hi: i16, d_lo: i16) -> i32 {
457- let approx = div_s(0x3fff, d_hi);
458- let mut r = mpy_32_16(d_hi, d_lo, approx);
459- r = 0x7fff_ffff - r;
460- let hi = (r >> 16) as i16;
461- let lo = ((r >> 1) - ((hi as i32) << 15)) as i16;
462- r = mpy_32_16(hi, lo, approx);
463- let hi = (r >> 16) as i16;
464- let lo = ((r >> 1) - ((hi as i32) << 15)) as i16;
465- let n_hi = (l_num >> 16) as i16;
466- let n_lo = ((l_num >> 1) - ((n_hi as i32) << 15)) as i16;
467- r = mpy_32(n_hi, n_lo, hi, lo);
468- l_shl(r, 2)
469-}
470297
471298 // ---------------------------------------------------------------- math functions
472299
@@ -492,7 +319,7 @@ pub fn log2_norm(x: i32, exp: i16, exponent: &mut i16, fraction: &mut i16) {
492319 *exponent = 30i16.wrapping_sub(exp);
493320 let x = x >> 10;
494321 let i = ((x >> 15) as i16).wrapping_sub(32) as usize;
495- let a = (x & 0x7fff) as i32;
322+ let a = x & 0x7fff;
496323 let mut y = (LOG2_TBL[i] as i32) << 16;
497324 let tmp = LOG2_TBL[i].wrapping_sub(LOG2_TBL[i + 1]) as i32;
498325 y = y.wrapping_sub((tmp * a) << 1);
@@ -540,7 +367,7 @@ pub fn sqrt_l_exp(l_x: i32, exp: &mut i16) -> i32 {
540367 *exp = e;
541368 let x = x >> 10;
542369 let mut i = ((x >> 15) & 63) as usize;
543- let a = (x as i16 & 0x7fff) as i16;
370+ let a = x as i16 & 0x7fff;
544371 if i > 15 {
545372 i -= 16;
546373 }
@@ -584,7 +411,6 @@ mod tests {
584411 assert_eq!(l_mult(-32768, -32768), i32::MAX);
585412 assert_eq!(l_mac(5, -32768, -32768), i32::MAX);
586413 assert_eq!(mult(-32768, -32768), 32767);
587- assert_eq!(mult_r(-32768, -32768), 32767);
588414 assert_eq!(shl(0x4000, 1), 32767);
589415 assert_eq!(shl(-0x4001, 1), -32768);
590416 assert_eq!(shl(3, 2), 12);
@@ -596,9 +422,6 @@ mod tests {
596422 assert_eq!(l_shl(-0x4000_0001, 1), i32::MIN);
597423 assert_eq!(l_shr_r(5, 1), 3);
598424 assert_eq!(l_shr(1, -31), i32::MAX);
599- let mut o = false;
600- add_o(32767, 1, &mut o);
601- assert!(o);
602425 }
603426
604427 #[test]
@@ -619,9 +442,5 @@ mod tests {
619442 log2(1 << 20, &mut e, &mut f);
620443 assert_eq!((e, f), (20, 0));
621444 assert_eq!(gmed_n(&[5, 1, 9, 3, 7], 5), 5);
622- let (mut h, mut l) = (0, 0);
623- l_extract(0x1234_5678, &mut h, &mut l);
624- assert_eq!(l_comp(h, l), 0x1234_5678);
625445 }
626446 }
627-
crates/ec-amr/src/nb/bitstream.rsmodified+1 -2
@@ -1,6 +1,5 @@
11 //! AMR-NB bitstream: RFC 4867 / 3GPP TS 26.101 IF1 (octet-aligned, "MIME/IETF storage") frame
22 //! parsing into decoder parameters (wmf_to_ets + bits2prm of opencore-amr).
3-#![allow(dead_code)]
43
54 use super::tables::*;
65
@@ -178,7 +177,7 @@ mod tests {
178177 assert_eq!(frame_bytes(10), None);
179178 // (bits + 7) / 8 for each mode
180179 for ft in 0..8usize {
181- assert_eq!((NUMOFBITS[ft] as usize + 7) / 8, WMFDECBYTESPERFRAME[ft] as usize);
180+ assert_eq!((NUMOFBITS[ft] as usize).div_ceil(8), WMFDECBYTESPERFRAME[ft] as usize);
182181 }
183182 }
184183
crates/ec-amr/src/nb/decoder.rsmodified+5 -6
@@ -1,6 +1,5 @@
11 //! AMR-NB decoder: port of opencore-amr `dec_amr.cpp` (Decoder_amr) and `sp_dec.cpp`
22 //! (GSMFrameDecode), plus the `AMRDecode` frame-type handling of the libopencore-amrnb wrapper.
3-#![allow(clippy::all)]
43
54 use super::basic::*;
65 use super::bitstream::{parse_frame, BitstreamError, RxFrameType};
@@ -49,9 +48,9 @@ fn agc2(sig_in: &[i16], sig_out: &mut [i16]) {
4948 let mut exp = norm_l(s) - 1;
5049 let gain_out = round_(l_shl(s, exp));
5150 s = energy_new(&sig_in[..l]);
52- let g0: i16;
53- if s == 0 {
54- g0 = 0;
51+
52+ let g0: i16 = if s == 0 {
53+ 0
5554 } else {
5655 let i = norm_l(s);
5756 let gain_in = round_(l_shl(s, i));
@@ -74,8 +73,8 @@ fn agc2(sig_in: &[i16], sig_out: &mut [i16]) {
7473 } else {
7574 s << 9
7675 };
77- g0 = round_(lt);
78- }
76+ round_(lt)
77+ };
7978 for i in (0..l).rev() {
8079 let lt = l_mult(sig_out[i], g0);
8180 sig_out[i] = if lt > 0x0FFF_FFFF {
crates/ec-amr/src/nb/dtx.rsmodified+1 -2
@@ -1,6 +1,5 @@
11 //! Decoder-side DTX / error-concealment helpers: dtx_dec, lsp_avg, bgnscd, c_g_aver,
22 //! ec_gains, ex_ctrl, pseudonoise / build_CN_code.
3-#![allow(clippy::too_many_arguments, clippy::needless_range_loop)]
43
54 use super::basic::*;
65 use super::bitstream::RxFrameType;
@@ -659,7 +658,7 @@ pub fn dtx_dec(
659658 lsf_state.past_r_q = [0; M];
660659
661660 let log_en_index = parm[4];
662- if log_en_index > 63 || log_en_index < -64 {
661+ if !(-64..=63).contains(&log_en_index) {
663662 st.log_en = if log_en_index > 0 { i16::MAX } else { i16::MIN };
664663 } else {
665664 st.log_en = log_en_index << (11 - 2);
crates/ec-amr/src/nb/excitation.rsmodified+10 -11
@@ -1,6 +1,5 @@
11 //! AMR-NB excitation decoding: pitch lag, algebraic codebooks, gains, phase dispersion.
22 //! Bit-exact port of the 3GPP TS 26.073 reference (opencore-amr flavour).
3-#![allow(clippy::all, dead_code, unused_imports, unused_variables, unused_assignments)]
43
54 use super::basic::*;
65 use super::tables::*;
@@ -192,10 +191,10 @@ fn pulse_val(sign: i32) -> i16 {
192191 /// C `dec_10i40_35bits` (MR122 codebook). `index` has 10 entries; `cod` 40 samples.
193192 #[inline]
194193 pub fn dec_10i40_35bits(index: &[i16], cod: &mut [i16]) {
195- for c in cod[..L_CODE as usize].iter_mut() {
194+ for c in cod[..L_CODE].iter_mut() {
196195 *c = 0;
197196 }
198- for j in 0..NB_TRACK as usize {
197+ for j in 0..NB_TRACK {
199198 let tmp = index[j] as i32;
200199 let i = DGRAY[(tmp & 7) as usize] as i32;
201200 let pos1 = (i * 5) as usize + j;
@@ -327,7 +326,7 @@ fn decompress10(msbs: i32, lsbs: i32, index1: usize, index2: usize, index3: usiz
327326 #[inline]
328327 pub fn dec_8i40_31bits(index: &[i16], cod: &mut [i16]) {
329328 const NT: usize = 4;
330- for c in cod[..L_CODE as usize].iter_mut() {
329+ for c in cod[..L_CODE].iter_mut() {
331330 *c = 0;
332331 }
333332 let mut signs = [0i32; NT];
@@ -433,7 +432,7 @@ pub fn gc_pred(
433432 let mut exp = 0i16;
434433 let mut frac = 0i16;
435434 log2(ener_code, &mut exp, &mut frac);
436- let l1 = ((exp as i32 - 30) as i32).wrapping_shl(16);
435+ let l1 = (exp as i32 - 30).wrapping_shl(16);
437436 ener_code = l1.wrapping_add((frac as i32) << 1);
438437 let mut ener = MEAN_ENER_MR122;
439438 for i in 0..NPRED {
@@ -487,7 +486,7 @@ pub fn gc_pred(
487486 l_tmp <<= 10;
488487 }
489488 for i in 0..4 {
490- let l2 = ((PRED[i] * st.past_qua_en[i] as i32)) << 1;
489+ let l2 = (PRED[i] * st.past_qua_en[i] as i32) << 1;
491490 l_tmp = l_add(l_tmp, l2);
492491 }
493492 let gcode0 = (l_tmp >> 16) as i16;
@@ -616,17 +615,17 @@ pub fn d_gain_code(pred_state: &mut GcPredState, mode: Mode, index: i16, code: &
616615 );
617616 let index = (index & 31) as usize;
618617 let p = &QUA_GAIN_CODE[index + (index << 1)..];
619- let gain_code: i16;
620- if mode == Mode::Mr122 {
618+
619+ let gain_code: i16 = if mode == Mode::Mr122 {
621620 let mut gcode0 = pow2(exp, frac) as i16;
622621 gcode0 = shl(gcode0, 4);
623- gain_code = shl(mult(gcode0, p[0]), 1);
622+ shl(mult(gcode0, p[0]), 1)
624623 } else {
625624 let gcode0 = pow2(14, frac) as i16;
626625 let l = l_mult(p[0], gcode0);
627626 let l = l_shr(l, sub(9, exp));
628- gain_code = (l >> 16) as i16;
629- }
627+ (l >> 16) as i16
628+ };
630629 let qua_ener_mr122 = p[1];
631630 let qua_ener = p[2];
632631 gc_pred_update(pred_state, qua_ener_mr122, qua_ener);
crates/ec-amr/src/nb/lpc.rsmodified+0 -25
@@ -1,6 +1,5 @@
11 //! LSF/LSP decoding, conversion and interpolation (d_plsf*, int_lsf, lsp_lsf,
22 //! lsp_az, int_lpc, reorder). Bit-exact port of the 3GPP reference.
3-#![allow(dead_code)]
43
54 use super::basic::{add, mult, negate, shl, sub};
65 use super::tables::{
@@ -305,15 +304,6 @@ pub fn int_lpc_1and3(lsp_old: &[i16], lsp_mid: &[i16], lsp_new: &[i16], az: &mut
305304 lsp_az(lsp_new, &mut az[3 * MP1..]);
306305 }
307306
308-/// C `Int_lpc_1and3_2`: writes Az[0..11] (subframe 1) and Az[22..33] (subframe 3).
309-pub fn int_lpc_1and3_2(lsp_old: &[i16], lsp_mid: &[i16], lsp_new: &[i16], az: &mut [i16]) {
310- let mut lsp = [0i16; M];
311- half_sum(lsp_old, lsp_mid, &mut lsp);
312- lsp_az(&lsp, &mut az[0..]);
313- half_sum(lsp_mid, lsp_new, &mut lsp);
314- lsp_az(&lsp, &mut az[2 * MP1..]);
315-}
316-
317307 /// C `Int_lpc_1to3`: 4 subframes from old/new LSPs; writes Az[0..44].
318308 pub fn int_lpc_1to3(lsp_old: &[i16], lsp_new: &[i16], az: &mut [i16]) {
319309 let mut lsp = [0i16; M];
@@ -329,18 +319,3 @@ pub fn int_lpc_1to3(lsp_old: &[i16], lsp_new: &[i16], az: &mut [i16]) {
329319 lsp_az(&lsp, &mut az[2 * MP1..]);
330320 lsp_az(lsp_new, &mut az[3 * MP1..]);
331321 }
332-
333-/// C `Int_lpc_1to3_2`: like `int_lpc_1to3` but only Az[0..33] (first 3 subframes).
334-pub fn int_lpc_1to3_2(lsp_old: &[i16], lsp_new: &[i16], az: &mut [i16]) {
335- let mut lsp = [0i16; M];
336- for i in 0..M {
337- lsp[i] = (lsp_old[i].wrapping_sub(lsp_old[i] >> 2)).wrapping_add(lsp_new[i] >> 2);
338- }
339- lsp_az(&lsp, &mut az[0..]);
340- half_sum(lsp_new, lsp_old, &mut lsp);
341- lsp_az(&lsp, &mut az[MP1..]);
342- for i in 0..M {
343- lsp[i] = (lsp_new[i].wrapping_sub(lsp_new[i] >> 2)).wrapping_add(lsp_old[i] >> 2);
344- }
345- lsp_az(&lsp, &mut az[2 * MP1..]);
346-}
crates/ec-amr/src/nb/mod.rsmodified+7 -7
@@ -1,11 +1,11 @@
11 //! AMR-NB decoder (fixed-point, bit-exact port of the 3GPP TS 26.073 reference as
22 //! carried by the Apache-2.0 opencore-amr sources).
3-#![allow(clippy::all)]
4-pub mod basic;
3+#![allow(clippy::needless_range_loop, clippy::too_many_arguments, clippy::manual_memcpy, clippy::manual_clamp)]
54 pub mod bitstream;
65 pub mod decoder;
7-pub mod dtx;
8-pub mod excitation;
9-pub mod lpc;
10-pub mod post;
11-pub mod tables;
6+pub(crate) mod basic;
7+pub(crate) mod dtx;
8+pub(crate) mod excitation;
9+pub(crate) mod lpc;
10+pub(crate) mod post;
11+pub(crate) mod tables;
crates/ec-amr/src/nb/post.rsmodified+5 -19
@@ -1,7 +1,5 @@
11 //! AMR-NB post-processing chain: syn_filt, residu, weight_ai, a_refl, preemphasis,
22 //! agc, post_filter, post_process (bit-exact port of opencore-amr).
3-#![allow(clippy::all)]
4-#![allow(dead_code)]
53
64 use super::basic::*;
75 use super::tables::Mode;
@@ -128,9 +126,6 @@ impl PreemphasisState {
128126 pub fn new() -> Self {
129127 Self { mem_pre: 0 }
130128 }
131- pub fn reset(&mut self) {
132- self.mem_pre = 0;
133- }
134129 }
135130
136131 /// C preemphasis: in-place signal[0..l] -= g*signal[i-1] (mem for i=0).
@@ -155,9 +150,6 @@ impl AgcState {
155150 pub fn new() -> Self {
156151 Self { past_gain: 4096 }
157152 }
158- pub fn reset(&mut self) {
159- self.past_gain = 4096;
160- }
161153 }
162154
163155 fn energy_new(inp: &[i16], l: usize) -> i32 {
@@ -189,9 +181,9 @@ pub fn agc(st: &mut AgcState, sig_in: &[i16], sig_out: &mut [i16], agc_fac: i16,
189181 let l_temp = l_shl(s, exp);
190182 let gain_out = round_(l_temp);
191183 s = energy_new(&sig_in[..l], l);
192- let g0: i16;
193- if s == 0 {
194- g0 = 0;
184+
185+ let g0: i16 = if s == 0 {
186+ 0
195187 } else {
196188 let i = norm_l(s);
197189 let l_temp = s.wrapping_shl(i as u32);
@@ -204,8 +196,8 @@ pub fn agc(st: &mut AgcState, sig_in: &[i16], sig_out: &mut [i16], agc_fac: i16,
204196 let l_temp = s.wrapping_shl(9);
205197 let i = (l_temp.wrapping_add(0x8000) >> 16) as i16;
206198 let temp = 32767 - agc_fac;
207- g0 = (((i as i32) * (temp as i32)) >> 15) as i16;
208- }
199+ (((i as i32) * (temp as i32)) >> 15) as i16
200+ };
209201 let mut gain = st.past_gain;
210202 for i in 0..l {
211203 gain = (((gain as i32) * (agc_fac as i32)) >> 15) as i16;
@@ -236,9 +228,6 @@ impl PostFilterState {
236228 synth_buf: [0; M + L_FRAME],
237229 }
238230 }
239- pub fn reset(&mut self) {
240- *self = Self::new();
241- }
242231 }
243232
244233 /// C Post_Filter: syn[0..160] is the synthesis speech, replaced by the postfiltered
@@ -337,9 +326,6 @@ impl PostProcessState {
337326 pub fn new() -> Self {
338327 Self::default()
339328 }
340- pub fn reset(&mut self) {
341- *self = Self::default();
342- }
343329 }
344330
345331 /// C Post_Process: in-place high-pass filter and upscale of signal[0..lg].
crates/ec-amr/src/nb/tables.rsmodified+0 -107
@@ -1,98 +1,24 @@
11 //! Constant tables for the AMR-NB decoder. GENERATED by /tmp/amrsrc/gen/gen.py from the C sources; do not edit.
2-#![allow(dead_code)]
32
43 // ---- constants (cnst.h / mode.h / bitno_tab.h / table sizes) ----
5-pub const L_TOTAL: usize = 320;
6-pub const L_WINDOW: usize = 240;
74 pub const L_FRAME: usize = 160;
85 pub const L_FRAME_BY2: usize = 80;
96 pub const L_SUBFR: usize = 40;
107 pub const L_CODE: usize = 40;
118 pub const NB_TRACK: usize = 5;
12-pub const STEP: usize = 5;
13-pub const NB_TRACK_MR102: usize = 4;
14-pub const STEP_MR102: usize = 4;
159 pub const M: usize = 10;
1610 pub const MP1: usize = 11;
1711 pub const LSF_GAP: i16 = 205;
18-pub const LSP_PRED_FAC_MR122: i16 = 21299;
1912 pub const AZ_SIZE: usize = 44;
2013 pub const PIT_MIN_MR122: i16 = 18;
2114 pub const PIT_MIN: i16 = 20;
2215 pub const PIT_MAX: i16 = 143;
2316 pub const L_INTERPOL: usize = 11;
24-pub const L_INTER_SRCH: usize = 4;
25-pub const MU: i16 = 26214;
26-pub const AGC_FAC: i16 = 29491;
27-pub const L_NEXT: usize = 40;
2817 pub const SHARPMAX: i16 = 13017;
2918 pub const SHARPMIN: i16 = 0;
3019 pub const MAX_PRM_SIZE: usize = 57;
3120 pub const MAX_SERIAL_SIZE: usize = 244;
32-pub const GP_CLIP: i16 = 15565;
33-pub const N_FRAME: usize = 7;
34-pub const EHF_MASK: i16 = 8;
35-pub const MR795_1_SIZE: usize = 512;
36-pub const PAST_RQ_INIT_SIZE: usize = 8;
37-pub const DICO1_SIZE: usize = 256;
38-pub const DICO2_SIZE: usize = 512;
39-pub const DICO3_SIZE: usize = 512;
40-pub const MR515_3_SIZE: usize = 128;
41-pub const VQ_SIZE_HIGHRATES: usize = 128;
42-pub const VQ_SIZE_LOWRATES: usize = 64;
4321 pub const MR475_VQ_SIZE: usize = 256;
44-pub const NB_QUA_PITCH: usize = 16;
45-pub const NB_QUA_CODE: usize = 32;
46-pub const BIT_0: i16 = 0;
47-pub const BIT_1: i16 = 1;
48-pub const DICO1_5_SIZE: usize = 128;
49-pub const DICO2_5_SIZE: usize = 256;
50-pub const DICO3_5_SIZE: usize = 256;
51-pub const DICO4_5_SIZE: usize = 256;
52-pub const DICO5_5_SIZE: usize = 64;
53-pub const DTX_MAX_EMPTY_THRESH: usize = 50;
54-pub const DTX_HIST_SIZE: usize = 8;
55-pub const DTX_ELAPSED_FRAMES_THRESH: usize = 30;
56-pub const DTX_HANG_CONST: usize = 7;
57-pub const PRMNO_MR475: usize = 17;
58-pub const PRMNO_MR515: usize = 19;
59-pub const PRMNO_MR59: usize = 19;
60-pub const PRMNO_MR67: usize = 19;
61-pub const PRMNO_MR74: usize = 19;
62-pub const PRMNO_MR795: usize = 23;
63-pub const PRMNO_MR102: usize = 39;
64-pub const PRMNO_MR122: usize = 57;
65-pub const PRMNO_MRDTX: usize = 5;
66-pub const PRMNOFSF_MR475: usize = 7;
67-pub const PRMNOFSF_MR515: usize = 7;
68-pub const PRMNOFSF_MR59: usize = 7;
69-pub const PRMNOFSF_MR67: usize = 7;
70-pub const PRMNOFSF_MR74: usize = 7;
71-pub const PRMNOFSF_MR795: usize = 8;
72-pub const PRMNOFSF_MR102: usize = 12;
73-pub const PRMNOFSF_MR122: usize = 18;
74-pub const NPRED: usize = 4;
75-pub const UP_SAMP_MAX: usize = 6;
76-pub const FIR_SIZE: usize = 61;
77-pub const NUM_MODES: usize = 16;
78-pub const NUMBIT_MR475: usize = 95;
79-pub const NUMBIT_MR515: usize = 103;
80-pub const NUMBIT_MR59: usize = 118;
81-pub const NUMBIT_MR67: usize = 134;
82-pub const NUMBIT_MR74: usize = 148;
83-pub const NUMBIT_MR795: usize = 159;
84-pub const NUMBIT_MR102: usize = 204;
85-pub const NUMBIT_MR122: usize = 244;
86-pub const NUMBIT_AMR_SID: usize = 39;
87-pub const NUMBIT_GSMEFR_SID: usize = 43;
88-pub const NUMBIT_TDMAEFR_SID: usize = 38;
89-pub const NUMBIT_PDCEFR_SID: usize = 37;
90-pub const NUMBIT_UNUSED1: usize = 0;
91-pub const NUMBIT_UNUSED2: usize = 0;
92-pub const NUMBIT_UNUSED3: usize = 0;
93-pub const NUMBIT_NO_DATA: usize = 0;
94-pub const LTP_GAIN_HISTORY_LEN: usize = 9;
95-pub const GRID_POINTS: usize = 60;
9622
9723 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
9824 pub enum Mode { Mr475, Mr515, Mr59, Mr67, Mr74, Mr795, Mr102, Mr122, MrDtx }
@@ -100,9 +26,6 @@ pub enum Mode { Mr475, Mr515, Mr59, Mr67, Mr74, Mr795, Mr102, Mr122, MrDtx }
10026 pub static PRMNO: [i16; 9] = [
10127 17, 19, 19, 19, 19, 23, 39, 57, 5,
10228 ];
103-pub static PRMNOFSF: [i16; 8] = [
104- 7, 7, 7, 7, 7, 8, 12, 18,
105-];
10629 pub static BITNO_MR475: [i16; 17] = [
10730 8, 8, 7, 8, 7, 2, 8, 4, 7, 2, 4, 7,
10831 2, 8, 4, 7, 2,
@@ -267,10 +190,6 @@ pub static REORDERBITS_MR122: [i16; 244] = [
267190 225, 224, 229, 228, 227, 232, 231, 230, 235, 234, 233, 238,
268191 237, 236, 96, 199,
269192 ];
270-pub static NUMCOMPRESSEDBYTES: [i16; 16] = [
271- 13, 14, 16, 18, 19, 21, 26, 31, 6, 6, 6, 6,
272- 0, 0, 0, 1,
273-];
274193 pub static STARTPOS: [i16; 16] = [ // 2 cols
275194 0, 2, 0, 3, 0, 2, 0, 3, 1, 3, 2, 4,
276195 1, 4, 1, 4,
@@ -290,20 +209,9 @@ pub static QUA_GAIN_CODE: [i16; 99] = [ // 3 cols
290209 12510, 2673, 16096, 16263, 3060, 18429, 21142, 3448, 20763, 27485, 3836, 23097,
291210 27485, 3836, 23097,
292211 ];
293-pub static GRAY: [i16; 8] = [
294- 0, 1, 3, 2, 6, 4, 5, 7,
295-];
296212 pub static DGRAY: [i16; 8] = [
297213 0, 1, 3, 2, 5, 6, 4, 7,
298214 ];
299-pub static GRID: [i16; 61] = [
300- 32760, 32723, 32588, 32364, 32051, 31651, 31164, 30591, 29935, 29196, 28377, 27481,
301- 26509, 25465, 24351, 23170, 21926, 20621, 19260, 17846, 16384, 14876, 13327, 11743,
302- 10125, 8480, 6812, 5126, 3425, 1714, 0, -1714, -3425, -5126, -6812, -8480,
303- -10125, -11743, -13327, -14876, -16384, -17846, -19260, -20621, -21926, -23170, -24351, -25465,
304- -26509, -27481, -28377, -29196, -29935, -30591, -31164, -31651, -32051, -32364, -32588, -32723,
305- -32760,
306-];
307215 pub static INV_SQRT_TBL: [i16; 49] = [
308216 32767, 31790, 30894, 30070, 29309, 28602, 27945, 27330, 26755, 26214, 25705, 25225,
309217 24770, 24339, 23930, 23541, 23170, 22817, 22479, 22155, 21845, 21548, 21263, 20988,
@@ -332,9 +240,6 @@ pub static SLOPE: [i16; 64] = [
332240 -946, -998, -1059, -1132, -1219, -1322, -1450, -1608, -1811, -2081, -2444, -2979,
333241 -3813, -5323, -8812, -26887,
334242 ];
335-pub static LSP_INIT_DATA: [i16; 10] = [
336- 30000, 26000, 21000, 15000, 8000, 0, -8000, -15000, -21000, -26000,
337-];
338243 pub static PH_IMP_LOW_MR795: [i16; 40] = [
339244 26777, 801, 2505, -683, -1382, 582, 604, -1274, 3511, -5894, 4534, -499,
340245 -1940, 3011, -5058, 5614, -1990, -1061, -1459, 4442, -700, -5335, 4609, 452,
@@ -1335,22 +1240,10 @@ pub static SQRT_L_TBL: [i16; 50] = [
13351240 29537, 29819, 30099, 30377, 30652, 30924, 31194, 31462, 31727, 31991, 32252, 32511,
13361241 32767, 32767,
13371242 ];
1338-pub static INTER_6_PRED_LT: [i16; 61] = [
1339- 29443, 28346, 25207, 20449, 14701, 8693, 3143, -1352, -4402, -5865, -5850, -4673,
1340- -2783, -672, 1211, 2536, 3130, 2991, 2259, 1170, 0, -1001, -1652, -1868,
1341- -1666, -1147, -464, 218, 756, 1060, 1099, 904, 550, 135, -245, -514,
1342- -634, -602, -451, -231, 0, 191, 308, 340, 296, 198, 78, -36,
1343- -120, -163, -165, -132, -79, -19, 34, 73, 91, 89, 70, 38,
1344- 0,
1345-];
13461243 pub static WMFDECBYTESPERFRAME: [i16; 16] = [
13471244 12, 13, 15, 17, 19, 20, 26, 31, 5, 6, 5, 5,
13481245 0, 0, 0, 0,
13491246 ];
1350-pub static IF2DECBYTESPERFRAME: [i16; 16] = [
1351- 13, 14, 16, 18, 19, 21, 26, 31, 6, 6, 6, 6,
1352- 0, 0, 0, 1,
1353-];
13541247 pub static TABLE_GAIN_MR475: [i16; 1024] = [ // 4 cols
13551248 812, 128, 542, 140, 2873, 1135, 2266, 3402, 2067, 563, 12677, 647,
13561249 4132, 1798, 5601, 5285, 7689, 374, 3735, 441, 10912, 2638, 11807, 2494,
crates/ec-amr/src/wb/bits.rsmodified+4 -18
@@ -1,19 +1,9 @@
11 //! Bit reading (get_amr_wb_bits.cpp), MIME unsorting (mime_io.cpp) and decoder homing frame test (homing_amr_wb_dec.cpp).
2-#![allow(dead_code)]
32
43 use super::ops::*;
54
6-pub const BIT_0: i16 = -127;
75 pub const BIT_1: i16 = 127;
86
9-pub const MODE_7K: i16 = 0;
10-pub const MODE_9K: i16 = 1;
11-pub const MODE_12K: i16 = 2;
12-pub const MODE_14K: i16 = 3;
13-pub const MODE_16K: i16 = 4;
14-pub const MODE_18K: i16 = 5;
15-pub const MODE_20K: i16 = 6;
16-pub const MODE_23K: i16 = 7;
177 pub const MODE_24K: i16 = 8;
188 pub const MRDTX: i16 = 9;
199 pub const MRSID: i16 = 9;
@@ -66,14 +56,9 @@ pub fn Serial_parm_1bit(prms: &mut Prms) -> i16 {
6656
6757 // ---------------- mime_io.cpp ----------------
6858
69-pub static toc_byte: [u8; 16] = [
70- 0x04, 0x0C, 0x14, 0x1C, 0x24, 0x2C, 0x34, 0x3C, 0x44, 0x4C, 0x54, 0x5C, 0x64, 0x6C, 0x74, 0x7C,
71-];
7259 pub static unpacked_size: [i16; 16] = [
7360 132, 177, 253, 285, 317, 365, 397, 461, 477, 35, 0, 0, 0, 0, 0, 0,
7461 ];
75-pub static packed_size: [i16; 16] = [17, 23, 32, 36, 40, 46, 50, 58, 60, 5, 0, 0, 0, 0, 0, 0];
76-pub static unused_size: [i16; 16] = [4, 7, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0];
7762
7863 pub static sort_660: [i16; 132] = [
7964 0, 5, 6, 7, 61, 84, 107, 130, 62, 85, 8, 4, 37, 38, 39, 40, 58, 81, 104, 127, 60, 83, 106, 129,
@@ -247,7 +232,6 @@ pub static sort_sid: [i16; 35] = [
247232 /// RX_State of mime_io.
248233 #[derive(Clone, Copy, Default)]
249234 pub struct RxState {
250- pub prev_ft: i16,
251235 pub prev_mode: i16,
252236 }
253237
@@ -268,6 +252,7 @@ fn sorting_table(mode: i16) -> Option<&'static [i16]> {
268252 }
269253
270254 /// Port of `mime_unsorting`. `mode` must be 0..=15.
255+#[allow(unused_assignments)]
271256 pub fn mime_unsorting(
272257 unsorted_bits: &[u8],
273258 sorted_bits_into_int16: &mut [i16],
@@ -400,6 +385,7 @@ fn dhf_table(mode: i32) -> &'static [i16] {
400385 }
401386
402387 /// Port of `dhf_test`.
388+#[allow(unused_assignments)]
403389 pub fn dhf_test(input_frame: &[i16], mode: i32, nparms: i16) -> i16 {
404390 let dhf = dhf_table(mode);
405391 let mut param = [0i16; DHF_PARMS_MAX + 1];
@@ -453,8 +439,8 @@ pub fn dhf_test(input_frame: &[i16], mode: i32, nparms: i16) -> i16 {
453439 let mut tmp: i16 = 0x7fff;
454440 tmp >>= shift;
455441 tmp = shl_int16(tmp, shift);
456- tmp = dhf[i] & tmp;
457- tmp = param[i] ^ tmp;
442+ tmp &= dhf[i];
443+ tmp ^= param[i];
458444 j |= tmp;
459445 } else {
460446 j = 1;
crates/ec-amr/src/wb/core.rsmodified+1 -0
@@ -115,6 +115,7 @@ impl DecoderState {
115115
116116 /// `pvDecoder_AmrWb`: decode one frame of parameters (`prms`, one bit per i16 in
117117 /// the decoder's serial order) into 320 samples.
118+#[allow(unused_assignments)]
118119 pub fn decode_frame(
119120 mode: i16,
120121 prms_buf: &[i16],
crates/ec-amr/src/wb/dtx.rsmodified+6 -173
@@ -1,31 +1,22 @@
11 //! AMR-WB decoder DTX / comfort noise (port of dtx_decoder_amr_wb.cpp and dtx.h).
2-#![allow(dead_code)]
32
43 use super::bits::{Prms, Serial_parm, Serial_parm_1bit};
54 use super::ops::*;
65
76 pub const DTX_MAX_EMPTY_THRESH: i16 = 50;
87 pub const DTX_HIST_SIZE: usize = 8;
9-pub const DTX_HIST_SIZE_MIN_ONE: usize = 7;
108 pub const DTX_ELAPSED_FRAMES_THRESH: i16 = 24 + 7 - 1;
119 pub const DTX_HANG_CONST: i16 = 7;
12-pub const INV_MED_THRESH: i16 = 14564;
1310 pub const ISF_GAP: i16 = 128;
1411 pub const ISF_DITH_GAP: i16 = 448;
1512 pub const ISF_FACTOR_LOW: i16 = 256;
1613 pub const ISF_FACTOR_STEP: i16 = 2;
17-pub const GAIN_THR: i16 = 180;
1814 pub const GAIN_FACTOR: i16 = 75;
1915
2016 pub const SPEECH: i16 = 0;
2117 pub const DTX: i16 = 1;
2218 pub const DTX_MUTE: i16 = 2;
2319
24-pub const TX_SPEECH: i16 = 0;
25-pub const TX_SID_FIRST: i16 = 1;
26-pub const TX_SID_UPDATE: i16 = 2;
27-pub const TX_NO_DATA: i16 = 3;
28-
2920 pub const RX_SPEECH_GOOD: i16 = 0;
3021 pub const RX_SPEECH_PROBABLY_DEGRADED: i16 = 1;
3122 pub const RX_SPEECH_LOST: i16 = 2;
@@ -35,26 +26,12 @@ pub const RX_SID_UPDATE: i16 = 5;
3526 pub const RX_SID_BAD: i16 = 6;
3627 pub const RX_NO_DATA: i16 = 7;
3728
38-#[derive(Clone)]
39-pub struct DtxEncState {
40- pub isf_hist: [i16; M * DTX_HIST_SIZE],
41- pub log_en_hist: [i16; DTX_HIST_SIZE],
42- pub hist_ptr: i16,
43- pub log_en_index: i16,
44- pub cng_seed: i16,
45- pub dtxHangoverCount: i16,
46- pub decAnaElapsedCount: i16,
47- pub D: [i32; 28],
48- pub sumD: [i32; DTX_HIST_SIZE],
49-}
50-
5129 #[derive(Clone)]
5230 pub struct DtxDecState {
5331 pub since_last_sid: i16,
5432 pub true_sid_period_inv: i16,
5533 pub log_en: i16,
5634 pub old_log_en: i16,
57- pub level: i16,
5835 pub isf: [i16; M],
5936 pub isf_old: [i16; M],
6037 pub cng_seed: i16,
@@ -79,7 +56,6 @@ impl Default for DtxDecState {
7956 true_sid_period_inv: 0,
8057 log_en: 0,
8158 old_log_en: 0,
82- level: 0,
8359 isf: [0; M],
8460 isf_old: [0; M],
8561 cng_seed: 0,
@@ -192,7 +168,7 @@ pub fn dtx_dec_amr_wb(
192168 ind[2] = Serial_parm(6, prms);
193169 ind[3] = Serial_parm(5, prms);
194170 ind[4] = Serial_parm(5, prms);
195- super::isf::disf_ns(&mut ind, &mut st.isf);
171+ super::isf::disf_ns(&ind, &mut st.isf);
196172 let log_en_index = Serial_parm(6, prms);
197173 st.CN_dith = Serial_parm_1bit(prms);
198174 st.log_en = shl_int16(log_en_index, 15 - 6);
@@ -305,7 +281,7 @@ pub fn dtx_dec_amr_wb_activity_update(st: &mut DtxDecState, isf: &[i16], exc: &[
305281 /// Port of `rx_amr_wb_dtx_handler`.
306282 pub fn rx_amr_wb_dtx_handler(st: &mut DtxDecState, frame_type: i16) -> i16 {
307283 let mut new_state: i16;
308- let enc_state: i16;
284+
309285
310286 if frame_type == RX_SID_FIRST
311287 || frame_type == RX_SID_UPDATE
@@ -339,15 +315,15 @@ pub fn rx_amr_wb_dtx_handler(st: &mut DtxDecState, frame_type: i16) -> i16 {
339315 st.decAnaElapsedCount = add_int16(st.decAnaElapsedCount, 1);
340316 st.dtxHangoverAdded = 0;
341317
342- if frame_type == RX_SID_FIRST
318+ let enc_state: i16 = if frame_type == RX_SID_FIRST
343319 || frame_type == RX_SID_UPDATE
344320 || frame_type == RX_SID_BAD
345321 || frame_type == RX_NO_DATA
346322 {
347- enc_state = DTX;
323+ DTX
348324 } else {
349- enc_state = SPEECH;
350- }
325+ SPEECH
326+ };
351327
352328 if enc_state == SPEECH {
353329 st.dtxHangoverCount = DTX_HANG_CONST;
@@ -377,149 +353,6 @@ pub fn rx_amr_wb_dtx_handler(st: &mut DtxDecState, frame_type: i16) -> i16 {
377353 new_state
378354 }
379355
380-/// Port of `aver_isf_history`.
381-pub fn aver_isf_history(isf_old: &mut [i16], indices: &[i16], isf_aver: &mut [i32]) {
382- let mut isf_tmp = [0i16; 2 * M];
383- for k in 0..2 {
384- if indices[k] as i32 + 1 != 0 {
385- let ik = indices[k] as usize * M;
386- let i2 = indices[2] as usize * M;
387- for i in 0..M {
388- isf_tmp[k * M + i] = isf_old[ik + i];
389- isf_old[ik + i] = isf_old[i2 + i];
390- }
391- }
392- }
393- for j in 0..M {
394- let mut l_tmp: i32 = 0;
395- for i in 0..DTX_HIST_SIZE {
396- l_tmp = add_int32(l_tmp, isf_old[i * M + j] as i32);
397- }
398- isf_aver[j] = l_tmp;
399- }
400- for k in 0..2 {
401- if indices[k] as i32 + 1 != 0 {
402- let ik = indices[k] as usize * M;
403- for i in 0..M {
404- isf_old[ik + i] = isf_tmp[k * M + i];
405- }
406- }
407- }
408-}
409-
410-/// Port of `find_frame_indices`.
411-pub fn find_frame_indices(isf_old_tx: &[i16], indices: &mut [i16], st: &mut DtxEncState) {
412- let mut tmp: i32 = DTX_HIST_SIZE_MIN_ONE as i32;
413- let mut j: i32 = -1;
414- for i in 0..DTX_HIST_SIZE_MIN_ONE {
415- j += tmp;
416- st.sumD[i] = sub_int32(st.sumD[i], st.D[j as usize]);
417- tmp -= 1;
418- }
419- for i in (1..=DTX_HIST_SIZE_MIN_ONE).rev() {
420- st.sumD[i] = st.sumD[i - 1];
421- }
422- st.sumD[0] = 0;
423-
424- tmp = 0;
425- let mut i: i32 = 27;
426- while i >= 12 {
427- tmp += 1;
428- let mut jj = tmp;
429- while jj > 0 {
430- st.D[(i - jj + 1) as usize] = st.D[(i - jj - tmp) as usize];
431- jj -= 1;
432- }
433- i -= tmp;
434- }
435-
436- let mut ptr = st.hist_ptr as i32;
437- let hp = st.hist_ptr as usize;
438- for i in 1..DTX_HIST_SIZE {
439- ptr -= 1;
440- if ptr < 0 {
441- ptr = DTX_HIST_SIZE_MIN_ONE as i32;
442- }
443- let mut l_tmp: i32 = 0;
444- for j in 0..M {
445- let t = sub_int16(isf_old_tx[hp * M + j], isf_old_tx[ptr as usize * M + j]);
446- l_tmp = mac_16by16_to_int32(l_tmp, t, t);
447- }
448- st.D[i - 1] = l_tmp;
449- st.sumD[0] = add_int32(st.sumD[0], st.D[i - 1]);
450- st.sumD[i] = add_int32(st.sumD[i], st.D[i - 1]);
451- }
452-
453- let mut summax = st.sumD[0];
454- let mut summin = st.sumD[0];
455- indices[0] = 0;
456- indices[2] = 0;
457- for i in 1..DTX_HIST_SIZE {
458- if st.sumD[i] > summax {
459- indices[0] = i as i16;
460- summax = st.sumD[i];
461- }
462- if st.sumD[i] < summin {
463- indices[2] = i as i16;
464- summin = st.sumD[i];
465- }
466- }
467-
468- let mut summax2nd: i32 = -2147483647;
469- indices[1] = -1;
470- for i in 0..DTX_HIST_SIZE {
471- if st.sumD[i] > summax2nd && i as i16 != indices[0] {
472- indices[1] = i as i16;
473- summax2nd = st.sumD[i];
474- }
475- }
476-
477- for i in 0..3 {
478- indices[i] = sub_int16(st.hist_ptr, indices[i]);
479- if indices[i] < 0 {
480- indices[i] = add_int16(indices[i], DTX_HIST_SIZE as i16);
481- }
482- }
483-
484- let t = normalize_amr_wb(summax);
485- summax = summax.wrapping_shl(t as u32);
486- summin = summin.wrapping_shl(t as u32);
487- let mut l_tmp = mul_16by16_to_int32(amr_wb_round(summax), INV_MED_THRESH);
488- if l_tmp <= summin {
489- indices[0] = -1;
490- }
491- summax2nd = shl_int32(summax2nd, t);
492- l_tmp = mul_16by16_to_int32(amr_wb_round(summax2nd), INV_MED_THRESH);
493- if l_tmp <= summin {
494- indices[1] = -1;
495- }
496-}
497-
498-/// Port of `dithering_control`.
499-pub fn dithering_control(st: &DtxEncState) -> i16 {
500- let mut isf_diff: i32 = 0;
501- for i in 0..8 {
502- isf_diff = add_int32(isf_diff, st.sumD[i]);
503- }
504- let mut cn_dith: i16 = if (isf_diff >> 26) > 0 { 1 } else { 0 };
505-
506- let mut mean: i16 = 0;
507- for i in 0..DTX_HIST_SIZE {
508- mean = add_int16(mean, st.log_en_hist[i]);
509- }
510- mean >>= 3;
511- let mut gain_diff: i16 = 0;
512- for i in 0..DTX_HIST_SIZE {
513- let mut tmp = sub_int16(st.log_en_hist[i], mean);
514- tmp = tmp.wrapping_sub((tmp < 0) as i16);
515- gain_diff = gain_diff.wrapping_add(tmp ^ (tmp >> 15));
516- }
517- if gain_diff > GAIN_THR {
518- cn_dith = 1;
519- }
520- cn_dith
521-}
522-
523356 /// Port of `CN_dithering`.
524357 pub fn CN_dithering(isf: &mut [i16], l_log_en_int: &mut i32, dither_seed: &mut i16) {
525358 use super::exc::noise_gen_amrwb;
crates/ec-amr/src/wb/exc.rsmodified+6 -6
@@ -478,9 +478,9 @@ pub fn agc2_amr_wb(sig_in: &[i16], sig_out: &mut [i16], l_trm: i16) {
478478 temp = sig_in[i] >> 2;
479479 s = mac_16by16_to_int32(s, temp, temp);
480480 }
481- let g0: i16;
482- if s == 0 {
483- g0 = 0;
481+
482+ let g0: i16 = if s == 0 {
483+ 0
484484 } else {
485485 let i = normalize_amr_wb(s);
486486 let gain_in = amr_wb_round(s.wrapping_shl(i as u32));
@@ -489,8 +489,8 @@ pub fn agc2_amr_wb(sig_in: &[i16], sig_out: &mut [i16], l_trm: i16) {
489489 s2 = shl_int32(s2, 7);
490490 s2 = shr_int32(s2, exp);
491491 s2 = super::math::one_ov_sqrt(s2);
492- g0 = amr_wb_round(shl_int32(s2, 9));
493- }
492+ amr_wb_round(shl_int32(s2, 9))
493+ };
494494 for i in 0..l {
495495 sig_out[i] = super::math::extract_h(shl_int32(fxp_mul_16by16(sig_out[i], g0), 3));
496496 }
@@ -513,7 +513,6 @@ pub fn scale_signal(x: &mut [i16], lg: i16, exp: i16) {
513513 }
514514
515515 /// Ports `median5`. `x[c]` is the C `x[0]` (reads `x[c-2..=c+2]`).
516-#[allow(unused_assignments)]
517516 pub fn median5(x: &[i16], c: usize) -> i16 {
518517 let mut x1 = x[c - 2];
519518 let mut x2 = x[c - 1];
@@ -706,6 +705,7 @@ pub fn dec_gain2_amr_wb_init(mem: &mut [i16]) {
706705 }
707706
708707 /// Ports `dec_gain2_amr_wb`. `mem` has 23 words (see init).
708+#[allow(unused_assignments)]
709709 pub fn dec_gain2_amr_wb(
710710 index: i16,
711711 nbits: i16,
crates/ec-amr/src/wb/math.rsmodified+0 -8
@@ -6,17 +6,9 @@ pub fn extract_h(x: i32) -> i16 {
66 (x >> 16) as i16
77 }
88 #[inline]
9-pub fn extract_l(x: i32) -> i16 {
10- x as i16
11-}
12-#[inline]
139 pub fn l_deposit_h(x: i16) -> i32 {
1410 (x as i32).wrapping_shl(16)
1511 }
16-#[inline]
17-pub fn l_deposit_l(x: i16) -> i32 {
18- x as i32
19-}
2012
2113 /// Ports `mult_int16_r`.
2214 pub fn mult_int16_r(var1: i16, var2: i16) -> i16 {
crates/ec-amr/src/wb/mod.rsmodified+14 -33
@@ -1,23 +1,17 @@
11 //! AMR-WB (3GPP TS 26.173) fixed-point decoder.
2-#![allow(
3- clippy::all,
4- clippy::pedantic,
5- dead_code,
6- unused_assignments,
7- non_snake_case,
8- non_upper_case_globals
9-)]
10-
11-pub mod bits;
12-pub mod core;
13-pub mod dtx;
14-pub mod exc;
15-pub mod exc_tab;
16-pub mod isf;
17-pub mod isf_tab;
18-pub mod math;
19-pub mod ops;
20-pub mod synth;
2+#![allow(non_snake_case, non_upper_case_globals, clippy::if_same_then_else)]
3+#![allow(clippy::needless_range_loop, clippy::too_many_arguments, clippy::manual_memcpy, clippy::manual_clamp)]
4+
5+pub(crate) mod bits;
6+pub(crate) mod core;
7+pub(crate) mod dtx;
8+pub(crate) mod exc;
9+pub(crate) mod exc_tab;
10+pub(crate) mod isf;
11+pub(crate) mod isf_tab;
12+pub(crate) mod math;
13+pub(crate) mod ops;
14+pub(crate) mod synth;
2115
2216 use ec_core::error::{Error, Result};
2317 use ec_core::frame::{AudioFrame, ChannelLayout, Frame, SampleFormat};
@@ -34,16 +28,6 @@ use self::dtx::{RX_NO_DATA, RX_SPEECH_GOOD, RX_SPEECH_LOST};
3428 /// Samples in one decoded AMR-WB frame (20 ms at 16 kHz).
3529 pub const FRAME_SAMPLES: usize = 320;
3630
37-/// Payload bytes (after the ToC byte) of an AMR-WB frame type, `None` for reserved types.
38-fn payload_len(ft: u8) -> Option<usize> {
39- const SIZES: [usize; 10] = [17, 23, 32, 36, 40, 46, 50, 58, 60, 5];
40- match ft {
41- 0..=9 => Some(SIZES[usize::from(ft)]),
42- 14 | 15 => Some(0),
43- _ => None,
44- }
45-}
46-
4731 /// A fixed-point AMR-WB decoder (3GPP TS 26.173), bit-exact with the reference decoder's
4832 /// 14-bit output. Packets are one or more frames, each a ToC byte followed by the speech bits
4933 /// (the `sawb` sample layout and the `.awb` frame layout).
@@ -78,7 +62,6 @@ impl AmrWbDecoder {
7862 AmrWbDecoder {
7963 st: DecoderState::new(),
8064 rx: RxState {
81- prev_ft: RX_SPEECH_GOOD,
8265 prev_mode: 0,
8366 },
8467 mode_old: 0,
@@ -101,7 +84,6 @@ impl AmrWbDecoder {
10184 fn reset_state(&mut self) {
10285 self.st = DecoderState::new();
10386 self.rx = RxState {
104- prev_ft: RX_SPEECH_GOOD,
10587 prev_mode: 0,
10688 };
10789 self.mode_old = 0;
@@ -117,8 +99,7 @@ impl AmrWbDecoder {
11799 while at < data.len() {
118100 let toc = data[at];
119101 let ft = (toc >> 3) & 0x0F;
120- let n = payload_len(ft)
121- .ok_or_else(|| Error::corrupt(format!("AMR-WB frame type {ft} is reserved")))?;
102+ let n = crate::container::wb_frame_size(ft)?;
122103 if at + 1 + n > data.len() {
123104 return Err(Error::corrupt("AMR-WB frame is truncated"));
124105 }
crates/ec-amr/src/wb/ops.rsmodified+2 -15
@@ -1,10 +1,8 @@
11 //! ETSI-style saturating basic operators (port of the 3GPP TS 26.173 basic_op set).
2-#![allow(dead_code)]
32
43 pub const MAX_16: i16 = 32767;
54 pub const MIN_16: i16 = -32768;
65 pub const MAX_32: i32 = 0x7fff_ffff;
7-pub const MIN_32: i32 = i32::MIN;
86
97 #[inline]
108 pub fn sat16(x: i32) -> i16 {
@@ -71,7 +69,7 @@ pub fn amr_wb_shl1_round(l: i32) -> i16 {
7169 }
7270 #[inline]
7371 pub fn mul_32by16(hi: i16, lo: i16, n: i16) -> i32 {
74- (((hi as i32 * n as i32) + ((lo as i32 * n as i32) >> 15)) as i32).wrapping_shl(1)
72+ ((hi as i32 * n as i32) + ((lo as i32 * n as i32) >> 15)).wrapping_shl(1)
7573 }
7674 /// plain (non saturating) 16x16 -> 32 multiply-accumulate
7775 #[inline]
@@ -97,7 +95,7 @@ pub fn shl_int16(v: i16, s: i16) -> i16 {
9795 let s = (s & 0xf) as u32;
9896 let out = ((v as i32) << s) as i16;
9997 if ((out as i32) >> s) != v as i32 {
100- ((v >> 15) ^ MAX_16) as i16
98+ (v >> 15) ^ MAX_16
10199 } else {
102100 out
103101 }
@@ -158,10 +156,6 @@ pub fn normalize_amr_wb(x: i32) -> i16 {
158156 i as i16
159157 }
160158 #[inline]
161-pub fn norm_l(x: i32) -> i16 {
162- normalize_amr_wb(x)
163-}
164-#[inline]
165159 pub fn norm_s(x: i16) -> i16 {
166160 normalize_amr_wb(x as i32) - 16
167161 }
@@ -175,7 +169,6 @@ pub const M: usize = 16;
175169 pub const M16K: usize = 20;
176170 pub const L_FILT16K: usize = 15;
177171 pub const L_FILT: usize = 12;
178-pub const GP_CLIP: i16 = 15565;
179172 pub const PIT_SHARP: i16 = 27853;
180173 pub const PIT_MIN: i16 = 34;
181174 pub const PIT_FR2: i16 = 128;
@@ -184,14 +177,10 @@ pub const PIT_FR1_8B: i16 = 92;
184177 pub const PIT_MAX: i16 = 231;
185178 pub const L_INTERPOL: usize = 17;
186179 pub const PREEMPH_FAC: i16 = 22282;
187-pub const GAMMA1: i16 = 30147;
188-pub const TILT_FAC: i16 = 22282;
189180 pub const Q_MAX: i16 = 8;
190181 pub const RANDOM_INITSEED: i16 = 21845;
191182 pub const L_MEANBUF: usize = 3;
192-pub const ONE_PER_MEANBUF: i16 = 10923;
193183 pub const EHF_MASK: i16 = 0x0008;
194-pub const AMR_WB_PCM_FRAME: usize = 320;
195184 pub const NBBITS_7K: i16 = 132;
196185 pub const NBBITS_9K: i16 = 177;
197186 pub const NBBITS_12K: i16 = 253;
@@ -199,7 +188,5 @@ pub const NBBITS_14K: i16 = 285;
199188 pub const NBBITS_16K: i16 = 317;
200189 pub const NBBITS_18K: i16 = 365;
201190 pub const NBBITS_20K: i16 = 397;
202-pub const NBBITS_23K: i16 = 461;
203191 pub const NBBITS_24K: i16 = 477;
204-pub const NBBITS_SID: i16 = 35;
205192 pub const AMR_WB_COMPRESSED: [i16; 10] = [132, 177, 253, 285, 317, 365, 397, 461, 477, 35];
crates/ec-amr/src/wb/synth.rsmodified+0 -2
@@ -1,13 +1,11 @@
11 //! AMR-WB synthesis stage: ports of wb_syn_filt.cpp, synthesis_amr_wb.cpp,
22 //! oversamp_12k8_to_16k.cpp, highpass_50hz_at_12k8.cpp, highpass_400hz_at_12k8.cpp,
33 //! band_pass_6k_7k.cpp, low_pass_filt_7k.cpp, deemphasis_32.cpp, isf_extrapolation.cpp.
4-#![allow(dead_code)]
54
65 use super::ops::*;
76
87 const L_FIR_BP: usize = 30;
98 const L_FIR_LP: usize = 30;
10-const L_FILT16K_: usize = 15;
119 const SPEECH: i16 = 0;
1210
1311 pub static HP_GAIN: [i16; 16] = [