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