| 1 | #![allow( |
| 2 | clippy::needless_range_loop, |
| 3 | clippy::too_many_arguments, |
| 4 | clippy::manual_memcpy, |
| 5 | clippy::explicit_counter_loop, |
| 6 | clippy::excessive_precision, |
| 7 | clippy::approx_constant |
| 8 | )] |
| 9 | |
| 10 | pub(crate) mod bands; |
| 11 | pub(crate) mod enc; |
| 12 | pub(crate) mod enc_an; |
| 13 | pub(crate) mod fft; |
| 14 | pub(crate) mod pitch; |
| 15 | pub(crate) mod quant_bands; |
| 16 | pub(crate) mod tables; |
| 17 | pub(crate) mod vq; |
| 18 | |
| 19 | pub(crate) use crate::celt::{BITRES, E_BANDS, LOG_N, NB_BANDS}; |
| 20 | |
| 21 | pub(crate) const OVERLAP: usize = 120; |
| 22 | pub(crate) const COMBFILTER_MAXPERIOD: usize = 1024; |
| 23 | pub(crate) const COMBFILTER_MINPERIOD: usize = 15; |
| 24 | pub(crate) const SHORT_MDCT: usize = 120; |
| 25 | pub(crate) const MAX_LM: usize = 3; |
| 26 | pub(crate) const PI: f64 = std::f64::consts::PI; |
| 27 | pub(crate) const EPSILON: f32 = 1e-15; |
| 28 | |
| 29 | pub(crate) fn celt_sqrt(x: f32) -> f32 { |
| 30 | (x as f64).sqrt() as f32 |
| 31 | } |
| 32 | |
| 33 | pub(crate) fn celt_rsqrt(x: f32) -> f32 { |
| 34 | 1.0 / celt_sqrt(x) |
| 35 | } |
| 36 | |
| 37 | pub(crate) fn celt_rcp(x: f32) -> f32 { |
| 38 | 1.0 / x |
| 39 | } |
| 40 | |
| 41 | pub(crate) fn celt_log2(x: f32) -> f32 { |
| 42 | (1.442695040888963387f64 * (x as f64).ln()) as f32 |
| 43 | } |
| 44 | |
| 45 | pub(crate) fn celt_exp2(x: f32) -> f32 { |
| 46 | (0.6931471805599453094f64 * x as f64).exp() as f32 |
| 47 | } |
| 48 | |
| 49 | pub(crate) fn celt_cos_norm(x: f32) -> f32 { |
| 50 | ((0.5f32 as f64 * PI) * x as f64).cos() as f32 |
| 51 | } |
| 52 | |
| 53 | pub(crate) fn celt_atan_norm(x: f32) -> f32 { |
| 54 | const ATAN2_2_OVER_PI: f32 = 0.636619772367581; |
| 55 | const A03: f32 = -3.3331659436225891113281250000e-01; |
| 56 | const A05: f32 = 1.99627041816711425781250000000e-01; |
| 57 | const A07: f32 = -1.3976582884788513183593750000e-01; |
| 58 | const A09: f32 = 9.79423448443412780761718750000e-02; |
| 59 | const A11: f32 = -5.7773590087890625000000000000e-02; |
| 60 | const A13: f32 = 2.30401363223791122436523437500e-02; |
| 61 | const A15: f32 = -4.3554059229791164398193359375e-03; |
| 62 | let x_sq = x * x; |
| 63 | ATAN2_2_OVER_PI |
| 64 | * (x + x |
| 65 | * x_sq |
| 66 | * (A03 |
| 67 | + x_sq |
| 68 | * (A05 |
| 69 | + x_sq * (A07 + x_sq * (A09 + x_sq * (A11 + x_sq * (A13 + x_sq * A15))))))) |
| 70 | } |
| 71 | |
| 72 | pub(crate) fn celt_atan2p_norm(y: f32, x: f32) -> f32 { |
| 73 | if x * x + y * y < 1e-18 { |
| 74 | return 0.0; |
| 75 | } |
| 76 | if y < x { |
| 77 | celt_atan_norm(y / x) |
| 78 | } else { |
| 79 | 1.0 - celt_atan_norm(x / y) |
| 80 | } |
| 81 | } |