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 @@
2 //! opencore-amr C-equivalent basic_op. Word16 = i16, Word32 = i32.2 //! opencore-amr C-equivalent basic_op. Word16 = i16, Word32 = i32.
3 //! Plain functions have no overflow flag; `*_o` variants additionally set `*ovf = true`3 //! Plain functions have no overflow flag; `*_o` variants additionally set `*ovf = true`
4 //! when the result saturated. `round_` is C `round`/`pv_round`.4 //! when the result saturated. `round_` is C `round`/`pv_round`.
5-#![allow(dead_code)]
6 5
7 pub const MAX_16: i16 = 0x7fff;6 pub const MAX_16: i16 = 0x7fff;
8 pub const MIN_16: i16 = -0x8000;7 pub const MIN_16: i16 = -0x8000;
@@ -13,38 +12,10 @@ use super::tables::{INV_SQRT_TBL, LOG2_TBL, POW2_TBL, SQRT_L_TBL};
13 12
14 // ---------------------------------------------------------------- 16-bit13 // ---------------------------------------------------------------- 16-bit
15 14
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-}
30 #[inline]15 #[inline]
31 pub fn add(a: i16, b: i16) -> i16 {16 pub fn add(a: i16, b: i16) -> i16 {
32 (a as i32 + b as i32).clamp(-32768, 32767) as i1617 (a as i32 + b as i32).clamp(-32768, 32767) as i16
33 }18 }
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-}
48 #[inline]19 #[inline]
49 pub fn sub(a: i16, b: i16) -> i16 {20 pub fn sub(a: i16, b: i16) -> i16 {
50 (a as i32 - b as i32).clamp(-32768, 32767) as i1621 (a as i32 - b as i32).clamp(-32768, 32767) as i16
@@ -77,24 +48,6 @@ pub fn mult(a: i16, b: i16) -> i16 {
77 p as i1648 p as i16
78 }49 }
79 }50 }
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-}
98 51
99 /// C shl (left shift with saturation; negative count shifts right, count <= -15 gives 0).52 /// C shl (left shift with saturation; negative count shifts right, count <= -15 gives 0).
100 #[inline]53 #[inline]
@@ -159,18 +112,6 @@ pub fn shr_r(var1: i16, var2: i16) -> i16 {
159 out112 out
160 }113 }
161 }114 }
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-}
174 115
175 // ---------------------------------------------------------------- 32-bit116 // ---------------------------------------------------------------- 32-bit
176 117
@@ -189,16 +130,6 @@ pub fn l_add(a: i32, b: i32) -> i32 {
189 a.saturating_add(b)130 a.saturating_add(b)
190 }131 }
191 #[inline]132 #[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]
202 pub fn l_sub(a: i32, b: i32) -> i32 {133 pub fn l_sub(a: i32, b: i32) -> i32 {
203 a.saturating_sub(b)134 a.saturating_sub(b)
204 }135 }
@@ -212,11 +143,6 @@ pub fn l_mult(a: i16, b: i16) -> i32 {
212 MAX_32143 MAX_32
213 }144 }
214 }145 }
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-}
220 /// C L_mac: opencore semantics (0x4000_0000 product gives MAX_32).146 /// C L_mac: opencore semantics (0x4000_0000 product gives MAX_32).
221 #[inline]147 #[inline]
222 pub fn l_mac_o(acc: i32, a: i16, b: i16, ovf: &mut bool) -> i32 {148 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 {
232 pub fn l_mac(acc: i32, a: i16, b: i16) -> i32 {158 pub fn l_mac(acc: i32, a: i16, b: i16) -> i32 {
233 l_mac_o(acc, a, b, &mut false)159 l_mac_o(acc, a, b, &mut false)
234 }160 }
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-}
240 #[inline]161 #[inline]
241 pub fn l_msu(acc: i32, a: i16, b: i16) -> i32 {162 pub fn l_msu(acc: i32, a: i16, b: i16) -> i32 {
242 l_sub(acc, l_mult(a, b))163 l_sub(acc, l_mult(a, b))
243 }164 }
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-}
268 /// C L_shl: left shift with saturation (negative count: arithmetic right, count <= -31 gives 0).165 /// C L_shl: left shift with saturation (negative count: arithmetic right, count <= -31 gives 0).
269 #[inline]166 #[inline]
270 pub fn l_shl_o(x: i32, n: i16, ovf: &mut bool) -> i32 {167 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 {
324 pub fn round_(x: i32) -> i16 {221 pub fn round_(x: i32) -> i16 {
325 (l_add(x, 0x8000) >> 16) as i16222 (l_add(x, 0x8000) >> 16) as i16
326 }223 }
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-}
337 224
338 /// Normalisation shift count for 16-bit (0 for 0 input).225 /// Normalisation shift count for 16-bit (0 for 0 input).
339 #[inline]226 #[inline]
@@ -395,37 +282,6 @@ pub fn div_s(var1: i16, var2: i16) -> i16 {
395 282
396 // ---------------------------------------------------------------- 32-bit via hi/lo283 // ---------------------------------------------------------------- 32-bit via hi/lo
397 284
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-}
429 /// C Mpy_32_16: (hi/lo) * var2.285 /// C Mpy_32_16: (hi/lo) * var2.
430 #[inline]286 #[inline]
431 pub fn mpy_32_16(hi: i16, lo: i16, v: i16) -> i32 {287 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 {
438 }294 }
439 s295 s
440 }296 }
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-}
470 297
471 // ---------------------------------------------------------------- math functions298 // ---------------------------------------------------------------- math functions
472 299
@@ -492,7 +319,7 @@ pub fn log2_norm(x: i32, exp: i16, exponent: &mut i16, fraction: &mut i16) {
492 *exponent = 30i16.wrapping_sub(exp);319 *exponent = 30i16.wrapping_sub(exp);
493 let x = x >> 10;320 let x = x >> 10;
494 let i = ((x >> 15) as i16).wrapping_sub(32) as usize;321 let i = ((x >> 15) as i16).wrapping_sub(32) as usize;
495- let a = (x & 0x7fff) as i32;322+ let a = x & 0x7fff;
496 let mut y = (LOG2_TBL[i] as i32) << 16;323 let mut y = (LOG2_TBL[i] as i32) << 16;
497 let tmp = LOG2_TBL[i].wrapping_sub(LOG2_TBL[i + 1]) as i32;324 let tmp = LOG2_TBL[i].wrapping_sub(LOG2_TBL[i + 1]) as i32;
498 y = y.wrapping_sub((tmp * a) << 1);325 y = y.wrapping_sub((tmp * a) << 1);
@@ -540,7 +367,7 @@ pub fn sqrt_l_exp(l_x: i32, exp: &mut i16) -> i32 {
540 *exp = e;367 *exp = e;
541 let x = x >> 10;368 let x = x >> 10;
542 let mut i = ((x >> 15) & 63) as usize;369 let mut i = ((x >> 15) & 63) as usize;
543- let a = (x as i16 & 0x7fff) as i16;370+ let a = x as i16 & 0x7fff;
544 if i > 15 {371 if i > 15 {
545 i -= 16;372 i -= 16;
546 }373 }
@@ -584,7 +411,6 @@ mod tests {
584 assert_eq!(l_mult(-32768, -32768), i32::MAX);411 assert_eq!(l_mult(-32768, -32768), i32::MAX);
585 assert_eq!(l_mac(5, -32768, -32768), i32::MAX);412 assert_eq!(l_mac(5, -32768, -32768), i32::MAX);
586 assert_eq!(mult(-32768, -32768), 32767);413 assert_eq!(mult(-32768, -32768), 32767);
587- assert_eq!(mult_r(-32768, -32768), 32767);
588 assert_eq!(shl(0x4000, 1), 32767);414 assert_eq!(shl(0x4000, 1), 32767);
589 assert_eq!(shl(-0x4001, 1), -32768);415 assert_eq!(shl(-0x4001, 1), -32768);
590 assert_eq!(shl(3, 2), 12);416 assert_eq!(shl(3, 2), 12);
@@ -596,9 +422,6 @@ mod tests {
596 assert_eq!(l_shl(-0x4000_0001, 1), i32::MIN);422 assert_eq!(l_shl(-0x4000_0001, 1), i32::MIN);
597 assert_eq!(l_shr_r(5, 1), 3);423 assert_eq!(l_shr_r(5, 1), 3);
598 assert_eq!(l_shr(1, -31), i32::MAX);424 assert_eq!(l_shr(1, -31), i32::MAX);
599- let mut o = false;
600- add_o(32767, 1, &mut o);
601- assert!(o);
602 }425 }
603 426
604 #[test]427 #[test]
@@ -619,9 +442,5 @@ mod tests {
619 log2(1 << 20, &mut e, &mut f);442 log2(1 << 20, &mut e, &mut f);
620 assert_eq!((e, f), (20, 0));443 assert_eq!((e, f), (20, 0));
621 assert_eq!(gmed_n(&[5, 1, 9, 3, 7], 5), 5);444 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);
625 }445 }
626 }446 }
627-
crates/ec-amr/src/nb/bitstream.rsmodified+1 -2
@@ -1,6 +1,5 @@
1 //! AMR-NB bitstream: RFC 4867 / 3GPP TS 26.101 IF1 (octet-aligned, "MIME/IETF storage") frame1 //! AMR-NB bitstream: RFC 4867 / 3GPP TS 26.101 IF1 (octet-aligned, "MIME/IETF storage") frame
2 //! parsing into decoder parameters (wmf_to_ets + bits2prm of opencore-amr).2 //! parsing into decoder parameters (wmf_to_ets + bits2prm of opencore-amr).
3-#![allow(dead_code)]
4 3
5 use super::tables::*;4 use super::tables::*;
6 5
@@ -178,7 +177,7 @@ mod tests {
178 assert_eq!(frame_bytes(10), None);177 assert_eq!(frame_bytes(10), None);
179 // (bits + 7) / 8 for each mode178 // (bits + 7) / 8 for each mode
180 for ft in 0..8usize {179 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);
182 }181 }
183 }182 }
184 183
crates/ec-amr/src/nb/decoder.rsmodified+5 -6
@@ -1,6 +1,5 @@
1 //! AMR-NB decoder: port of opencore-amr `dec_amr.cpp` (Decoder_amr) and `sp_dec.cpp`1 //! AMR-NB decoder: port of opencore-amr `dec_amr.cpp` (Decoder_amr) and `sp_dec.cpp`
2 //! (GSMFrameDecode), plus the `AMRDecode` frame-type handling of the libopencore-amrnb wrapper.2 //! (GSMFrameDecode), plus the `AMRDecode` frame-type handling of the libopencore-amrnb wrapper.
3-#![allow(clippy::all)]
4 3
5 use super::basic::*;4 use super::basic::*;
6 use super::bitstream::{parse_frame, BitstreamError, RxFrameType};5 use super::bitstream::{parse_frame, BitstreamError, RxFrameType};
@@ -49,9 +48,9 @@ fn agc2(sig_in: &[i16], sig_out: &mut [i16]) {
49 let mut exp = norm_l(s) - 1;48 let mut exp = norm_l(s) - 1;
50 let gain_out = round_(l_shl(s, exp));49 let gain_out = round_(l_shl(s, exp));
51 s = energy_new(&sig_in[..l]);50 s = energy_new(&sig_in[..l]);
52- let g0: i16;51+
53- if s == 0 {52+ let g0: i16 = if s == 0 {
54- g0 = 0;53+ 0
55 } else {54 } else {
56 let i = norm_l(s);55 let i = norm_l(s);
57 let gain_in = round_(l_shl(s, i));56 let gain_in = round_(l_shl(s, i));
@@ -74,8 +73,8 @@ fn agc2(sig_in: &[i16], sig_out: &mut [i16]) {
74 } else {73 } else {
75 s << 974 s << 9
76 };75 };
77- g0 = round_(lt);76+ round_(lt)
78- }77+ };
79 for i in (0..l).rev() {78 for i in (0..l).rev() {
80 let lt = l_mult(sig_out[i], g0);79 let lt = l_mult(sig_out[i], g0);
81 sig_out[i] = if lt > 0x0FFF_FFFF {80 sig_out[i] = if lt > 0x0FFF_FFFF {
crates/ec-amr/src/nb/dtx.rsmodified+1 -2
@@ -1,6 +1,5 @@
1 //! Decoder-side DTX / error-concealment helpers: dtx_dec, lsp_avg, bgnscd, c_g_aver,1 //! Decoder-side DTX / error-concealment helpers: dtx_dec, lsp_avg, bgnscd, c_g_aver,
2 //! ec_gains, ex_ctrl, pseudonoise / build_CN_code.2 //! ec_gains, ex_ctrl, pseudonoise / build_CN_code.
3-#![allow(clippy::too_many_arguments, clippy::needless_range_loop)]
4 3
5 use super::basic::*;4 use super::basic::*;
6 use super::bitstream::RxFrameType;5 use super::bitstream::RxFrameType;
@@ -659,7 +658,7 @@ pub fn dtx_dec(
659 lsf_state.past_r_q = [0; M];658 lsf_state.past_r_q = [0; M];
660 659
661 let log_en_index = parm[4];660 let log_en_index = parm[4];
662- if log_en_index > 63 || log_en_index < -64 {661+ if !(-64..=63).contains(&log_en_index) {
663 st.log_en = if log_en_index > 0 { i16::MAX } else { i16::MIN };662 st.log_en = if log_en_index > 0 { i16::MAX } else { i16::MIN };
664 } else {663 } else {
665 st.log_en = log_en_index << (11 - 2);664 st.log_en = log_en_index << (11 - 2);
crates/ec-amr/src/nb/excitation.rsmodified+10 -11
@@ -1,6 +1,5 @@
1 //! AMR-NB excitation decoding: pitch lag, algebraic codebooks, gains, phase dispersion.1 //! AMR-NB excitation decoding: pitch lag, algebraic codebooks, gains, phase dispersion.
2 //! Bit-exact port of the 3GPP TS 26.073 reference (opencore-amr flavour).2 //! 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)]
4 3
5 use super::basic::*;4 use super::basic::*;
6 use super::tables::*;5 use super::tables::*;
@@ -192,10 +191,10 @@ fn pulse_val(sign: i32) -> i16 {
192 /// C `dec_10i40_35bits` (MR122 codebook). `index` has 10 entries; `cod` 40 samples.191 /// C `dec_10i40_35bits` (MR122 codebook). `index` has 10 entries; `cod` 40 samples.
193 #[inline]192 #[inline]
194 pub fn dec_10i40_35bits(index: &[i16], cod: &mut [i16]) {193 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() {
196 *c = 0;195 *c = 0;
197 }196 }
198- for j in 0..NB_TRACK as usize {197+ for j in 0..NB_TRACK {
199 let tmp = index[j] as i32;198 let tmp = index[j] as i32;
200 let i = DGRAY[(tmp & 7) as usize] as i32;199 let i = DGRAY[(tmp & 7) as usize] as i32;
201 let pos1 = (i * 5) as usize + j;200 let pos1 = (i * 5) as usize + j;
@@ -327,7 +326,7 @@ fn decompress10(msbs: i32, lsbs: i32, index1: usize, index2: usize, index3: usiz
327 #[inline]326 #[inline]
328 pub fn dec_8i40_31bits(index: &[i16], cod: &mut [i16]) {327 pub fn dec_8i40_31bits(index: &[i16], cod: &mut [i16]) {
329 const NT: usize = 4;328 const NT: usize = 4;
330- for c in cod[..L_CODE as usize].iter_mut() {329+ for c in cod[..L_CODE].iter_mut() {
331 *c = 0;330 *c = 0;
332 }331 }
333 let mut signs = [0i32; NT];332 let mut signs = [0i32; NT];
@@ -433,7 +432,7 @@ pub fn gc_pred(
433 let mut exp = 0i16;432 let mut exp = 0i16;
434 let mut frac = 0i16;433 let mut frac = 0i16;
435 log2(ener_code, &mut exp, &mut frac);434 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);
437 ener_code = l1.wrapping_add((frac as i32) << 1);436 ener_code = l1.wrapping_add((frac as i32) << 1);
438 let mut ener = MEAN_ENER_MR122;437 let mut ener = MEAN_ENER_MR122;
439 for i in 0..NPRED {438 for i in 0..NPRED {
@@ -487,7 +486,7 @@ pub fn gc_pred(
487 l_tmp <<= 10;486 l_tmp <<= 10;
488 }487 }
489 for i in 0..4 {488 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;
491 l_tmp = l_add(l_tmp, l2);490 l_tmp = l_add(l_tmp, l2);
492 }491 }
493 let gcode0 = (l_tmp >> 16) as i16;492 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: &
616 );615 );
617 let index = (index & 31) as usize;616 let index = (index & 31) as usize;
618 let p = &QUA_GAIN_CODE[index + (index << 1)..];617 let p = &QUA_GAIN_CODE[index + (index << 1)..];
619- let gain_code: i16;618+
620- if mode == Mode::Mr122 {619+ let gain_code: i16 = if mode == Mode::Mr122 {
621 let mut gcode0 = pow2(exp, frac) as i16;620 let mut gcode0 = pow2(exp, frac) as i16;
622 gcode0 = shl(gcode0, 4);621 gcode0 = shl(gcode0, 4);
623- gain_code = shl(mult(gcode0, p[0]), 1);622+ shl(mult(gcode0, p[0]), 1)
624 } else {623 } else {
625 let gcode0 = pow2(14, frac) as i16;624 let gcode0 = pow2(14, frac) as i16;
626 let l = l_mult(p[0], gcode0);625 let l = l_mult(p[0], gcode0);
627 let l = l_shr(l, sub(9, exp));626 let l = l_shr(l, sub(9, exp));
628- gain_code = (l >> 16) as i16;627+ (l >> 16) as i16
629- }628+ };
630 let qua_ener_mr122 = p[1];629 let qua_ener_mr122 = p[1];
631 let qua_ener = p[2];630 let qua_ener = p[2];
632 gc_pred_update(pred_state, qua_ener_mr122, qua_ener);631 gc_pred_update(pred_state, qua_ener_mr122, qua_ener);
crates/ec-amr/src/nb/lpc.rsmodified+0 -25
@@ -1,6 +1,5 @@
1 //! LSF/LSP decoding, conversion and interpolation (d_plsf*, int_lsf, lsp_lsf,1 //! LSF/LSP decoding, conversion and interpolation (d_plsf*, int_lsf, lsp_lsf,
2 //! lsp_az, int_lpc, reorder). Bit-exact port of the 3GPP reference.2 //! lsp_az, int_lpc, reorder). Bit-exact port of the 3GPP reference.
3-#![allow(dead_code)]
4 3
5 use super::basic::{add, mult, negate, shl, sub};4 use super::basic::{add, mult, negate, shl, sub};
6 use super::tables::{5 use super::tables::{
@@ -305,15 +304,6 @@ pub fn int_lpc_1and3(lsp_old: &[i16], lsp_mid: &[i16], lsp_new: &[i16], az: &mut
305 lsp_az(lsp_new, &mut az[3 * MP1..]);304 lsp_az(lsp_new, &mut az[3 * MP1..]);
306 }305 }
307 306
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-
317 /// C `Int_lpc_1to3`: 4 subframes from old/new LSPs; writes Az[0..44].307 /// C `Int_lpc_1to3`: 4 subframes from old/new LSPs; writes Az[0..44].
318 pub fn int_lpc_1to3(lsp_old: &[i16], lsp_new: &[i16], az: &mut [i16]) {308 pub fn int_lpc_1to3(lsp_old: &[i16], lsp_new: &[i16], az: &mut [i16]) {
319 let mut lsp = [0i16; M];309 let mut lsp = [0i16; M];
@@ -329,18 +319,3 @@ pub fn int_lpc_1to3(lsp_old: &[i16], lsp_new: &[i16], az: &mut [i16]) {
329 lsp_az(&lsp, &mut az[2 * MP1..]);319 lsp_az(&lsp, &mut az[2 * MP1..]);
330 lsp_az(lsp_new, &mut az[3 * MP1..]);320 lsp_az(lsp_new, &mut az[3 * MP1..]);
331 }321 }
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 @@
1 //! AMR-NB decoder (fixed-point, bit-exact port of the 3GPP TS 26.073 reference as1 //! AMR-NB decoder (fixed-point, bit-exact port of the 3GPP TS 26.073 reference as
2 //! carried by the Apache-2.0 opencore-amr sources).2 //! carried by the Apache-2.0 opencore-amr sources).
3-#![allow(clippy::all)]3+#![allow(clippy::needless_range_loop, clippy::too_many_arguments, clippy::manual_memcpy, clippy::manual_clamp)]
4-pub mod basic;
5 pub mod bitstream;4 pub mod bitstream;
6 pub mod decoder;5 pub mod decoder;
7-pub mod dtx;6+pub(crate) mod basic;
8-pub mod excitation;7+pub(crate) mod dtx;
9-pub mod lpc;8+pub(crate) mod excitation;
10-pub mod post;9+pub(crate) mod lpc;
11-pub mod tables;10+pub(crate) mod post;
11+pub(crate) mod tables;
crates/ec-amr/src/nb/post.rsmodified+5 -19
@@ -1,7 +1,5 @@
1 //! AMR-NB post-processing chain: syn_filt, residu, weight_ai, a_refl, preemphasis,1 //! AMR-NB post-processing chain: syn_filt, residu, weight_ai, a_refl, preemphasis,
2 //! agc, post_filter, post_process (bit-exact port of opencore-amr).2 //! agc, post_filter, post_process (bit-exact port of opencore-amr).
3-#![allow(clippy::all)]
4-#![allow(dead_code)]
5 3
6 use super::basic::*;4 use super::basic::*;
7 use super::tables::Mode;5 use super::tables::Mode;
@@ -128,9 +126,6 @@ impl PreemphasisState {
128 pub fn new() -> Self {126 pub fn new() -> Self {
129 Self { mem_pre: 0 }127 Self { mem_pre: 0 }
130 }128 }
131- pub fn reset(&mut self) {
132- self.mem_pre = 0;
133- }
134 }129 }
135 130
136 /// C preemphasis: in-place signal[0..l] -= g*signal[i-1] (mem for i=0).131 /// C preemphasis: in-place signal[0..l] -= g*signal[i-1] (mem for i=0).
@@ -155,9 +150,6 @@ impl AgcState {
155 pub fn new() -> Self {150 pub fn new() -> Self {
156 Self { past_gain: 4096 }151 Self { past_gain: 4096 }
157 }152 }
158- pub fn reset(&mut self) {
159- self.past_gain = 4096;
160- }
161 }153 }
162 154
163 fn energy_new(inp: &[i16], l: usize) -> i32 {155 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,
189 let l_temp = l_shl(s, exp);181 let l_temp = l_shl(s, exp);
190 let gain_out = round_(l_temp);182 let gain_out = round_(l_temp);
191 s = energy_new(&sig_in[..l], l);183 s = energy_new(&sig_in[..l], l);
192- let g0: i16;184+
193- if s == 0 {185+ let g0: i16 = if s == 0 {
194- g0 = 0;186+ 0
195 } else {187 } else {
196 let i = norm_l(s);188 let i = norm_l(s);
197 let l_temp = s.wrapping_shl(i as u32);189 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,
204 let l_temp = s.wrapping_shl(9);196 let l_temp = s.wrapping_shl(9);
205 let i = (l_temp.wrapping_add(0x8000) >> 16) as i16;197 let i = (l_temp.wrapping_add(0x8000) >> 16) as i16;
206 let temp = 32767 - agc_fac;198 let temp = 32767 - agc_fac;
207- g0 = (((i as i32) * (temp as i32)) >> 15) as i16;199+ (((i as i32) * (temp as i32)) >> 15) as i16
208- }200+ };
209 let mut gain = st.past_gain;201 let mut gain = st.past_gain;
210 for i in 0..l {202 for i in 0..l {
211 gain = (((gain as i32) * (agc_fac as i32)) >> 15) as i16;203 gain = (((gain as i32) * (agc_fac as i32)) >> 15) as i16;
@@ -236,9 +228,6 @@ impl PostFilterState {
236 synth_buf: [0; M + L_FRAME],228 synth_buf: [0; M + L_FRAME],
237 }229 }
238 }230 }
239- pub fn reset(&mut self) {
240- *self = Self::new();
241- }
242 }231 }
243 232
244 /// C Post_Filter: syn[0..160] is the synthesis speech, replaced by the postfiltered233 /// C Post_Filter: syn[0..160] is the synthesis speech, replaced by the postfiltered
@@ -337,9 +326,6 @@ impl PostProcessState {
337 pub fn new() -> Self {326 pub fn new() -> Self {
338 Self::default()327 Self::default()
339 }328 }
340- pub fn reset(&mut self) {
341- *self = Self::default();
342- }
343 }329 }
344 330
345 /// C Post_Process: in-place high-pass filter and upscale of signal[0..lg].331 /// 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 @@
1 //! Constant tables for the AMR-NB decoder. GENERATED by /tmp/amrsrc/gen/gen.py from the C sources; do not edit.1 //! 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)]
3 2
4 // ---- constants (cnst.h / mode.h / bitno_tab.h / table sizes) ----3 // ---- constants (cnst.h / mode.h / bitno_tab.h / table sizes) ----
5-pub const L_TOTAL: usize = 320;
6-pub const L_WINDOW: usize = 240;
7 pub const L_FRAME: usize = 160;4 pub const L_FRAME: usize = 160;
8 pub const L_FRAME_BY2: usize = 80;5 pub const L_FRAME_BY2: usize = 80;
9 pub const L_SUBFR: usize = 40;6 pub const L_SUBFR: usize = 40;
10 pub const L_CODE: usize = 40;7 pub const L_CODE: usize = 40;
11 pub const NB_TRACK: usize = 5;8 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;
15 pub const M: usize = 10;9 pub const M: usize = 10;
16 pub const MP1: usize = 11;10 pub const MP1: usize = 11;
17 pub const LSF_GAP: i16 = 205;11 pub const LSF_GAP: i16 = 205;
18-pub const LSP_PRED_FAC_MR122: i16 = 21299;
19 pub const AZ_SIZE: usize = 44;12 pub const AZ_SIZE: usize = 44;
20 pub const PIT_MIN_MR122: i16 = 18;13 pub const PIT_MIN_MR122: i16 = 18;
21 pub const PIT_MIN: i16 = 20;14 pub const PIT_MIN: i16 = 20;
22 pub const PIT_MAX: i16 = 143;15 pub const PIT_MAX: i16 = 143;
23 pub const L_INTERPOL: usize = 11;16 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;
28 pub const SHARPMAX: i16 = 13017;17 pub const SHARPMAX: i16 = 13017;
29 pub const SHARPMIN: i16 = 0;18 pub const SHARPMIN: i16 = 0;
30 pub const MAX_PRM_SIZE: usize = 57;19 pub const MAX_PRM_SIZE: usize = 57;
31 pub const MAX_SERIAL_SIZE: usize = 244;20 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;
43 pub const MR475_VQ_SIZE: usize = 256;21 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;
96 22
97 #[derive(Clone, Copy, PartialEq, Eq, Debug)]23 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
98 pub enum Mode { Mr475, Mr515, Mr59, Mr67, Mr74, Mr795, Mr102, Mr122, MrDtx }24 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 }
100 pub static PRMNO: [i16; 9] = [26 pub static PRMNO: [i16; 9] = [
101 17, 19, 19, 19, 19, 23, 39, 57, 5,27 17, 19, 19, 19, 19, 23, 39, 57, 5,
102 ];28 ];
103-pub static PRMNOFSF: [i16; 8] = [
104- 7, 7, 7, 7, 7, 8, 12, 18,
105-];
106 pub static BITNO_MR475: [i16; 17] = [29 pub static BITNO_MR475: [i16; 17] = [
107 8, 8, 7, 8, 7, 2, 8, 4, 7, 2, 4, 7,30 8, 8, 7, 8, 7, 2, 8, 4, 7, 2, 4, 7,
108 2, 8, 4, 7, 2,31 2, 8, 4, 7, 2,
@@ -267,10 +190,6 @@ pub static REORDERBITS_MR122: [i16; 244] = [
267 225, 224, 229, 228, 227, 232, 231, 230, 235, 234, 233, 238,190 225, 224, 229, 228, 227, 232, 231, 230, 235, 234, 233, 238,
268 237, 236, 96, 199,191 237, 236, 96, 199,
269 ];192 ];
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-];
274 pub static STARTPOS: [i16; 16] = [ // 2 cols193 pub static STARTPOS: [i16; 16] = [ // 2 cols
275 0, 2, 0, 3, 0, 2, 0, 3, 1, 3, 2, 4,194 0, 2, 0, 3, 0, 2, 0, 3, 1, 3, 2, 4,
276 1, 4, 1, 4,195 1, 4, 1, 4,
@@ -290,20 +209,9 @@ pub static QUA_GAIN_CODE: [i16; 99] = [ // 3 cols
290 12510, 2673, 16096, 16263, 3060, 18429, 21142, 3448, 20763, 27485, 3836, 23097,209 12510, 2673, 16096, 16263, 3060, 18429, 21142, 3448, 20763, 27485, 3836, 23097,
291 27485, 3836, 23097,210 27485, 3836, 23097,
292 ];211 ];
293-pub static GRAY: [i16; 8] = [
294- 0, 1, 3, 2, 6, 4, 5, 7,
295-];
296 pub static DGRAY: [i16; 8] = [212 pub static DGRAY: [i16; 8] = [
297 0, 1, 3, 2, 5, 6, 4, 7,213 0, 1, 3, 2, 5, 6, 4, 7,
298 ];214 ];
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-];
307 pub static INV_SQRT_TBL: [i16; 49] = [215 pub static INV_SQRT_TBL: [i16; 49] = [
308 32767, 31790, 30894, 30070, 29309, 28602, 27945, 27330, 26755, 26214, 25705, 25225,216 32767, 31790, 30894, 30070, 29309, 28602, 27945, 27330, 26755, 26214, 25705, 25225,
309 24770, 24339, 23930, 23541, 23170, 22817, 22479, 22155, 21845, 21548, 21263, 20988,217 24770, 24339, 23930, 23541, 23170, 22817, 22479, 22155, 21845, 21548, 21263, 20988,
@@ -332,9 +240,6 @@ pub static SLOPE: [i16; 64] = [
332 -946, -998, -1059, -1132, -1219, -1322, -1450, -1608, -1811, -2081, -2444, -2979,240 -946, -998, -1059, -1132, -1219, -1322, -1450, -1608, -1811, -2081, -2444, -2979,
333 -3813, -5323, -8812, -26887,241 -3813, -5323, -8812, -26887,
334 ];242 ];
335-pub static LSP_INIT_DATA: [i16; 10] = [
336- 30000, 26000, 21000, 15000, 8000, 0, -8000, -15000, -21000, -26000,
337-];
338 pub static PH_IMP_LOW_MR795: [i16; 40] = [243 pub static PH_IMP_LOW_MR795: [i16; 40] = [
339 26777, 801, 2505, -683, -1382, 582, 604, -1274, 3511, -5894, 4534, -499,244 26777, 801, 2505, -683, -1382, 582, 604, -1274, 3511, -5894, 4534, -499,
340 -1940, 3011, -5058, 5614, -1990, -1061, -1459, 4442, -700, -5335, 4609, 452,245 -1940, 3011, -5058, 5614, -1990, -1061, -1459, 4442, -700, -5335, 4609, 452,
@@ -1335,22 +1240,10 @@ pub static SQRT_L_TBL: [i16; 50] = [
1335 29537, 29819, 30099, 30377, 30652, 30924, 31194, 31462, 31727, 31991, 32252, 32511,1240 29537, 29819, 30099, 30377, 30652, 30924, 31194, 31462, 31727, 31991, 32252, 32511,
1336 32767, 32767,1241 32767, 32767,
1337 ];1242 ];
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-];
1346 pub static WMFDECBYTESPERFRAME: [i16; 16] = [1243 pub static WMFDECBYTESPERFRAME: [i16; 16] = [
1347 12, 13, 15, 17, 19, 20, 26, 31, 5, 6, 5, 5,1244 12, 13, 15, 17, 19, 20, 26, 31, 5, 6, 5, 5,
1348 0, 0, 0, 0,1245 0, 0, 0, 0,
1349 ];1246 ];
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-];
1354 pub static TABLE_GAIN_MR475: [i16; 1024] = [ // 4 cols1247 pub static TABLE_GAIN_MR475: [i16; 1024] = [ // 4 cols
1355 812, 128, 542, 140, 2873, 1135, 2266, 3402, 2067, 563, 12677, 647,1248 812, 128, 542, 140, 2873, 1135, 2266, 3402, 2067, 563, 12677, 647,
1356 4132, 1798, 5601, 5285, 7689, 374, 3735, 441, 10912, 2638, 11807, 2494,1249 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 @@
1 //! Bit reading (get_amr_wb_bits.cpp), MIME unsorting (mime_io.cpp) and decoder homing frame test (homing_amr_wb_dec.cpp).1 //! 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)]
3 2
4 use super::ops::*;3 use super::ops::*;
5 4
6-pub const BIT_0: i16 = -127;
7 pub const BIT_1: i16 = 127;5 pub const BIT_1: i16 = 127;
8 6
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;
17 pub const MODE_24K: i16 = 8;7 pub const MODE_24K: i16 = 8;
18 pub const MRDTX: i16 = 9;8 pub const MRDTX: i16 = 9;
19 pub const MRSID: i16 = 9;9 pub const MRSID: i16 = 9;
@@ -66,14 +56,9 @@ pub fn Serial_parm_1bit(prms: &mut Prms) -> i16 {
66 56
67 // ---------------- mime_io.cpp ----------------57 // ---------------- mime_io.cpp ----------------
68 58
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-];
72 pub static unpacked_size: [i16; 16] = [59 pub static unpacked_size: [i16; 16] = [
73 132, 177, 253, 285, 317, 365, 397, 461, 477, 35, 0, 0, 0, 0, 0, 0,60 132, 177, 253, 285, 317, 365, 397, 461, 477, 35, 0, 0, 0, 0, 0, 0,
74 ];61 ];
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];
77 62
78 pub static sort_660: [i16; 132] = [63 pub static sort_660: [i16; 132] = [
79 0, 5, 6, 7, 61, 84, 107, 130, 62, 85, 8, 4, 37, 38, 39, 40, 58, 81, 104, 127, 60, 83, 106, 129,64 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] = [
247 /// RX_State of mime_io.232 /// RX_State of mime_io.
248 #[derive(Clone, Copy, Default)]233 #[derive(Clone, Copy, Default)]
249 pub struct RxState {234 pub struct RxState {
250- pub prev_ft: i16,
251 pub prev_mode: i16,235 pub prev_mode: i16,
252 }236 }
253 237
@@ -268,6 +252,7 @@ fn sorting_table(mode: i16) -> Option<&'static [i16]> {
268 }252 }
269 253
270 /// Port of `mime_unsorting`. `mode` must be 0..=15.254 /// Port of `mime_unsorting`. `mode` must be 0..=15.
255+#[allow(unused_assignments)]
271 pub fn mime_unsorting(256 pub fn mime_unsorting(
272 unsorted_bits: &[u8],257 unsorted_bits: &[u8],
273 sorted_bits_into_int16: &mut [i16],258 sorted_bits_into_int16: &mut [i16],
@@ -400,6 +385,7 @@ fn dhf_table(mode: i32) -> &'static [i16] {
400 }385 }
401 386
402 /// Port of `dhf_test`.387 /// Port of `dhf_test`.
388+#[allow(unused_assignments)]
403 pub fn dhf_test(input_frame: &[i16], mode: i32, nparms: i16) -> i16 {389 pub fn dhf_test(input_frame: &[i16], mode: i32, nparms: i16) -> i16 {
404 let dhf = dhf_table(mode);390 let dhf = dhf_table(mode);
405 let mut param = [0i16; DHF_PARMS_MAX + 1];391 let mut param = [0i16; DHF_PARMS_MAX + 1];
@@ -453,8 +439,8 @@ pub fn dhf_test(input_frame: &[i16], mode: i32, nparms: i16) -> i16 {
453 let mut tmp: i16 = 0x7fff;439 let mut tmp: i16 = 0x7fff;
454 tmp >>= shift;440 tmp >>= shift;
455 tmp = shl_int16(tmp, shift);441 tmp = shl_int16(tmp, shift);
456- tmp = dhf[i] & tmp;442+ tmp &= dhf[i];
457- tmp = param[i] ^ tmp;443+ tmp ^= param[i];
458 j |= tmp;444 j |= tmp;
459 } else {445 } else {
460 j = 1;446 j = 1;
crates/ec-amr/src/wb/core.rsmodified+1 -0
@@ -115,6 +115,7 @@ impl DecoderState {
115 115
116 /// `pvDecoder_AmrWb`: decode one frame of parameters (`prms`, one bit per i16 in116 /// `pvDecoder_AmrWb`: decode one frame of parameters (`prms`, one bit per i16 in
117 /// the decoder's serial order) into 320 samples.117 /// the decoder's serial order) into 320 samples.
118+#[allow(unused_assignments)]
118 pub fn decode_frame(119 pub fn decode_frame(
119 mode: i16,120 mode: i16,
120 prms_buf: &[i16],121 prms_buf: &[i16],
crates/ec-amr/src/wb/dtx.rsmodified+6 -173
@@ -1,31 +1,22 @@
1 //! AMR-WB decoder DTX / comfort noise (port of dtx_decoder_amr_wb.cpp and dtx.h).1 //! AMR-WB decoder DTX / comfort noise (port of dtx_decoder_amr_wb.cpp and dtx.h).
2-#![allow(dead_code)]
3 2
4 use super::bits::{Prms, Serial_parm, Serial_parm_1bit};3 use super::bits::{Prms, Serial_parm, Serial_parm_1bit};
5 use super::ops::*;4 use super::ops::*;
6 5
7 pub const DTX_MAX_EMPTY_THRESH: i16 = 50;6 pub const DTX_MAX_EMPTY_THRESH: i16 = 50;
8 pub const DTX_HIST_SIZE: usize = 8;7 pub const DTX_HIST_SIZE: usize = 8;
9-pub const DTX_HIST_SIZE_MIN_ONE: usize = 7;
10 pub const DTX_ELAPSED_FRAMES_THRESH: i16 = 24 + 7 - 1;8 pub const DTX_ELAPSED_FRAMES_THRESH: i16 = 24 + 7 - 1;
11 pub const DTX_HANG_CONST: i16 = 7;9 pub const DTX_HANG_CONST: i16 = 7;
12-pub const INV_MED_THRESH: i16 = 14564;
13 pub const ISF_GAP: i16 = 128;10 pub const ISF_GAP: i16 = 128;
14 pub const ISF_DITH_GAP: i16 = 448;11 pub const ISF_DITH_GAP: i16 = 448;
15 pub const ISF_FACTOR_LOW: i16 = 256;12 pub const ISF_FACTOR_LOW: i16 = 256;
16 pub const ISF_FACTOR_STEP: i16 = 2;13 pub const ISF_FACTOR_STEP: i16 = 2;
17-pub const GAIN_THR: i16 = 180;
18 pub const GAIN_FACTOR: i16 = 75;14 pub const GAIN_FACTOR: i16 = 75;
19 15
20 pub const SPEECH: i16 = 0;16 pub const SPEECH: i16 = 0;
21 pub const DTX: i16 = 1;17 pub const DTX: i16 = 1;
22 pub const DTX_MUTE: i16 = 2;18 pub const DTX_MUTE: i16 = 2;
23 19
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-
29 pub const RX_SPEECH_GOOD: i16 = 0;20 pub const RX_SPEECH_GOOD: i16 = 0;
30 pub const RX_SPEECH_PROBABLY_DEGRADED: i16 = 1;21 pub const RX_SPEECH_PROBABLY_DEGRADED: i16 = 1;
31 pub const RX_SPEECH_LOST: i16 = 2;22 pub const RX_SPEECH_LOST: i16 = 2;
@@ -35,26 +26,12 @@ pub const RX_SID_UPDATE: i16 = 5;
35 pub const RX_SID_BAD: i16 = 6;26 pub const RX_SID_BAD: i16 = 6;
36 pub const RX_NO_DATA: i16 = 7;27 pub const RX_NO_DATA: i16 = 7;
37 28
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-
51 #[derive(Clone)]29 #[derive(Clone)]
52 pub struct DtxDecState {30 pub struct DtxDecState {
53 pub since_last_sid: i16,31 pub since_last_sid: i16,
54 pub true_sid_period_inv: i16,32 pub true_sid_period_inv: i16,
55 pub log_en: i16,33 pub log_en: i16,
56 pub old_log_en: i16,34 pub old_log_en: i16,
57- pub level: i16,
58 pub isf: [i16; M],35 pub isf: [i16; M],
59 pub isf_old: [i16; M],36 pub isf_old: [i16; M],
60 pub cng_seed: i16,37 pub cng_seed: i16,
@@ -79,7 +56,6 @@ impl Default for DtxDecState {
79 true_sid_period_inv: 0,56 true_sid_period_inv: 0,
80 log_en: 0,57 log_en: 0,
81 old_log_en: 0,58 old_log_en: 0,
82- level: 0,
83 isf: [0; M],59 isf: [0; M],
84 isf_old: [0; M],60 isf_old: [0; M],
85 cng_seed: 0,61 cng_seed: 0,
@@ -192,7 +168,7 @@ pub fn dtx_dec_amr_wb(
192 ind[2] = Serial_parm(6, prms);168 ind[2] = Serial_parm(6, prms);
193 ind[3] = Serial_parm(5, prms);169 ind[3] = Serial_parm(5, prms);
194 ind[4] = Serial_parm(5, prms);170 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);
196 let log_en_index = Serial_parm(6, prms);172 let log_en_index = Serial_parm(6, prms);
197 st.CN_dith = Serial_parm_1bit(prms);173 st.CN_dith = Serial_parm_1bit(prms);
198 st.log_en = shl_int16(log_en_index, 15 - 6);174 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: &[
305 /// Port of `rx_amr_wb_dtx_handler`.281 /// Port of `rx_amr_wb_dtx_handler`.
306 pub fn rx_amr_wb_dtx_handler(st: &mut DtxDecState, frame_type: i16) -> i16 {282 pub fn rx_amr_wb_dtx_handler(st: &mut DtxDecState, frame_type: i16) -> i16 {
307 let mut new_state: i16;283 let mut new_state: i16;
308- let enc_state: i16;284+
309 285
310 if frame_type == RX_SID_FIRST286 if frame_type == RX_SID_FIRST
311 || frame_type == RX_SID_UPDATE287 || frame_type == RX_SID_UPDATE
@@ -339,15 +315,15 @@ pub fn rx_amr_wb_dtx_handler(st: &mut DtxDecState, frame_type: i16) -> i16 {
339 st.decAnaElapsedCount = add_int16(st.decAnaElapsedCount, 1);315 st.decAnaElapsedCount = add_int16(st.decAnaElapsedCount, 1);
340 st.dtxHangoverAdded = 0;316 st.dtxHangoverAdded = 0;
341 317
342- if frame_type == RX_SID_FIRST318+ let enc_state: i16 = if frame_type == RX_SID_FIRST
343 || frame_type == RX_SID_UPDATE319 || frame_type == RX_SID_UPDATE
344 || frame_type == RX_SID_BAD320 || frame_type == RX_SID_BAD
345 || frame_type == RX_NO_DATA321 || frame_type == RX_NO_DATA
346 {322 {
347- enc_state = DTX;323+ DTX
348 } else {324 } else {
349- enc_state = SPEECH;325+ SPEECH
350- }326+ };
351 327
352 if enc_state == SPEECH {328 if enc_state == SPEECH {
353 st.dtxHangoverCount = DTX_HANG_CONST;329 st.dtxHangoverCount = DTX_HANG_CONST;
@@ -377,149 +353,6 @@ pub fn rx_amr_wb_dtx_handler(st: &mut DtxDecState, frame_type: i16) -> i16 {
377 new_state353 new_state
378 }354 }
379 355
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-
523 /// Port of `CN_dithering`.356 /// Port of `CN_dithering`.
524 pub fn CN_dithering(isf: &mut [i16], l_log_en_int: &mut i32, dither_seed: &mut i16) {357 pub fn CN_dithering(isf: &mut [i16], l_log_en_int: &mut i32, dither_seed: &mut i16) {
525 use super::exc::noise_gen_amrwb;358 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) {
478 temp = sig_in[i] >> 2;478 temp = sig_in[i] >> 2;
479 s = mac_16by16_to_int32(s, temp, temp);479 s = mac_16by16_to_int32(s, temp, temp);
480 }480 }
481- let g0: i16;481+
482- if s == 0 {482+ let g0: i16 = if s == 0 {
483- g0 = 0;483+ 0
484 } else {484 } else {
485 let i = normalize_amr_wb(s);485 let i = normalize_amr_wb(s);
486 let gain_in = amr_wb_round(s.wrapping_shl(i as u32));486 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) {
489 s2 = shl_int32(s2, 7);489 s2 = shl_int32(s2, 7);
490 s2 = shr_int32(s2, exp);490 s2 = shr_int32(s2, exp);
491 s2 = super::math::one_ov_sqrt(s2);491 s2 = super::math::one_ov_sqrt(s2);
492- g0 = amr_wb_round(shl_int32(s2, 9));492+ amr_wb_round(shl_int32(s2, 9))
493- }493+ };
494 for i in 0..l {494 for i in 0..l {
495 sig_out[i] = super::math::extract_h(shl_int32(fxp_mul_16by16(sig_out[i], g0), 3));495 sig_out[i] = super::math::extract_h(shl_int32(fxp_mul_16by16(sig_out[i], g0), 3));
496 }496 }
@@ -513,7 +513,6 @@ pub fn scale_signal(x: &mut [i16], lg: i16, exp: i16) {
513 }513 }
514 514
515 /// Ports `median5`. `x[c]` is the C `x[0]` (reads `x[c-2..=c+2]`).515 /// Ports `median5`. `x[c]` is the C `x[0]` (reads `x[c-2..=c+2]`).
516-#[allow(unused_assignments)]
517 pub fn median5(x: &[i16], c: usize) -> i16 {516 pub fn median5(x: &[i16], c: usize) -> i16 {
518 let mut x1 = x[c - 2];517 let mut x1 = x[c - 2];
519 let mut x2 = x[c - 1];518 let mut x2 = x[c - 1];
@@ -706,6 +705,7 @@ pub fn dec_gain2_amr_wb_init(mem: &mut [i16]) {
706 }705 }
707 706
708 /// Ports `dec_gain2_amr_wb`. `mem` has 23 words (see init).707 /// Ports `dec_gain2_amr_wb`. `mem` has 23 words (see init).
708+#[allow(unused_assignments)]
709 pub fn dec_gain2_amr_wb(709 pub fn dec_gain2_amr_wb(
710 index: i16,710 index: i16,
711 nbits: i16,711 nbits: i16,
crates/ec-amr/src/wb/math.rsmodified+0 -8
@@ -6,17 +6,9 @@ pub fn extract_h(x: i32) -> i16 {
6 (x >> 16) as i166 (x >> 16) as i16
7 }7 }
8 #[inline]8 #[inline]
9-pub fn extract_l(x: i32) -> i16 {
10- x as i16
11-}
12-#[inline]
13 pub fn l_deposit_h(x: i16) -> i32 {9 pub fn l_deposit_h(x: i16) -> i32 {
14 (x as i32).wrapping_shl(16)10 (x as i32).wrapping_shl(16)
15 }11 }
16-#[inline]
17-pub fn l_deposit_l(x: i16) -> i32 {
18- x as i32
19-}
20 12
21 /// Ports `mult_int16_r`.13 /// Ports `mult_int16_r`.
22 pub fn mult_int16_r(var1: i16, var2: i16) -> i16 {14 pub fn mult_int16_r(var1: i16, var2: i16) -> i16 {
crates/ec-amr/src/wb/mod.rsmodified+14 -33
@@ -1,23 +1,17 @@
1 //! AMR-WB (3GPP TS 26.173) fixed-point decoder.1 //! AMR-WB (3GPP TS 26.173) fixed-point decoder.
2-#![allow(2+#![allow(non_snake_case, non_upper_case_globals, clippy::if_same_then_else)]
3- clippy::all,3+#![allow(clippy::needless_range_loop, clippy::too_many_arguments, clippy::manual_memcpy, clippy::manual_clamp)]
4- clippy::pedantic,4+
5- dead_code,5+pub(crate) mod bits;
6- unused_assignments,6+pub(crate) mod core;
7- non_snake_case,7+pub(crate) mod dtx;
8- non_upper_case_globals8+pub(crate) mod exc;
9-)]9+pub(crate) mod exc_tab;
10-10+pub(crate) mod isf;
11-pub mod bits;11+pub(crate) mod isf_tab;
12-pub mod core;12+pub(crate) mod math;
13-pub mod dtx;13+pub(crate) mod ops;
14-pub mod exc;14+pub(crate) mod synth;
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;
21 15
22 use ec_core::error::{Error, Result};16 use ec_core::error::{Error, Result};
23 use ec_core::frame::{AudioFrame, ChannelLayout, Frame, SampleFormat};17 use ec_core::frame::{AudioFrame, ChannelLayout, Frame, SampleFormat};
@@ -34,16 +28,6 @@ use self::dtx::{RX_NO_DATA, RX_SPEECH_GOOD, RX_SPEECH_LOST};
34 /// Samples in one decoded AMR-WB frame (20 ms at 16 kHz).28 /// Samples in one decoded AMR-WB frame (20 ms at 16 kHz).
35 pub const FRAME_SAMPLES: usize = 320;29 pub const FRAME_SAMPLES: usize = 320;
36 30
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-
47 /// A fixed-point AMR-WB decoder (3GPP TS 26.173), bit-exact with the reference decoder's31 /// A fixed-point AMR-WB decoder (3GPP TS 26.173), bit-exact with the reference decoder's
48 /// 14-bit output. Packets are one or more frames, each a ToC byte followed by the speech bits32 /// 14-bit output. Packets are one or more frames, each a ToC byte followed by the speech bits
49 /// (the `sawb` sample layout and the `.awb` frame layout).33 /// (the `sawb` sample layout and the `.awb` frame layout).
@@ -78,7 +62,6 @@ impl AmrWbDecoder {
78 AmrWbDecoder {62 AmrWbDecoder {
79 st: DecoderState::new(),63 st: DecoderState::new(),
80 rx: RxState {64 rx: RxState {
81- prev_ft: RX_SPEECH_GOOD,
82 prev_mode: 0,65 prev_mode: 0,
83 },66 },
84 mode_old: 0,67 mode_old: 0,
@@ -101,7 +84,6 @@ impl AmrWbDecoder {
101 fn reset_state(&mut self) {84 fn reset_state(&mut self) {
102 self.st = DecoderState::new();85 self.st = DecoderState::new();
103 self.rx = RxState {86 self.rx = RxState {
104- prev_ft: RX_SPEECH_GOOD,
105 prev_mode: 0,87 prev_mode: 0,
106 };88 };
107 self.mode_old = 0;89 self.mode_old = 0;
@@ -117,8 +99,7 @@ impl AmrWbDecoder {
117 while at < data.len() {99 while at < data.len() {
118 let toc = data[at];100 let toc = data[at];
119 let ft = (toc >> 3) & 0x0F;101 let ft = (toc >> 3) & 0x0F;
120- let n = payload_len(ft)102+ let n = crate::container::wb_frame_size(ft)?;
121- .ok_or_else(|| Error::corrupt(format!("AMR-WB frame type {ft} is reserved")))?;
122 if at + 1 + n > data.len() {103 if at + 1 + n > data.len() {
123 return Err(Error::corrupt("AMR-WB frame is truncated"));104 return Err(Error::corrupt("AMR-WB frame is truncated"));
124 }105 }
crates/ec-amr/src/wb/ops.rsmodified+2 -15
@@ -1,10 +1,8 @@
1 //! ETSI-style saturating basic operators (port of the 3GPP TS 26.173 basic_op set).1 //! ETSI-style saturating basic operators (port of the 3GPP TS 26.173 basic_op set).
2-#![allow(dead_code)]
3 2
4 pub const MAX_16: i16 = 32767;3 pub const MAX_16: i16 = 32767;
5 pub const MIN_16: i16 = -32768;4 pub const MIN_16: i16 = -32768;
6 pub const MAX_32: i32 = 0x7fff_ffff;5 pub const MAX_32: i32 = 0x7fff_ffff;
7-pub const MIN_32: i32 = i32::MIN;
8 6
9 #[inline]7 #[inline]
10 pub fn sat16(x: i32) -> i16 {8 pub fn sat16(x: i32) -> i16 {
@@ -71,7 +69,7 @@ pub fn amr_wb_shl1_round(l: i32) -> i16 {
71 }69 }
72 #[inline]70 #[inline]
73 pub fn mul_32by16(hi: i16, lo: i16, n: i16) -> i32 {71 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)
75 }73 }
76 /// plain (non saturating) 16x16 -> 32 multiply-accumulate74 /// plain (non saturating) 16x16 -> 32 multiply-accumulate
77 #[inline]75 #[inline]
@@ -97,7 +95,7 @@ pub fn shl_int16(v: i16, s: i16) -> i16 {
97 let s = (s & 0xf) as u32;95 let s = (s & 0xf) as u32;
98 let out = ((v as i32) << s) as i16;96 let out = ((v as i32) << s) as i16;
99 if ((out as i32) >> s) != v as i32 {97 if ((out as i32) >> s) != v as i32 {
100- ((v >> 15) ^ MAX_16) as i1698+ (v >> 15) ^ MAX_16
101 } else {99 } else {
102 out100 out
103 }101 }
@@ -158,10 +156,6 @@ pub fn normalize_amr_wb(x: i32) -> i16 {
158 i as i16156 i as i16
159 }157 }
160 #[inline]158 #[inline]
161-pub fn norm_l(x: i32) -> i16 {
162- normalize_amr_wb(x)
163-}
164-#[inline]
165 pub fn norm_s(x: i16) -> i16 {159 pub fn norm_s(x: i16) -> i16 {
166 normalize_amr_wb(x as i32) - 16160 normalize_amr_wb(x as i32) - 16
167 }161 }
@@ -175,7 +169,6 @@ pub const M: usize = 16;
175 pub const M16K: usize = 20;169 pub const M16K: usize = 20;
176 pub const L_FILT16K: usize = 15;170 pub const L_FILT16K: usize = 15;
177 pub const L_FILT: usize = 12;171 pub const L_FILT: usize = 12;
178-pub const GP_CLIP: i16 = 15565;
179 pub const PIT_SHARP: i16 = 27853;172 pub const PIT_SHARP: i16 = 27853;
180 pub const PIT_MIN: i16 = 34;173 pub const PIT_MIN: i16 = 34;
181 pub const PIT_FR2: i16 = 128;174 pub const PIT_FR2: i16 = 128;
@@ -184,14 +177,10 @@ pub const PIT_FR1_8B: i16 = 92;
184 pub const PIT_MAX: i16 = 231;177 pub const PIT_MAX: i16 = 231;
185 pub const L_INTERPOL: usize = 17;178 pub const L_INTERPOL: usize = 17;
186 pub const PREEMPH_FAC: i16 = 22282;179 pub const PREEMPH_FAC: i16 = 22282;
187-pub const GAMMA1: i16 = 30147;
188-pub const TILT_FAC: i16 = 22282;
189 pub const Q_MAX: i16 = 8;180 pub const Q_MAX: i16 = 8;
190 pub const RANDOM_INITSEED: i16 = 21845;181 pub const RANDOM_INITSEED: i16 = 21845;
191 pub const L_MEANBUF: usize = 3;182 pub const L_MEANBUF: usize = 3;
192-pub const ONE_PER_MEANBUF: i16 = 10923;
193 pub const EHF_MASK: i16 = 0x0008;183 pub const EHF_MASK: i16 = 0x0008;
194-pub const AMR_WB_PCM_FRAME: usize = 320;
195 pub const NBBITS_7K: i16 = 132;184 pub const NBBITS_7K: i16 = 132;
196 pub const NBBITS_9K: i16 = 177;185 pub const NBBITS_9K: i16 = 177;
197 pub const NBBITS_12K: i16 = 253;186 pub const NBBITS_12K: i16 = 253;
@@ -199,7 +188,5 @@ pub const NBBITS_14K: i16 = 285;
199 pub const NBBITS_16K: i16 = 317;188 pub const NBBITS_16K: i16 = 317;
200 pub const NBBITS_18K: i16 = 365;189 pub const NBBITS_18K: i16 = 365;
201 pub const NBBITS_20K: i16 = 397;190 pub const NBBITS_20K: i16 = 397;
202-pub const NBBITS_23K: i16 = 461;
203 pub const NBBITS_24K: i16 = 477;191 pub const NBBITS_24K: i16 = 477;
204-pub const NBBITS_SID: i16 = 35;
205 pub const AMR_WB_COMPRESSED: [i16; 10] = [132, 177, 253, 285, 317, 365, 397, 461, 477, 35];192 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 @@
1 //! AMR-WB synthesis stage: ports of wb_syn_filt.cpp, synthesis_amr_wb.cpp,1 //! AMR-WB synthesis stage: ports of wb_syn_filt.cpp, synthesis_amr_wb.cpp,
2 //! oversamp_12k8_to_16k.cpp, highpass_50hz_at_12k8.cpp, highpass_400hz_at_12k8.cpp,2 //! oversamp_12k8_to_16k.cpp, highpass_50hz_at_12k8.cpp, highpass_400hz_at_12k8.cpp,
3 //! band_pass_6k_7k.cpp, low_pass_filt_7k.cpp, deemphasis_32.cpp, isf_extrapolation.cpp.3 //! band_pass_6k_7k.cpp, low_pass_filt_7k.cpp, deemphasis_32.cpp, isf_extrapolation.cpp.
4-#![allow(dead_code)]
5 4
6 use super::ops::*;5 use super::ops::*;
7 6
8 const L_FIR_BP: usize = 30;7 const L_FIR_BP: usize = 30;
9 const L_FIR_LP: usize = 30;8 const L_FIR_LP: usize = 30;
10-const L_FILT16K_: usize = 15;
11 const SPEECH: i16 = 0;9 const SPEECH: i16 = 0;
12 10
13 pub static HP_GAIN: [i16; 16] = [11 pub static HP_GAIN: [i16; 16] = [