use std::sync::LazyLock;
use crate::mdct::MdctLookup;
pub const BAND_ALLOCATION: [u8; 11 * 21] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 80, 75, 69, 63, 56, 49, 40,
34, 29, 20, 18, 10, 0, 0, 0, 0, 0, 0, 0, 0, 110, 100, 90, 84, 78, 71, 65, 58, 51, 45, 39, 32,
26, 20, 12, 0, 0, 0, 0, 0, 0, 118, 110, 103, 93, 86, 80, 75, 70, 65, 59, 53, 47, 40, 31, 23,
15, 4, 0, 0, 0, 0, 126, 119, 112, 104, 95, 89, 83, 78, 72, 66, 60, 54, 47, 39, 32, 25, 17, 12,
1, 0, 0, 134, 127, 120, 114, 103, 97, 91, 85, 78, 72, 66, 60, 54, 47, 41, 35, 29, 23, 16, 10,
1, 144, 137, 130, 124, 113, 107, 101, 95, 88, 82, 76, 70, 64, 57, 51, 45, 39, 33, 26, 15, 1,
152, 145, 138, 132, 123, 117, 111, 105, 98, 92, 86, 80, 74, 67, 61, 55, 49, 43, 36, 20, 1, 162,
155, 148, 142, 133, 127, 121, 115, 108, 102, 96, 90, 84, 77, 71, 65, 59, 53, 46, 30, 1, 172,
165, 158, 152, 143, 137, 131, 125, 118, 112, 106, 100, 94, 87, 81, 75, 69, 63, 56, 45, 20, 200,
200, 200, 200, 200, 200, 200, 198, 193, 188, 183, 178, 173, 168, 163, 158, 153, 148, 129, 104,
104,
];
pub const CACHE_INDEX50: [i16; 105] = [
-1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 41, 41, 41, 82, 82, 123, 164, 200, 222, 0, 0, 0, 0,
0, 0, 0, 0, 41, 41, 41, 41, 123, 123, 123, 164, 164, 240, 266, 283, 295, 41, 41, 41, 41, 41,
41, 41, 41, 123, 123, 123, 123, 240, 240, 240, 266, 266, 305, 318, 328, 336, 123, 123, 123,
123, 123, 123, 123, 123, 240, 240, 240, 240, 305, 305, 305, 318, 318, 343, 351, 358, 364, 240,
240, 240, 240, 240, 240, 240, 240, 305, 305, 305, 305, 343, 343, 343, 351, 351, 370, 376, 382,
387,
];
pub const CACHE_BITS50: [u8; 392] = [
40, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 40, 15, 23, 28, 31, 34, 36, 38, 39, 41, 42, 43, 44, 45, 46, 47,
47, 49, 50, 51, 52, 53, 54, 55, 55, 57, 58, 59, 60, 61, 62, 63, 63, 65, 66, 67, 68, 69, 70, 71,
71, 40, 20, 33, 41, 48, 53, 57, 61, 64, 66, 69, 71, 73, 75, 76, 78, 80, 82, 85, 87, 89, 91, 92,
94, 96, 98, 101, 103, 105, 107, 108, 110, 112, 114, 117, 119, 121, 123, 124, 126, 128, 40, 23,
39, 51, 60, 67, 73, 79, 83, 87, 91, 94, 97, 100, 102, 105, 107, 111, 115, 118, 121, 124, 126,
129, 131, 135, 139, 142, 145, 148, 150, 153, 155, 159, 163, 166, 169, 172, 174, 177, 179, 35,
28, 49, 65, 78, 89, 99, 107, 114, 120, 126, 132, 136, 141, 145, 149, 153, 159, 165, 171, 176,
180, 185, 189, 192, 199, 205, 211, 216, 220, 225, 229, 232, 239, 245, 251, 21, 33, 58, 79, 97,
112, 125, 137, 148, 157, 166, 174, 182, 189, 195, 201, 207, 217, 227, 235, 243, 251, 17, 35,
63, 86, 106, 123, 139, 152, 165, 177, 187, 197, 206, 214, 222, 230, 237, 250, 25, 31, 55, 75,
91, 105, 117, 128, 138, 146, 154, 161, 168, 174, 180, 185, 190, 200, 208, 215, 222, 229, 235,
240, 245, 255, 16, 36, 65, 89, 110, 128, 144, 159, 173, 185, 196, 207, 217, 226, 234, 242, 250,
11, 41, 74, 103, 128, 151, 172, 191, 209, 225, 241, 255, 9, 43, 79, 110, 138, 163, 186, 207,
227, 246, 12, 39, 71, 99, 123, 144, 164, 182, 198, 214, 228, 241, 253, 9, 44, 81, 113, 142,
168, 192, 214, 235, 255, 7, 49, 90, 127, 160, 191, 220, 247, 6, 51, 95, 134, 170, 203, 234, 7,
47, 87, 123, 155, 184, 212, 237, 6, 52, 97, 137, 174, 208, 240, 5, 57, 106, 151, 192, 231, 5,
59, 111, 158, 202, 243, 5, 55, 103, 147, 187, 224, 5, 60, 113, 161, 206, 248, 4, 65, 122, 175,
224, 4, 67, 127, 182, 234,
];
pub const CACHE_CAPS50: [u8; 168] = [
224, 224, 224, 224, 224, 224, 224, 224, 160, 160, 160, 160, 185, 185, 185, 178, 178, 168, 134,
61, 37, 224, 224, 224, 224, 224, 224, 224, 224, 240, 240, 240, 240, 207, 207, 207, 198, 198,
183, 144, 66, 40, 160, 160, 160, 160, 160, 160, 160, 160, 185, 185, 185, 185, 193, 193, 193,
183, 183, 172, 138, 64, 38, 240, 240, 240, 240, 240, 240, 240, 240, 207, 207, 207, 207, 204,
204, 204, 193, 193, 180, 143, 66, 40, 185, 185, 185, 185, 185, 185, 185, 185, 193, 193, 193,
193, 193, 193, 193, 183, 183, 172, 138, 65, 39, 207, 207, 207, 207, 207, 207, 207, 207, 204,
204, 204, 204, 201, 201, 201, 188, 188, 176, 141, 66, 40, 193, 193, 193, 193, 193, 193, 193,
193, 193, 193, 193, 193, 194, 194, 194, 184, 184, 173, 139, 65, 39, 204, 204, 204, 204, 204,
204, 204, 204, 201, 201, 201, 201, 198, 198, 198, 187, 187, 175, 140, 66, 40,
];
pub struct PulseCache {
pub size: usize,
pub index: &'static [i16],
pub bits: &'static [u8],
pub caps: &'static [u8],
}
pub struct CeltMode {
pub fs: i32,
pub overlap: usize,
pub nb_ebands: usize,
pub eff_ebands: usize,
pub preemph: [f32; 4],
pub e_bands: &'static [i16],
pub max_lm: usize,
pub nb_short_mdcts: usize,
pub short_mdct_size: usize,
pub nb_alloc_vectors: usize,
pub alloc_vectors: &'static [u8],
pub alloc_stride: usize,
pub log_n: &'static [i16],
pub window: &'static [f32],
pub mdct: MdctLookup,
pub cache: PulseCache,
pub e_means: &'static [f32],
}
pub const EBAND_5MS: [i16; 22] = [
0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 34, 40, 48, 60, 78, 100,
];
impl CeltMode {
pub fn new_48000_960_120() -> Self {
let short_mdct_size = 120;
let nb_short_mdcts = 8;
let max_lm = 3usize;
let mdct = MdctLookup::new(2 * short_mdct_size * nb_short_mdcts, max_lm);
Self {
fs: 48000,
overlap: 120,
nb_ebands: 21,
eff_ebands: 21,
preemph: [0.850_006_1, 0.100_006_1, 1.512_834_7, 0.661_010_7],
e_bands: &EBAND_5MS,
max_lm,
nb_short_mdcts,
short_mdct_size,
nb_alloc_vectors: 11,
alloc_vectors: &BAND_ALLOCATION,
alloc_stride: 21,
log_n: &LOG_N_400,
window: &WINDOW_120,
mdct,
cache: PulseCache {
size: 392,
index: &CACHE_INDEX50,
bits: &CACHE_BITS50,
caps: &CACHE_CAPS50,
},
e_means: &E_MEANS,
}
}
}
pub const E_MEANS: [f32; 25] = [
6.4375, 6.25, 5.75, 5.3125, 5.0625, 4.8125, 4.5, 4.375, 4.875, 4.6875, 4.5625, 4.4375, 4.875,
4.625, 4.3125, 4.5, 4.375, 4.625, 4.75, 4.4375, 3.75, 3.75, 3.75, 3.75, 3.75,
];
pub fn default_mode() -> &'static CeltMode {
&MODE_48000_960_120
}
static MODE_48000_960_120: LazyLock<CeltMode> = LazyLock::new(CeltMode::new_48000_960_120);
const LOG_N_400: [i16; 21] = [
0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 16, 16, 16, 21, 21, 24, 29, 34, 36,
];
const WINDOW_120: [f32; 120] = [
6.728_696_6e-05,
0.000_605_513_5,
0.001_681_597,
0.003_294_796_2,
0.005_443_994_3,
0.008_127_692,
0.011_344_001,
0.015_090_633,
0.019_364_886,
0.024_163_635,
0.029_483_315,
0.035_319_905,
0.041_668_91,
0.048_525_35,
0.055_883_718,
0.063_737_999,
0.072_081_62,
0.080_907_43,
0.090_207_7,
0.099_974_11,
0.110_197_69,
0.120_868_83,
0.131_977_29,
0.143_512_14,
0.155_461_77,
0.167_813_9,
0.180_555_5,
0.193_672_9,
0.207_151_71,
0.220_976_82,
0.235_132_43,
0.249_602_08,
0.264_368_6,
0.279_414_19,
0.294_720_4,
0.310_268_2,
0.326_037_88,
0.342_009_3,
0.358_161_77,
0.374_474_07,
0.390_924_62,
0.407_491_42,
0.424_152_15,
0.440_884_23,
0.457_664_84,
0.474_471_04,
0.491_279_78,
0.508_067_98,
0.524_812_61,
0.541_490_8,
0.558_079_7,
0.574_557,
0.590_900_5,
0.607_088_4,
0.623_099_5,
0.638_913_06,
0.654_508_96,
0.669_867_76,
0.684_970_8,
0.699_800_1,
0.714_338_7,
0.728_570_5,
0.742_480_43,
0.756_054_2,
0.769_278_95,
0.782_142_6,
0.794_634_3,
0.806_744_45,
0.818_464_6,
0.829_787_3,
0.840_706_7,
0.851_217_8,
0.861_317,
0.871_001_83,
0.880_271_11,
0.889_124_8,
0.897_564,
0.905_590_94,
0.913_209,
0.920_422_7,
0.927_237_4,
0.933_659_55,
0.939_696_56,
0.945_356_7,
0.950_649_1,
0.955_583_5,
0.960_170_7,
0.964_421_7,
0.968_348_5,
0.971_963_34,
0.975_279_06,
0.978_308_83,
0.981_066_16,
0.983_564_8,
0.985_818_7,
0.987_841_9,
0.989_648_6,
0.991_252_7,
0.992_668_5,
0.993_909_7,
0.994_990_04,
0.995_923,
0.996_721_6,
0.997_398_74,
0.997_966_67,
0.998_437_3,
0.998_822,
0.999_131_47,
0.999_376_06,
0.999_565_27,
0.999_708,
0.999_812_5,
0.999_886_13,
0.999_935_6,
0.999_967,
0.999_985_18,
0.999_994_6,
0.999_998_59,
0.999_999_8,
1.0,
];
pub const SPREAD_ICDF: [u8; 4] = [25, 23, 2, 0];
pub const TRIM_ICDF: [u8; 11] = [126, 124, 119, 109, 87, 41, 19, 9, 4, 2, 0];
pub const TAPSET_ICDF: [u8; 3] = [2, 1, 0];
pub const TF_SELECT_TABLE: [[i8; 8]; 4] = [
[0, -1, 0, -1, 0, -1, 0, -1],
[0, -1, 0, -2, 1, 0, 1, -1],
[0, -2, 0, -3, 2, 0, 1, -1],
[0, -2, 0, -3, 3, 0, 1, -1],
];