]> git.nihav.org Git - nihav.git/blame - nihav-vivo/src/codecs/siren.rs
add VivoActive (imperfect) format family support
[nihav.git] / nihav-vivo / src / codecs / siren.rs
CommitLineData
31cf33ac
KS
1use nihav_core::formats::SND_F32P_FORMAT;
2use nihav_core::frame::*;
3use nihav_core::codecs::*;
4use nihav_core::io::bitreader::*;
5use nihav_core::io::codebook::*;
6use nihav_codec_support::dsp::mdct::IMDCT;
7use nihav_codec_support::dsp::window::{generate_window, WindowType};
8use std::str::FromStr;
9
10const SAMPLES: usize = 320;
11const NUM_REGIONS: usize = 14;
12const REGION_SIZE: usize = 20;
13const NUM_DIFF_CB: usize = NUM_REGIONS - 1;
14
15struct PRNG {
16 dw: [u16; 4],
17}
18
19impl PRNG {
20 fn new() -> Self { Self{ dw: [1; 4] } }
21 fn get_dw(&mut self) -> u16 {
22 let mut ret = self.dw[0].wrapping_add(self.dw[3]);
23 if (ret & 0x8000) != 0 {
24 ret = ret.wrapping_add(1);
25 }
26
27 self.dw[0] = self.dw[1];
28 self.dw[1] = self.dw[2];
29 self.dw[2] = self.dw[3];
30 self.dw[3] = ret;
31
32 ret
33 }
34}
35
36struct SirenDecoder {
37 chmap: NAChannelMap,
38 ainfo: NAAudioInfo,
39 info: NACodecInfoRef,
40 diff_cb: Vec<Codebook<i8>>,
41 vec_cb: [Codebook<u16>; 7],
42 imdct: IMDCT,
43
44 coeffs: [f32; SAMPLES],
45 delay: [f32; SAMPLES],
46 synth_buf: [f32; SAMPLES * 2],
47 last_good_frame: [f32; SAMPLES],
48 window: [f32; SAMPLES],
49 quant_tab: [f32; 64],
50
51 pow_index: [i32; NUM_REGIONS],
52 region_quant: [f32; NUM_REGIONS],
53 power_cat: [usize; NUM_REGIONS],
54 cat_balance: [usize; 16],
55
56 rng: PRNG,
57}
58
59fn map_idx_diff(idx: usize) -> i8 { (idx as i8) - 12 }
60fn map_idx0(idx: usize) -> u16 { VEC_CB0_SYMS[idx] }
61fn map_idx1(idx: usize) -> u16 { VEC_CB1_SYMS[idx] }
62fn map_idx2(idx: usize) -> u16 { VEC_CB2_SYMS[idx] }
63fn map_idx3(idx: usize) -> u16 { VEC_CB3_SYMS[idx] }
64fn map_idx4(idx: usize) -> u16 { VEC_CB4_SYMS[idx] }
65fn map_idx5(idx: usize) -> u16 { VEC_CB5_SYMS[idx] }
66fn map_idx6(idx: usize) -> u16 { VEC_CB6_SYMS[idx] }
67impl SirenDecoder {
68 fn new() -> Self {
69 let mut diff_cb = Vec::with_capacity(NUM_DIFF_CB);
70 for i in 0..NUM_DIFF_CB {
71 let mut cr = TableCodebookDescReader::new(&DIFF_CODE_BITS[i], &DIFF_CODE_LENS[i], map_idx_diff);
72 let cb = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
73 diff_cb.push(cb);
74 }
75 let mut cr = TableCodebookDescReader::new(&VEC_CB0_BITS, &VEC_CB0_LENS, map_idx0);
76 let vec_cb0 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
77 let mut cr = TableCodebookDescReader::new(&VEC_CB1_BITS, &VEC_CB1_LENS, map_idx1);
78 let vec_cb1 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
79 let mut cr = TableCodebookDescReader::new(&VEC_CB2_BITS, &VEC_CB2_LENS, map_idx2);
80 let vec_cb2 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
81 let mut cr = TableCodebookDescReader::new(&VEC_CB3_BITS, &VEC_CB3_LENS, map_idx3);
82 let vec_cb3 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
83 let mut cr = TableCodebookDescReader::new(&VEC_CB4_BITS, &VEC_CB4_LENS, map_idx4);
84 let vec_cb4 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
85 let mut cr = TableCodebookDescReader::new(&VEC_CB5_BITS, &VEC_CB5_LENS, map_idx5);
86 let vec_cb5 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
87 let mut cr = TableCodebookDescReader::new(&VEC_CB6_BITS, &VEC_CB6_LENS, map_idx6);
88 let vec_cb6 = Codebook::new(&mut cr, CodebookMode::MSB).unwrap();
89 let vec_cb = [vec_cb0, vec_cb1, vec_cb2, vec_cb3, vec_cb4, vec_cb5, vec_cb6];
90
91 let mut window = [0.0f32; SAMPLES];
92 generate_window(WindowType::Sine, 1.0 / 320.0 / 8.0, SAMPLES, true, &mut window);
93
94 let mut quant_tab = [0.0; 64];
95 for i in 0..64 {
96 quant_tab[i] = 2.0f32.powf((((i as i32) - 24) as f32) / 2.0);
97 }
98
99 SirenDecoder {
100 chmap: NAChannelMap::from_str("C").unwrap(),
101 ainfo: NAAudioInfo::new(16000, 1, SND_F32P_FORMAT, SAMPLES),
102 info: NACodecInfo::new_dummy(),
103 diff_cb, vec_cb,
104
105 coeffs: [0.0; SAMPLES],
106 delay: [0.0; SAMPLES],
107 synth_buf: [0.0; SAMPLES * 2],
108 last_good_frame: [0.0; SAMPLES],
109 imdct: IMDCT::new(SAMPLES * 2, false),
110 window, quant_tab,
111
112 pow_index: [0; NUM_REGIONS],
113 region_quant: [0.0; NUM_REGIONS],
114 power_cat: [0; NUM_REGIONS],
115 cat_balance: [0; 16],
116
117 rng: PRNG::new(),
118 }
119 }
120 fn decode_envelope(&mut self, br: &mut BitReader) -> DecoderResult<()> {
121 self.pow_index[0] = (br.read(5)? as i32) - 7;
122
123 for i in 1..NUM_REGIONS {
124 let diff = br.read_cb(&self.diff_cb[i - 1])?;
125 self.pow_index[i] = (self.pow_index[i - 1] + i32::from(diff)).max(-24).min(39);
126 }
127 for i in 0..NUM_REGIONS {
128 self.region_quant[i] = self.quant_tab[(self.pow_index[i] + 24) as usize];
129 }
130
131 Ok(())
132 }
133 fn allocate_bits(&mut self, tot_bits: u32, rate_ctl: usize) -> DecoderResult<()> {
134 const CATEGORY_BITS: [u32; 8] = [ 52, 47, 43, 37, 29, 22, 16, 0 ];
135 const MAX_RC: usize = 15;
136
137 let mut offset = -32;
138 let mut delta = 32;
139 while delta > 0 {
140 let mut bitpool = 0;
141 for reg in 0..NUM_REGIONS {
142 let cat = ((delta + offset - self.pow_index[reg]) >> 1).max(0).min(7) as usize;
143 //self.power_cat[reg] = cat;
144 bitpool += CATEGORY_BITS[cat];
145 }
146 if bitpool >= tot_bits - 32 {
147 offset += delta;
148 }
149 delta >>= 1;
150 }
151
152 let mut bitpool = 0;
153 let mut max_rate_cat = [0; NUM_REGIONS];
154 let mut min_rate_cat = [0; NUM_REGIONS];
155 for reg in 0..NUM_REGIONS {
156 let cat = ((offset - self.pow_index[reg]) >> 1).max(0).min(7) as usize;
157 max_rate_cat[reg] = cat;
158 min_rate_cat[reg] = cat;
159 self.power_cat[reg] = cat;
160 bitpool += CATEGORY_BITS[cat];
161 }
162
163 let mut min_bitpool = bitpool;
164 let mut max_bitpool = bitpool;
165 let mut min_offset = MAX_RC + 1;
166 let mut max_offset = MAX_RC + 1;
167 let mut temp_cat = [0; 64];
168 for _ in 0..MAX_RC {
169 if min_bitpool + max_bitpool > tot_bits * 2 {
170 let mut max_value = -99;
171 let mut min_idx = 0;
172 for reg in (0..NUM_REGIONS).rev() {
173 if min_rate_cat[reg] >= 7 { continue; }
174 let val = offset - self.pow_index[reg] - 2 * (min_rate_cat[reg] as i32);
175 if max_value < val {
176 max_value = val;
177 min_idx = reg;
178 }
179 }
180 validate!(max_value != -99);
181 temp_cat[min_offset] = min_idx;
182 min_offset += 1;
183 min_bitpool = min_bitpool + CATEGORY_BITS[min_rate_cat[min_idx] + 1] - CATEGORY_BITS[min_rate_cat[min_idx]];
184 min_rate_cat[min_idx] += 1;
185 } else {
186 let mut min_value = 99;
187 let mut max_idx = 0;
188 for reg in 0..NUM_REGIONS {
189 if max_rate_cat[reg] == 0 { continue; }
190 let val = offset - self.pow_index[reg] - 2 * (max_rate_cat[reg] as i32);
191 if min_value > val {
192 min_value = val;
193 max_idx = reg;
194 }
195 }
196 validate!(min_value != 99);
197 max_offset -= 1;
198 temp_cat[max_offset] = max_idx;
199 max_bitpool = max_bitpool + CATEGORY_BITS[max_rate_cat[max_idx] - 1] - CATEGORY_BITS[max_rate_cat[max_idx]];
200 max_rate_cat[max_idx] -= 1;
201 }
202 }
203
204 self.power_cat = max_rate_cat;
205
206 for i in 0..MAX_RC {
207 self.cat_balance[i] = temp_cat[max_offset + i];
208 }
209
210 for cat in self.cat_balance.iter().take(rate_ctl) {
211 self.power_cat[*cat] += 1;
212 }
213 Ok(())
214 }
215 fn decode_coefficients(&mut self, br: &mut BitReader) -> DecoderResult<bool> {
216 const NUM_VECTORS: [u8; 8] = [ 10, 10, 10, 5, 5, 4, 4, 20 ];
217 const VECTOR_SIZE: [u8; 8] = [ 2, 2, 2, 4, 4, 5, 5, 1 ];
218 const INDEX_BITS: [u8; 8] = [ 4, 4, 3, 3, 2, 2, 1, 0 ];
219
220 let mut error = false;
221 self.coeffs = [0.0; SAMPLES];
222 for (reg, coeffs) in self.coeffs.chunks_exact_mut(REGION_SIZE).take(NUM_REGIONS).enumerate() {
223 let mut cat = self.power_cat[reg];
224 if cat < 7 {
225 let cb = &self.vec_cb[cat];
226 let num_vecs = NUM_VECTORS[cat] as usize;
227 let vec_len = VECTOR_SIZE[cat] as usize;
228
229 'vec_loop: for i in 0..num_vecs {
230 let ret = br.read_cb(cb);
231 if let Err(_) = ret {
232 error = true;
233 break 'vec_loop;
234 }
235 let mut idx = ret.ok().unwrap_or(0) as usize;
236 let mask = (1 << INDEX_BITS[cat]) - 1;
237 for j in 0..vec_len {
238 let coef = QUANT_LEVELS[cat][idx & mask] * self.region_quant[reg];
239 idx >>= INDEX_BITS[cat];
240 if coef != 0.0 {
241 if br.left() == 0 {
242 break 'vec_loop;
243 }
244 coeffs[i * vec_len + j] = if br.read_bool()? { -coef } else { coef };
245 }
246 }
247 }
248 if error {
249 cat = 7;
250 for i in reg..NUM_REGIONS {
251 self.power_cat[i] = 7;
252 }
253 }
254 }
255 let noise_val = match cat {
256 5 => {
257 let mut nz_count = 0;
258 for el in coeffs.iter() {
259 if *el != 0.0 {
260 if *el > 2.0 * self.region_quant[reg] {
261 nz_count += 4;
262 }
263 nz_count += 1;
264 }
265 }
266 if nz_count < REGION_SIZE {
267 self.region_quant[reg] * CAT5_NOISE_FACTOR[nz_count]
268 } else {
269 0.0
270 }
271 },
272 6 => {
273 let mut nz_count = 0;
274 for el in coeffs.iter() {
275 if *el != 0.0 {
276 nz_count += 1;
277 }
278 }
279 self.region_quant[reg] * CAT6_NOISE_FACTOR[nz_count]
280 },
281 7 => {
282 self.region_quant[reg] * 0.70711
283 },
284 _ => 0.0,
285 };
286 if cat >= 5 {
287 let mut dw1 = self.rng.get_dw();
288 let mut dw2 = self.rng.get_dw();
289 for pair in coeffs.chunks_exact_mut(2) {
290 if (cat == 7) || pair[0] == 0.0 {
291 pair[0] = if (dw1 & 1) != 0 { noise_val } else { -noise_val };
292 }
293 if (cat == 7) || pair[1] == 0.0 {
294 pair[1] = if (dw2 & 1) != 0 { noise_val } else { -noise_val };
295 }
296 dw1 >>= 1;
297 dw2 >>= 1;
298 }
299 }
300 }
301 Ok(error)
302 }
303}
304
305impl NADecoder for SirenDecoder {
306 fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
307 if let NACodecTypeInfo::Audio(_ainfo) = info.get_properties() {
308 self.info = info.replace_info(NACodecTypeInfo::Audio(self.ainfo));
309 Ok(())
310 } else {
311 Err(DecoderError::InvalidData)
312 }
313 }
314 fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
315 let info = pkt.get_stream().get_info();
316 validate!(info.get_properties().is_audio());
317 let src = pkt.get_buffer();
318
319 let mut br = BitReader::new(src.as_slice(), BitReaderMode::BE);
320 self.decode_envelope(&mut br)?;
321 let rate_ctl = br.read(4)? as usize;
322 self.allocate_bits(br.left() as u32, rate_ctl)?;
323 self.decode_coefficients(&mut br)?;
324
325 let mut bad_frame = false;
326 while br.left() > 0 {
327 bad_frame |= !br.read_bool().ok().unwrap_or(true);
328 }
329 for el in self.pow_index.iter() {
330 if *el > 33 {
331 bad_frame = true;
332 }
333 }
334
335 if bad_frame {
336 self.coeffs.copy_from_slice(&self.last_good_frame);
337 self.last_good_frame = [0.0; SAMPLES];
338 } else {
339 self.last_good_frame.copy_from_slice(&self.coeffs);
340 }
341
342 let abuf = alloc_audio_buffer(self.ainfo, SAMPLES, self.chmap.clone())?;
343 let mut adata = abuf.get_abuf_f32().unwrap();
344 let asamples = adata.get_data_mut().unwrap();
345
346 self.imdct.imdct_half(&self.coeffs, &mut self.synth_buf);
347 for i in (0..SAMPLES/2).step_by(2) {
348 let idx0 = i;
349 let idx1 = SAMPLES / 2 - 1 - i;
350 let idx2 = SAMPLES / 2 + i;
351 let idx3 = SAMPLES - 1 - i;
352 // samples are actually in reverse order
353 let c3 = self.synth_buf[idx0];
354 let c2 = self.synth_buf[idx1];
355 let c1 = self.synth_buf[idx2];
356 let c0 = self.synth_buf[idx3];
357
358 let d0 = self.delay[idx0];
359 let d1 = self.delay[idx1];
360
361 let w0 = self.window[idx0];
362 let w1 = self.window[idx1];
363 let w2 = self.window[idx2];
364 let w3 = self.window[idx3];
365
366 asamples[idx3] = c1 * w3 - d0 * w0;
367 asamples[idx2] = c0 * w2 - d1 * w1;
368 asamples[idx1] = d1 * w2 + c0 * w1;
369 asamples[idx0] = d0 * w3 + c1 * w0;
370
371 self.delay[idx0] = c2;
372 self.delay[idx1] = c3;
373 }
374
375 let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), abuf);
376 frm.set_keyframe(true);
377 Ok(frm.into_ref())
378 }
379 fn flush(&mut self) {
380 self.delay = [0.0; SAMPLES];
381 self.last_good_frame = [0.0; SAMPLES];
382 }
383}
384
385pub fn get_decoder() -> Box<dyn NADecoder + Send> {
386 Box::new(SirenDecoder::new())
387}
388
389#[cfg(test)]
390mod test {
391 use nihav_core::codecs::RegisteredDecoders;
392 use nihav_core::demuxers::RegisteredDemuxers;
393 use nihav_codec_support::test::dec_video::*;
394 use crate::vivo_register_all_codecs;
395 use crate::vivo_register_all_demuxers;
396 #[test]
397 fn test_siren() {
398 let mut dmx_reg = RegisteredDemuxers::new();
399 vivo_register_all_demuxers(&mut dmx_reg);
400 let mut dec_reg = RegisteredDecoders::new();
401 vivo_register_all_codecs(&mut dec_reg);
402
403 let file = "assets/Misc/favmovie.viv";
404 //let file = "assets/Misc/gr_al.viv";
405 test_decode_audio("vivo", file, None, None/*Some("siren")*/, &dmx_reg, &dec_reg);
406 }
407}
408
409const DIFF_CODE_BITS: [[u16; 24]; NUM_DIFF_CB] = [
410 [
411 0x0008, 0x0026, 0x0012, 0x000A, 0x0007, 0x0006, 0x0003, 0x0002,
412 0x0000, 0x0001, 0x0007, 0x0006, 0x0005, 0x0004, 0x000B, 0x004E,
413 0x009E, 0x013E, 0x04FE, 0x04FF, 0x09F8, 0x09F9, 0x09FA, 0x09FB
414 ], [
415 0x0024, 0x0008, 0x0003, 0x0005, 0x0000, 0x0001, 0x0007, 0x0006,
416 0x0004, 0x0003, 0x0002, 0x0005, 0x0003, 0x0004, 0x0005, 0x0013,
417 0x004A, 0x0096, 0x012E, 0x04BD, 0x04BE, 0x04BF, 0x0978, 0x0979
418 ], [
419 0x0A16, 0x0284, 0x00A0, 0x0029, 0x0005, 0x000B, 0x0007, 0x0005,
420 0x0004, 0x0001, 0x0000, 0x0006, 0x0004, 0x0007, 0x0003, 0x0006,
421 0x0004, 0x0015, 0x0051, 0x0143, 0x050A, 0x142F, 0x285C, 0x285D
422 ], [
423 0x0B7C, 0x016E, 0x00B5, 0x00B4, 0x002F, 0x002E, 0x001B, 0x000A,
424 0x0008, 0x0005, 0x0001, 0x0000, 0x0003, 0x0007, 0x0004, 0x0009,
425 0x000C, 0x001A, 0x002C, 0x00B6, 0x02DE, 0x0B7D, 0x0B7E, 0x0B7F
426 ], [
427 0x0F8E, 0x1F1F, 0x03E2, 0x00F9, 0x003F, 0x001A, 0x0013, 0x0012,
428 0x000E, 0x0008, 0x0006, 0x0001, 0x0000, 0x0002, 0x0005, 0x0007,
429 0x000C, 0x001E, 0x001B, 0x007D, 0x01F0, 0x07C6, 0x3E3C, 0x3E3D
430 ], [
431 0x0CB6, 0x065A, 0x0197, 0x00CE, 0x00CA, 0x0064, 0x001E, 0x000E,
432 0x0003, 0x0005, 0x0003, 0x0000, 0x0002, 0x0004, 0x0002, 0x000D,
433 0x0018, 0x001F, 0x0066, 0x00CF, 0x032C, 0x196F, 0x32DC, 0x32DD
434 ], [
435 0x0456, 0x08A8, 0x0457, 0x008B, 0x0023, 0x0009, 0x0003, 0x0014,
436 0x000B, 0x0004, 0x0002, 0x0001, 0x0003, 0x0003, 0x0001, 0x0000,
437 0x0015, 0x0005, 0x0010, 0x0044, 0x0114, 0x08A9, 0x08AA, 0x08AB
438 ], [
439 0x03F5, 0x03F6, 0x007F, 0x003E, 0x001D, 0x0006, 0x0004, 0x0010,
440 0x0000, 0x0001, 0x0003, 0x0002, 0x0003, 0x0001, 0x0005, 0x0009,
441 0x0011, 0x0005, 0x001C, 0x001E, 0x00FC, 0x03F7, 0x07E8, 0x07E9
442 ], [
443 0x017D, 0x017C, 0x0174, 0x00BF, 0x005E, 0x002C, 0x0010, 0x000A,
444 0x0007, 0x0003, 0x0001, 0x0000, 0x0002, 0x0006, 0x0009, 0x0011,
445 0x002D, 0x005C, 0x00BB, 0x02EA, 0x05D6, 0x0BAF, 0x175C, 0x175D
446 ], [
447 0x0BDC, 0x02F6, 0x00BC, 0x002D, 0x002B, 0x000A, 0x0004, 0x0003,
448 0x0006, 0x0004, 0x0002, 0x0000, 0x0003, 0x0007, 0x000B, 0x0014,
449 0x002A, 0x002C, 0x002E, 0x005F, 0x017A, 0x0BDD, 0x0BDE, 0x0BDF
450 ], [
451 0x02EF, 0x005C, 0x002D, 0x0014, 0x001A, 0x0004, 0x000C, 0x0007,
452 0x0004, 0x0000, 0x0004, 0x0001, 0x0003, 0x0005, 0x0005, 0x0003,
453 0x001B, 0x0015, 0x002C, 0x002F, 0x00BA, 0x0176, 0x05DC, 0x05DD
454 ], [
455 0xB204, 0x1641, 0x0B21, 0x0591, 0x0165, 0x002D, 0x0017, 0x0006,
456 0x000A, 0x0007, 0x0002, 0x0002, 0x0003, 0x0000, 0x0004, 0x0006,
457 0x0007, 0x0058, 0x00B3, 0x02C9, 0x2C80, 0xB205, 0xB206, 0xB207
458 ], [
459 0x09CF, 0x1398, 0x139A, 0x1399, 0x0138, 0x004F, 0x0026, 0x0024,
460 0x001E, 0x000E, 0x0006, 0x0000, 0x0002, 0x0001, 0x0003, 0x0005,
461 0x0008, 0x001F, 0x0025, 0x009D, 0x0272, 0x139B, 0x139C, 0x139D
462 ]
463];
464const DIFF_CODE_LENS: [[u8; 24]; 13/*27*/] = [
465 [ 4, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 4, 5, 7, 8, 9, 11, 11, 12, 12, 12, 12 ],
466 [ 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 7, 9, 11, 12, 13, 15, 15, 15, 16, 16 ],
467 [ 12, 10, 8, 6, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 4, 4, 5, 5, 7, 9, 11, 13, 14, 14 ],
468 [ 13, 10, 9, 9, 7, 7, 5, 5, 4, 3, 3, 3, 3, 3, 4, 4, 4, 5, 7, 9, 11, 13, 13, 13 ],
469 [ 12, 13, 10, 8, 6, 6, 5, 5, 4, 4, 3, 3, 3, 3, 3, 4, 5, 5, 6, 7, 9, 11, 14, 14 ],
470 [ 12, 11, 9, 8, 8, 7, 5, 4, 4, 3, 3, 3, 3, 3, 4, 4, 5, 5, 7, 8, 10, 13, 14, 14 ],
471 [ 15, 16, 15, 12, 10, 8, 6, 5, 4, 3, 3, 3, 2, 3, 4, 5, 5, 7, 9, 11, 13, 16, 16, 16 ],
472 [ 14, 14, 11, 10, 9, 7, 7, 5, 5, 4, 3, 3, 2, 3, 3, 4, 5, 7, 9, 9, 12, 14, 15, 15 ],
473 [ 9, 9, 9, 8, 7, 6, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 13 ],
474 [ 14, 12, 10, 8, 6, 6, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 6, 8, 8, 9, 11, 14, 14, 14 ],
475 [ 13, 10, 9, 8, 6, 6, 5, 4, 4, 4, 3, 3, 2, 3, 4, 5, 6, 8, 9, 9, 11, 12, 14, 14 ],
476 [ 16, 13, 12, 11, 9, 6, 5, 5, 4, 4, 4, 3, 2, 3, 3, 4, 5, 7, 8, 10, 14, 16, 16, 16 ],
477 [ 13, 14, 14, 14, 10, 8, 7, 7, 5, 4, 3, 3, 2, 3, 3, 4, 5, 5, 7, 9, 11, 14, 14, 14 ]
478];
479
480const VEC_CB0_BITS: [u16; 181] = [
481 0x0000, 0x0001, 0x0001, 0x0010, 0x0044, 0x0114, 0x0115, 0x008B,
482 0x0023, 0x0009, 0x0005, 0x0018, 0x0019, 0x000D, 0x0007, 0x0001,
483 0x0010, 0x0044, 0x0114, 0x0115, 0x022C, 0x045A, 0x045B, 0x0117,
484 0x0046, 0x0047, 0x0009, 0x0014, 0x0015, 0x0016, 0x002E, 0x005E,
485 0x005F, 0x000C, 0x001A, 0x0036, 0x0037, 0x000E, 0x001E, 0x003E,
486 0x00FC, 0x00FD, 0x01FC, 0x01FD, 0x01FE, 0x01FF, 0x0008, 0x0090,
487 0x0091, 0x0049, 0x004A, 0x004B, 0x004C, 0x009A, 0x0136, 0x09B8,
488 0x1372, 0x1373, 0x1374, 0x1375, 0x1376, 0x1377, 0x026F, 0x004E,
489 0x004F, 0x000A, 0x0016, 0x0017, 0x0018, 0x0032, 0x0033, 0x00D0,
490 0x01A2, 0x0346, 0x0347, 0x0069, 0x00D4, 0x00D5, 0x01AC, 0x06B4,
491 0x06B5, 0x06B6, 0x1ADC, 0x1ADD, 0x0D6F, 0x00D7, 0x0036, 0x0037,
492 0x000E, 0x0078, 0x0079, 0x003D, 0x003E, 0x003F, 0x0002, 0x0003,
493 0x0020, 0x0420, 0x0421, 0x0422, 0x0423, 0x0212, 0x0426, 0x0427,
494 0x0085, 0x010C, 0x010D, 0x010E, 0x010F, 0x0044, 0x0114, 0x022A,
495 0x022B, 0x0116, 0x08B8, 0x08B9, 0x045D, 0x1178, 0x1179, 0x08BD,
496 0x045F, 0x008C, 0x008D, 0x0047, 0x0012, 0x0098, 0x0099, 0x0134,
497 0x0135, 0x0136, 0x0137, 0x004E, 0x0278, 0x0279, 0x013D, 0x013E,
498 0x09F8, 0x27E4, 0x27E5, 0x13F3, 0x04FD, 0x027F, 0x000A, 0x0016,
499 0x005C, 0x00BA, 0x00BB, 0x005E, 0x02F8, 0x02F9, 0x017D, 0x00BF,
500 0x0018, 0x0032, 0x0033, 0x0034, 0x0350, 0x0351, 0x0352, 0x0353,
501 0x00D5, 0x006B, 0x006C, 0x00DA, 0x00DB, 0x006E, 0x01BC, 0x01BD,
502 0x00DF, 0x001C, 0x003A, 0x03B0, 0x0762, 0x0763, 0x01D9, 0x01DA,
503 0x01DB, 0x00EE, 0x00EF, 0x000F, 0x0001
504];
505const VEC_CB0_LENS: [u8; 181] = [
506 9, 9, 8, 11, 13, 15, 15, 14, 12, 10, 9, 11, 11, 10, 9, 6,
507 9, 11, 13, 13, 14, 15, 15, 13, 11, 11, 8, 9, 9, 9, 10, 11,
508 11, 8, 9, 10, 10, 8, 9, 10, 12, 12, 13, 13, 13, 13, 7, 11,
509 11, 10, 10, 10, 10, 11, 12, 15, 16, 16, 16, 16, 16, 16, 13, 10,
510 10, 7, 8, 8, 8, 9, 9, 11, 12, 13, 13, 10, 11, 11, 12, 14,
511 14, 14, 16, 16, 15, 11, 9, 9, 7, 10, 10, 9, 9, 9, 4, 4,
512 7, 12, 12, 12, 12, 11, 12, 12, 9, 10, 10, 10, 10, 8, 10, 11,
513 11, 10, 13, 13, 12, 14, 14, 13, 12, 9, 9, 8, 6, 9, 9, 10,
514 10, 10, 10, 8, 11, 11, 10, 10, 13, 15, 15, 14, 12, 11, 5, 6,
515 8, 9, 9, 8, 11, 11, 10, 9, 6, 7, 7, 7, 11, 11, 11, 11,
516 9, 8, 8, 9, 9, 8, 10, 10, 9, 6, 7, 11, 12, 12, 10, 10,
517 10, 9, 9, 5, 1
518];
519const VEC_CB0_SYMS: [u16; 181] = [
520 37, 51, 5, 102, 76, 139, 155, 169, 151, 41, 82, 103,
521 118, 100, 8, 32, 113, 134, 211, 182, 213, 214, 124, 183,
522 28, 29, 96, 52, 24, 67, 146, 193, 104, 35, 144, 176,
523 115, 21, 129, 70, 210, 45, 123, 197, 92, 61, 49, 74,
524 164, 56, 11, 177, 42, 192, 195, 109, 185, 156, 140, 216,
525 171, 201, 212, 27, 57, 19, 81, 50, 6, 145, 38, 12,
526 60, 122, 77, 131, 119, 59, 166, 153, 199, 93, 125, 141,
527 215, 13, 98, 53, 64, 101, 85, 9, 25, 114, 16, 1,
528 4, 137, 106, 150, 121, 149, 91, 167, 83, 116, 117, 71,
529 178, 112, 162, 179, 44, 147, 152, 198, 181, 154, 170, 138,
530 107, 10, 39, 97, 18, 40, 54, 86, 72, 88, 43, 22,
531 209, 90, 163, 133, 108, 186, 200, 184, 196, 165, 17, 33,
532 7, 26, 68, 36, 135, 208, 87, 99, 48, 20, 80, 34,
533 105, 180, 75, 194, 161, 66, 23, 160, 84, 128, 58, 148,
534 55, 3, 65, 120, 136, 168, 132, 73, 89, 69, 130, 2, 0
535];
536
537const VEC_CB1_BITS: [u16; 94] = [
538 0x0000, 0x0010, 0x0044, 0x0045, 0x0023, 0x0009, 0x0005, 0x000C,
539 0x000D, 0x000E, 0x001E, 0x001F, 0x0001, 0x0002, 0x000C, 0x0034,
540 0x01A8, 0x0352, 0x0353, 0x00D5, 0x006B, 0x0036, 0x006E, 0x006F,
541 0x01C0, 0x01C1, 0x00E1, 0x0071, 0x0072, 0x0073, 0x01D0, 0x03A2,
542 0x03A3, 0x00E9, 0x0075, 0x003B, 0x0078, 0x00F2, 0x01E6, 0x01E7,
543 0x003D, 0x001F, 0x0020, 0x0021, 0x0088, 0x0112, 0x0113, 0x0045,
544 0x0023, 0x0024, 0x0094, 0x0095, 0x004B, 0x004C, 0x009A, 0x0136,
545 0x04DC, 0x4DD0, 0x4DD1, 0x26E9, 0x1375, 0x09BB, 0x026F, 0x0027,
546 0x000A, 0x000B, 0x0018, 0x0064, 0x00CA, 0x0196, 0x0197, 0x0066,
547 0x0067, 0x001A, 0x001B, 0x000E, 0x0078, 0x0790, 0x0F22, 0x1E46,
548 0x1E47, 0x03C9, 0x01E5, 0x00F3, 0x007A, 0x00F6, 0x03DC, 0x07BA,
549 0x1EEC, 0x1EED, 0x0F77, 0x01EF, 0x001F, 0x0001
550];
551const VEC_CB1_LENS: [u8; 94] = [
552 5, 9, 11, 11, 10, 8, 7, 8, 8, 8, 9, 9, 4, 4, 6, 8,
553 11, 12, 12, 10, 9, 8, 9, 9, 11, 11, 10, 9, 9, 9, 11, 12,
554 12, 10, 9, 8, 9, 10, 11, 11, 8, 7, 7, 7, 9, 10, 10, 8,
555 7, 7, 9, 9, 8, 8, 9, 10, 12, 16, 16, 15, 14, 13, 11, 7,
556 5, 5, 6, 8, 9, 10, 10, 8, 8, 6, 6, 5, 8, 12, 13, 14,
557 14, 11, 10, 9, 8, 9, 11, 12, 14, 14, 13, 10, 6, 1
558];
559const VEC_CB1_SYMS: [u16; 94] = [
560 17, 23, 86, 131, 85, 80, 49, 21, 5, 36, 83, 112,
561 1, 16, 33, 51, 71, 87, 88, 70, 39, 81, 53, 113,
562 145, 117, 55, 68, 98, 7, 41, 118, 57, 100, 84, 66,
563 99, 115, 116, 132, 52, 64, 20, 65, 54, 25, 128, 37,
564 4, 35, 8, 69, 22, 6, 24, 144, 147, 120, 105, 150,
565 135, 148, 102, 50, 2, 32, 3, 82, 114, 9, 56, 97,
566 67, 19, 48, 18, 96, 103, 73, 104, 149, 146, 130, 40,
567 38, 129, 72, 133, 119, 89, 134, 101, 34, 0
568];
569
570const VEC_CB2_BITS: [u16; 48] = [
571 0x0000, 0x0008, 0x0024, 0x004A, 0x004B, 0x0013, 0x000A, 0x000B,
572 0x0018, 0x0019, 0x0034, 0x0035, 0x006C, 0x00DA, 0x01B6, 0x01B7,
573 0x0037, 0x001C, 0x001D, 0x001E, 0x003E, 0x003F, 0x0002, 0x0018,
574 0x0019, 0x000D, 0x0007, 0x0008, 0x0009, 0x000A, 0x0160, 0x0161,
575 0x0162, 0x0163, 0x0059, 0x00B4, 0x2D40, 0x5A82, 0x5A83, 0x16A1,
576 0x0B51, 0x05A9, 0x02D5, 0x016B, 0x005B, 0x0017, 0x0003, 0x0001
577];
578const VEC_CB2_LENS: [u8; 48] = [
579 4, 7, 9, 10, 10, 8, 7, 7, 8, 8, 9, 9, 10, 11, 12, 12,
580 9, 8, 8, 8, 9, 9, 4, 7, 7, 6, 5, 5, 5, 5, 10, 10,
581 10, 10, 8, 9, 15, 16, 16, 14, 13, 12, 11, 10, 8, 6, 3, 1
582];
583const VEC_CB2_SYMS: [u16; 48] = [
584 8, 25, 13, 42, 14, 12, 3, 24, 33, 4, 28, 41,
585 36, 22, 44, 30, 35, 32, 27, 20, 40, 21, 9, 19,
586 26, 18, 2, 10, 17, 16, 49, 29, 43, 50, 34, 6,
587 45, 53, 46, 52, 38, 51, 37, 48, 5, 11, 1, 0
588];
589
590const VEC_CB3_BITS: [u16; 520] = [
591 0x0000, 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086,
592 0x0087, 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E,
593 0x008F, 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096,
594 0x0097, 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E,
595 0x013E, 0x013F, 0x0005, 0x0003, 0x0002, 0x000C, 0x001A, 0x001B,
596 0x0038, 0x0039, 0x003A, 0x003B, 0x000F, 0x0008, 0x0090, 0x0091,
597 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099,
598 0x009A, 0x009B, 0x0027, 0x0005, 0x000C, 0x000D, 0x000E, 0x001E,
599 0x001F, 0x0040, 0x0041, 0x0042, 0x0860, 0x0861, 0x0862, 0x0863,
600 0x0864, 0x0865, 0x0866, 0x0867, 0x0868, 0x0869, 0x086A, 0x086B,
601 0x086C, 0x086D, 0x086E, 0x086F, 0x0870, 0x0871, 0x0872, 0x0873,
602 0x0874, 0x0875, 0x0876, 0x0877, 0x0878, 0x0879, 0x087A, 0x087B,
603 0x087C, 0x087D, 0x087E, 0x087F, 0x0880, 0x0881, 0x0882, 0x0883,
604 0x0884, 0x0885, 0x0886, 0x0887, 0x0888, 0x0889, 0x088A, 0x088B,
605 0x088C, 0x088D, 0x088E, 0x088F, 0x0890, 0x0891, 0x0892, 0x0893,
606 0x0894, 0x0895, 0x0896, 0x0897, 0x0898, 0x0899, 0x089A, 0x089B,
607 0x089C, 0x089D, 0x089E, 0x089F, 0x08A0, 0x08A1, 0x08A2, 0x08A3,
608 0x08A4, 0x08A5, 0x08A6, 0x08A7, 0x08A8, 0x08A9, 0x08AA, 0x08AB,
609 0x08AC, 0x08AD, 0x08AE, 0x08AF, 0x08B0, 0x08B1, 0x08B2, 0x08B3,
610 0x08B4, 0x08B5, 0x08B6, 0x08B7, 0x08B8, 0x08B9, 0x08BA, 0x08BB,
611 0x08BC, 0x08BD, 0x08BE, 0x08BF, 0x08C0, 0x08C1, 0x08C2, 0x08C3,
612 0x08C4, 0x08C5, 0x08C6, 0x08C7, 0x08C8, 0x08C9, 0x08CA, 0x08CB,
613 0x08CC, 0x08CD, 0x08CE, 0x08CF, 0x08D0, 0x08D1, 0x08D2, 0x08D3,
614 0x08D4, 0x08D5, 0x08D6, 0x08D7, 0x08D8, 0x08D9, 0x08DA, 0x08DB,
615 0x08DC, 0x08DD, 0x08DE, 0x08DF, 0x08E0, 0x08E1, 0x08E2, 0x08E3,
616 0x08E4, 0x08E5, 0x08E6, 0x08E7, 0x08E8, 0x08E9, 0x08EA, 0x08EB,
617 0x08EC, 0x08ED, 0x08EE, 0x08EF, 0x08F0, 0x08F1, 0x08F2, 0x08F3,
618 0x08F4, 0x08F5, 0x08F6, 0x08F7, 0x08F8, 0x08F9, 0x08FA, 0x08FB,
619 0x08FC, 0x08FD, 0x08FE, 0x08FF, 0x0009, 0x0A00, 0x0A01, 0x0A02,
620 0x0A03, 0x0A04, 0x0A05, 0x0A06, 0x0A07, 0x0A08, 0x0A09, 0x0A0A,
621 0x0A0B, 0x0A0C, 0x0A0D, 0x0A0E, 0x0A0F, 0x0A10, 0x0A11, 0x0A12,
622 0x0A13, 0x0A14, 0x0A15, 0x0A16, 0x0A17, 0x0A18, 0x0A19, 0x0A1A,
623 0x0A1B, 0x0A1C, 0x0A1D, 0x0A1E, 0x0A1F, 0x0A20, 0x0A21, 0x0A22,
624 0x0A23, 0x0A24, 0x0A25, 0x0A26, 0x0A27, 0x0A28, 0x0A29, 0x0A2A,
625 0x0A2B, 0x0A2C, 0x0A2D, 0x0A2E, 0x0A2F, 0x00A3, 0x0029, 0x002A,
626 0x0056, 0x0057, 0x000B, 0x0003, 0x0004, 0x0005, 0x0030, 0x0062,
627 0x18C0, 0x18C1, 0x18C2, 0x18C3, 0x18C4, 0x18C5, 0x18C6, 0x18C7,
628 0x0319, 0x018D, 0x00C7, 0x0032, 0x0198, 0x0199, 0x019A, 0x019B,
629 0x0067, 0x001A, 0x0360, 0x0361, 0x0362, 0x0363, 0x0364, 0x0365,
630 0x0366, 0x0367, 0x0368, 0x0369, 0x036A, 0x036B, 0x00DB, 0x006E,
631 0x006F, 0x001C, 0x00E8, 0x00E9, 0x0075, 0x0076, 0x0077, 0x0780,
632 0x0781, 0x0782, 0x0783, 0x0784, 0x0785, 0x0786, 0x0787, 0x0788,
633 0x0789, 0x078A, 0x078B, 0x078C, 0x078D, 0x078E, 0x078F, 0x0079,
634 0x003D, 0x007C, 0x07D0, 0x07D1, 0x07D2, 0x07D3, 0x01F5, 0x00FB,
635 0x00FC, 0x00FD, 0x00FE, 0x01FE, 0x01FF, 0x0004, 0x0005, 0x000C,
636 0x0068, 0x00D2, 0x00D3, 0x0035, 0x0036, 0x0037, 0x0038, 0x00E4,
637 0x00E5, 0x0073, 0x003A, 0x0076, 0x01DC, 0x01DD, 0x00EF, 0x000F,
638 0x0008, 0x0009, 0x0050, 0x0144, 0x0145, 0x0146, 0x028E, 0x051E,
639 0x051F, 0x0052, 0x0530, 0x0531, 0x0532, 0x0533, 0x0534, 0x0535,
640 0x0536, 0x0537, 0x014E, 0x0A78, 0x0A79, 0x0A7A, 0x0A7B, 0x0A7C,
641 0x0A7D, 0x0A7E, 0x0A7F, 0x0015, 0x0016, 0x0017, 0x0006, 0x0070,
642 0x00E2, 0x0E30, 0x0E31, 0x0E32, 0x0E33, 0x038D, 0x01C7, 0x0039,
643 0x01D0, 0x03A2, 0x0E8C, 0x0E8D, 0x0747, 0x00E9, 0x0075, 0x003B,
644 0x001E, 0x007C, 0x00FA, 0x03EC, 0x03ED, 0x03EE, 0x07DE, 0x07DF,
645 0x07E0, 0x07E1, 0x07E2, 0x07E3, 0x01F9, 0x00FD, 0x007F, 0x0008,
646 0x0090, 0x0091, 0x0092, 0x0093, 0x0128, 0x0129, 0x012A, 0x0958,
647 0x9590, 0x9591, 0x4AC9, 0x2565, 0x12B3, 0x04AD, 0x0257, 0x004B,
648 0x0098, 0x0264, 0x0265, 0x0266, 0x04CE, 0x04CF, 0x004D, 0x009C,
649 0x013A, 0x0276, 0x0277, 0x004F, 0x00A0, 0x0284, 0x050A, 0x050B,
650 0x050C, 0x0A1A, 0x0A1B, 0x0A1C, 0x0A1D, 0x0A1E, 0x0A1F, 0x00A2,
651 0x0A30, 0x0A31, 0x0A32, 0x0A33, 0x028D, 0x028E, 0x1478, 0x1479,
652 0x147A, 0x147B, 0x147C, 0x147D, 0x147E, 0x147F, 0x0029, 0x0015,
653 0x0058, 0x0059, 0x00B4, 0x16A0, 0x16A1, 0x16A2, 0x16A3, 0x16A4,
654 0x16A5, 0x16A6, 0x2D4E, 0x2D4F, 0x02D5, 0x016B, 0x02D8, 0x02D9,
655 0x016D, 0x016E, 0x05BC, 0x05BD, 0x02DF, 0x002E, 0x002F, 0x0003
656];
657const VEC_CB3_LENS: [u8; 520] = [
658 8, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
659 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
660 16, 16, 10, 9, 8, 10, 11, 11, 12, 12, 12, 12, 10, 9, 13, 13,
661 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11, 8, 9, 9, 9, 10,
662 10, 11, 11, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
663 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
664 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
665 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
666 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
667 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
668 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
669 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
670 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
671 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
672 16, 16, 16, 16, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
673 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
674 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
675 16, 16, 16, 16, 16, 12, 10, 10, 11, 11, 8, 6, 6, 6, 9, 10,
676 16, 16, 16, 16, 16, 16, 16, 16, 13, 12, 11, 9, 12, 12, 12, 12,
677 10, 8, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 11, 10,
678 10, 8, 11, 11, 10, 10, 10, 14, 14, 14, 14, 14, 14, 14, 14, 14,
679 14, 14, 14, 14, 14, 14, 14, 10, 9, 10, 14, 14, 14, 14, 12, 11,
680 11, 11, 11, 12, 12, 5, 5, 6, 9, 10, 10, 8, 8, 8, 8, 10,
681 10, 9, 8, 9, 11, 11, 10, 6, 5, 5, 8, 10, 10, 10, 11, 12,
682 12, 8, 12, 12, 12, 12, 12, 12, 12, 12, 10, 13, 13, 13, 13, 13,
683 13, 13, 13, 6, 6, 6, 4, 8, 9, 13, 13, 13, 13, 11, 10, 7,
684 10, 11, 13, 13, 12, 9, 8, 7, 6, 8, 9, 11, 11, 11, 12, 12,
685 12, 12, 12, 12, 10, 9, 8, 4, 8, 8, 8, 8, 9, 9, 9, 12,
686 16, 16, 15, 14, 13, 11, 10, 7, 8, 10, 10, 10, 11, 11, 7, 8,
687 9, 10, 10, 7, 8, 10, 11, 11, 11, 12, 12, 12, 12, 12, 12, 8,
688 12, 12, 12, 12, 10, 10, 13, 13, 13, 13, 13, 13, 13, 13, 6, 5,
689 7, 7, 8, 13, 13, 13, 13, 13, 13, 13, 14, 14, 10, 9, 10, 10,
690 9, 9, 11, 11, 10, 6, 6, 2
691];
692const VEC_CB3_SYMS: [u16; 520] = [
693 74, 1120, 1682, 1745, 1801, 274, 1050, 730, 546, 1058, 1729, 1539,
694 2240, 1547, 1163, 1730, 2064, 1624, 723, 1235, 1115, 35, 2248, 1304,
695 644, 196, 1625, 1036, 1548, 1185, 652, 1044, 2136, 1753, 1664, 129,
696 640, 83, 665, 130, 1225, 1232, 602, 76, 587, 1161, 1049, 545,
697 265, 1218, 2113, 202, 98, 131, 643, 1288, 524, 785, 720, 1096,
698 704, 528, 657, 601, 67, 537, 33, 579, 1746, 2258, 1248, 786,
699 1298, 1810, 2265, 2313, 1761, 1562, 2074, 2264, 1569, 2257, 225, 2138,
700 1056, 2081, 2249, 1690, 2202, 736, 2186, 1242, 1754, 282, 794, 1306,
701 1792, 1561, 2201, 1570, 2073, 281, 1122, 1634, 2178, 674, 1186, 1698,
702 226, 738, 1250, 1240, 289, 800, 1738, 2051, 1632, 1121, 793, 1603,
703 2115, 1633, 2250, 737, 1667, 2179, 195, 707, 1219, 1731, 2243, 259,
704 771, 1283, 1795, 2304, 2144, 2305, 1249, 2059, 2192, 2072, 2200, 1611,
705 2123, 1689, 288, 1696, 1675, 2187, 203, 792, 1227, 1739, 2251, 267,
706 779, 1291, 1803, 1802, 2256, 2242, 1555, 2067, 1560, 258, 1688, 1619,
707 2131, 770, 2145, 2114, 1683, 2195, 211, 1057, 2065, 1747, 275, 787,
708 1299, 1817, 1697, 1051, 1563, 2075, 1794, 2050, 801, 1627, 2139, 1800,
709 667, 1179, 1691, 219, 731, 1243, 1755, 283, 795, 2066, 547, 1059,
710 1571, 1184, 611, 1123, 1635, 163, 675, 1187, 227, 739, 1568, 1760,
711 1028, 1540, 2052, 2193, 1752, 1092, 1604, 2116, 1793, 2177, 1156, 1668,
712 649, 1618, 708, 1220, 1732, 260, 772, 1808, 1816, 280, 2312, 2060,
713 1305, 1241, 1297, 1612, 2124, 140, 2122, 1164, 1676, 204, 716, 1228,
714 1740, 268, 780, 2241, 1809, 2194, 1556, 2137, 2058, 1108, 1620, 148,
715 660, 1172, 1684, 212, 724, 1236, 28, 540, 1052, 1564, 92, 604,
716 1116, 666, 1105, 1153, 1673, 1162, 522, 584, 513, 73, 712, 650,
717 1628, 156, 668, 1180, 220, 732, 36, 548, 672, 777, 32, 656,
718 1233, 1113, 1602, 1665, 523, 586, 609, 1538, 728, 1112, 1289, 257,
719 1280, 1234, 216, 610, 1091, 2121, 1026, 1224, 1608, 1600, 96, 536,
720 713, 1104, 26, 1296, 1282, 2130, 1626, 218, 162, 1744, 1155, 2129,
721 715, 1043, 1281, 147, 1171, 224, 99, 1169, 144, 1672, 132, 1100,
722 2185, 596, 264, 768, 664, 1168, 1106, 154, 651, 64, 8, 585,
723 594, 201, 90, 1097, 593, 11, 1089, 2048, 1098, 89, 3, 75,
724 208, 91, 1090, 65, 576, 9, 137, 642, 658, 515, 20, 1736,
725 1728, 1025, 194, 784, 722, 538, 34, 1099, 769, 2176, 1544, 608,
726 1666, 1546, 217, 160, 2184, 544, 1027, 577, 521, 520, 1, 1032,
727 145, 2049, 1680, 659, 273, 97, 2112, 16, 138, 1217, 580, 588,
728 729, 4, 514, 81, 2, 592, 192, 1042, 531, 595, 2120, 1610,
729 714, 1170, 139, 1737, 1034, 88, 578, 512, 18, 1536, 1033, 66,
730 24, 200, 530, 84, 100, 612, 2080, 266, 1177, 209, 1601, 80,
731 1160, 146, 600, 152, 1035, 776, 17, 82, 25, 1609, 153, 648,
732 529, 1216, 1545, 27, 68, 272, 1552, 161, 1176, 1048, 1617, 641,
733 210, 1114, 1553, 1616, 1040, 705, 2057, 706, 2128, 1674, 1226, 1554,
734 1178, 1107, 10, 72, 136, 128, 1152, 1681, 539, 603, 155, 516,
735 673, 532, 778, 1290, 1537, 12, 721, 256, 1041, 19, 1154, 2056,
736 193, 1024, 1088, 0
737];
738
739const VEC_CB4_BITS: [u16; 209] = [
740 0x0000, 0x0004, 0x000A, 0x0016, 0x002E, 0x0178, 0x0179, 0x00BD,
741 0x05F0, 0x05F1, 0x05F2, 0x05F3, 0x05F4, 0x05F5, 0x05F6, 0x05F7,
742 0x05F8, 0x05F9, 0x05FA, 0x05FB, 0x05FC, 0x05FD, 0x05FE, 0x05FF,
743 0x0018, 0x0019, 0x000D, 0x001C, 0x001D, 0x000F, 0x0001, 0x0002,
744 0x0018, 0x0064, 0x0328, 0x0CA4, 0x0CA5, 0x0CA6, 0x0CA7, 0x0CA8,
745 0x0CA9, 0x0655, 0x032B, 0x00CB, 0x0066, 0x0067, 0x000D, 0x000E,
746 0x000F, 0x0001, 0x0010, 0x0440, 0x1104, 0x220A, 0x220B, 0x0883,
747 0x0221, 0x0111, 0x0089, 0x0045, 0x0118, 0x0119, 0x0468, 0x08D2,
748 0x08D3, 0x08D4, 0x08D5, 0x046B, 0x011B, 0x008E, 0x023C, 0x047A,
749 0x08F6, 0x23DC, 0x23DD, 0x23DE, 0x23DF, 0x011F, 0x0009, 0x000A,
750 0x0058, 0x02C8, 0x0592, 0x164C, 0x164D, 0x164E, 0x164F, 0x0B28,
751 0x0B29, 0x0595, 0x0596, 0x0597, 0x02CC, 0x059A, 0x0B36, 0x0B37,
752 0x0B38, 0x2CE4, 0x59CA, 0x59CB, 0x1673, 0x059D, 0x02CF, 0x00B4,
753 0x00B5, 0x005B, 0x0017, 0x0018, 0x0019, 0x001A, 0x0036, 0x01B8,
754 0x06E4, 0x1B94, 0x1B95, 0x0DCB, 0x0373, 0x06E8, 0x06E9, 0x0375,
755 0x01BB, 0x006F, 0x001C, 0x0074, 0x00EA, 0x01D6, 0x0EB8, 0x1D72,
756 0x75CC, 0x75CD, 0x75CE, 0x75CF, 0x75D0, 0x75D1, 0x75D2, 0x75D3,
757 0x75D4, 0x75D5, 0x75D6, 0x75D7, 0x75D8, 0x75D9, 0x75DA, 0x75DB,
758 0x75DC, 0x75DD, 0x75DE, 0x75DF, 0x75E0, 0x75E1, 0x75E2, 0x75E3,
759 0x75E4, 0x75E5, 0x75E6, 0x75E7, 0x75E8, 0x75E9, 0x75EA, 0x75EB,
760 0x75EC, 0x75ED, 0x75EE, 0x75EF, 0x75F0, 0x75F1, 0x75F2, 0x75F3,
761 0x75F4, 0x75F5, 0x75F6, 0x75F7, 0x75F8, 0x75F9, 0x75FA, 0x75FB,
762 0x75FC, 0x75FD, 0x75FE, 0x75FF, 0x00EC, 0x01DA, 0x76C0, 0x76C1,
763 0x76C2, 0x76C3, 0x76C4, 0x76C5, 0x76C6, 0x76C7, 0x76C8, 0x76C9,
764 0x76CA, 0x76CB, 0x76CC, 0x76CD, 0x76CE, 0x76CF, 0x76D0, 0x76D1,
765 0x76D2, 0x76D3, 0x76D4, 0x76D5, 0x3B6B, 0x0EDB, 0x03B7, 0x0077, 0x000F
766];
767const VEC_CB4_LENS: [u8; 209] = [
768 5, 7, 8, 9, 10, 13, 13, 12, 15, 15, 15, 15, 15, 15, 15, 15,
769 15, 15, 15, 15, 15, 15, 15, 15, 9, 9, 8, 9, 9, 8, 4, 4,
770 7, 9, 12, 14, 14, 14, 14, 14, 14, 13, 12, 10, 9, 9, 6, 6,
771 6, 2, 5, 11, 13, 14, 14, 12, 10, 9, 8, 7, 9, 9, 11, 12,
772 12, 12, 12, 11, 9, 8, 10, 11, 12, 14, 14, 14, 14, 9, 4, 4,
773 7, 10, 11, 13, 13, 13, 13, 12, 12, 11, 11, 11, 10, 11, 12, 12,
774 12, 14, 15, 15, 13, 11, 10, 8, 8, 7, 5, 5, 5, 5, 6, 9,
775 11, 13, 13, 12, 10, 11, 11, 10, 9, 7, 5, 7, 8, 9, 12, 13,
776 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
777 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
778 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
779 15, 15, 15, 15, 8, 9, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
780 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 12, 10, 7, 4
781];
782const VEC_CB4_SYMS: [u16; 209] = [
783 80, 128, 96, 132, 160, 134, 92, 23, 180, 228, 232, 214,
784 225, 166, 54, 138, 121, 131, 147, 99, 141, 75, 27, 91,
785 37, 66, 24, 129, 145, 36, 1, 64, 6, 73, 34, 57,
786 49, 42, 106, 14, 56, 130, 98, 7, 33, 97, 69, 81,
787 85, 0, 20, 12, 76, 11, 44, 212, 40, 70, 22, 144,
788 86, 149, 165, 196, 102, 137, 146, 52, 72, 148, 192, 28,
789 19, 120, 30, 224, 169, 82, 4, 16, 8, 208, 48, 93,
790 168, 193, 53, 152, 67, 161, 112, 29, 41, 74, 77, 150,
791 71, 87, 114, 178, 213, 116, 164, 18, 101, 32, 65, 21,
792 84, 17, 2, 3, 153, 113, 83, 117, 105, 38, 90, 13,
793 10, 100, 68, 9, 89, 133, 197, 209, 181, 61, 245, 198,
794 205, 125, 156, 220, 233, 172, 216, 230, 109, 118, 182, 217,
795 176, 173, 202, 204, 108, 154, 218, 184, 185, 170, 58, 122,
796 124, 78, 142, 201, 94, 158, 46, 110, 157, 200, 240, 195,
797 244, 60, 210, 211, 35, 241, 163, 51, 115, 221, 229, 135,
798 88, 26, 199, 177, 45, 151, 215, 39, 103, 167, 55, 119,
799 140, 162, 139, 226, 50, 155, 43, 107, 15, 79, 31, 95,
800 194, 136, 104, 25, 5
801];
802
803const VEC_CB5_BITS: [u16; 192] = [
804 0x0000, 0x0004, 0x0005, 0x0060, 0x0184, 0x030A, 0x0616, 0x0617,
805 0x030C, 0x061A, 0x061B, 0x0187, 0x0031, 0x0019, 0x001A, 0x001B,
806 0x000E, 0x003C, 0x003D, 0x003E, 0x007E, 0x01FC, 0x03FA, 0x1FD8,
807 0x1FD9, 0x0FED, 0x0FEE, 0x0FEF, 0x00FF, 0x0010, 0x0044, 0x008A,
808 0x008B, 0x0023, 0x0009, 0x000A, 0x000B, 0x0060, 0x1840, 0x1841,
809 0x1842, 0x1843, 0x0C22, 0x0C23, 0x0612, 0x184C, 0x309A, 0x309B,
810 0x0C27, 0x030A, 0x0616, 0x0617, 0x0186, 0x1870, 0x1871, 0x0C39,
811 0x0C3A, 0x0C3B, 0x061E, 0x0C3E, 0x0C3F, 0x0031, 0x0019, 0x001A,
812 0x0036, 0x00DC, 0x0DD0, 0x0DD1, 0x06E9, 0x0375, 0x01BB, 0x01BC,
813 0x0DE8, 0x37A4, 0x6F4A, 0x6F4B, 0x1BD3, 0x06F5, 0x06F6, 0x1BDC,
814 0x1BDD, 0x0DEF, 0x0DF0, 0x0DF1, 0x6F90, 0x6F91, 0x6F92, 0x6F93,
815 0x6F94, 0x6F95, 0x6F96, 0x6F97, 0x6F98, 0x6F99, 0x6F9A, 0x6F9B,
816 0x6F9C, 0x6F9D, 0x6F9E, 0x6F9F, 0x6FA0, 0x6FA1, 0x6FA2, 0x6FA3,
817 0x6FA4, 0x6FA5, 0x6FA6, 0x6FA7, 0x6FA8, 0x6FA9, 0x6FAA, 0x6FAB,
818 0x6FAC, 0x6FAD, 0x6FAE, 0x6FAF, 0x6FB0, 0x6FB1, 0x6FB2, 0x6FB3,
819 0x6FB4, 0x6FB5, 0x6FB6, 0x6FB7, 0x6FB8, 0x6FB9, 0x6FBA, 0x6FBB,
820 0x6FBC, 0x6FBD, 0x6FBE, 0x6FBF, 0x6FC0, 0x6FC1, 0x6FC2, 0x6FC3,
821 0x6FC4, 0x6FC5, 0x6FC6, 0x6FC7, 0x6FC8, 0x6FC9, 0x6FCA, 0x6FCB,
822 0x6FCC, 0x6FCD, 0x6FCE, 0x6FCF, 0x6FD0, 0x6FD1, 0x6FD2, 0x6FD3,
823 0x6FD4, 0x6FD5, 0x6FD6, 0x6FD7, 0x6FD8, 0x6FD9, 0x6FDA, 0x6FDB,
824 0x6FDC, 0x6FDD, 0x37EF, 0x0DFC, 0x0DFD, 0x0DFE, 0x37FC, 0x37FD,
825 0x37FE, 0x37FF, 0x001C, 0x003A, 0x0076, 0x0077, 0x00F0, 0x00F1,
826 0x03C8, 0x0792, 0x1E4C, 0x1E4D, 0x1E4E, 0x1E4F, 0x1E50, 0x1E51,
827 0x1E52, 0x1E53, 0x0F2A, 0x0F2B, 0x03CB, 0x00F3, 0x003D, 0x001F
828];
829const VEC_CB5_LENS: [u8; 192] = [
830 2, 4, 4, 8, 10, 11, 12, 12, 11, 12, 12, 10, 7, 6, 6, 6,
831 5, 7, 7, 7, 8, 10, 11, 14, 14, 13, 13, 13, 9, 5, 7, 8,
832 8, 6, 4, 4, 4, 7, 13, 13, 13, 13, 12, 12, 11, 13, 14, 14,
833 12, 10, 11, 11, 9, 13, 13, 12, 12, 12, 11, 12, 12, 6, 5, 5,
834 6, 8, 12, 12, 11, 10, 9, 9, 12, 14, 15, 15, 13, 11, 11, 13,
835 13, 12, 12, 12, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
836 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
837 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
838 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
839 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
840 15, 15, 14, 12, 12, 12, 14, 14, 14, 14, 5, 6, 7, 7, 8, 8,
841 10, 11, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 10, 8, 6, 5
842];
843const VEC_CB5_SYMS: [u16; 192] = [
844 0, 1, 256, 277, 24, 25, 262, 88, 100, 132, 70, 384,
845 81, 17, 272, 68, 5, 321, 69, 276, 337, 144, 72, 10,
846 389, 289, 532, 517, 32, 320, 324, 325, 2, 260, 4, 64,
847 16, 273, 352, 265, 264, 329, 97, 148, 66, 86, 533, 149,
848 37, 36, 400, 22, 128, 280, 326, 516, 101, 292, 528, 577,
849 592, 21, 20, 80, 336, 512, 133, 580, 33, 96, 576, 9,
850 274, 593, 597, 581, 356, 513, 288, 338, 278, 328, 388, 73,
851 405, 661, 344, 660, 549, 152, 417, 613, 165, 421, 392, 296,
852 521, 645, 641, 585, 137, 393, 608, 416, 537, 656, 609, 601,
853 153, 409, 420, 297, 105, 361, 360, 408, 514, 164, 40, 578,
854 130, 386, 548, 544, 530, 584, 545, 594, 146, 402, 600, 290,
855 98, 354, 644, 136, 518, 657, 520, 582, 134, 390, 104, 536,
856 534, 161, 342, 598, 150, 406, 38, 294, 102, 358, 612, 266,
857 74, 330, 26, 282, 90, 346, 41, 293, 322, 82, 34, 640,
858 401, 160, 257, 84, 340, 85, 341, 6, 258, 129, 353, 529,
859 404, 357, 281, 89, 345, 596, 385, 145, 18, 8, 261, 65
860];
861
862const VEC_CB6_BITS: [u16; 32] = [
863 0x0000, 0x0004, 0x0005, 0x0003, 0x0001, 0x0002, 0x0003, 0x0001,
864 0x0002, 0x0003, 0x0004, 0x0005, 0x0018, 0x00C8, 0x0192, 0x0326,
865 0x0327, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x01A8, 0x01A9,
866 0x00D5, 0x006B, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0001
867];
868const VEC_CB6_LENS: [u8; 32] = [
869 7, 9, 9, 8, 6, 6, 6, 4, 4, 4, 4, 4, 6, 9, 10, 11,
870 11, 8, 8, 8, 8, 8, 10, 10, 9, 8, 6, 6, 6, 6, 6, 1
871];
872const VEC_CB6_SYMS: [u16; 32] = [
873 9, 19, 22, 7, 3, 24, 6, 1, 16, 2, 8, 4,
874 12, 21, 27, 29, 31, 28, 14, 13, 11, 26, 30, 23,
875 15, 25, 5, 10, 20, 17, 18, 0
876];
877
878const QUANT_LEVELS: [[f32; 14]; 7] = [
879 [ 0.0, 0.392, 0.761, 1.120, 1.477, 1.832, 2.183, 2.541, 2.893, 3.245, 3.598, 3.942, 4.288, 4.724 ],
880 [ 0.0, 0.544, 1.060, 1.563, 2.068, 2.571, 3.072, 3.562, 4.070, 4.620, 0.0, 0.0, 0.0, 0.0 ],
881 [ 0.0, 0.746, 1.464, 2.180, 2.882, 3.584, 4.316, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ],
882 [ 0.0, 1.006, 2.000, 2.993, 3.985, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ],
883 [ 0.0, 1.321, 2.703, 3.983, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ],
884 [ 0.0, 1.657, 3.491, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ],
885 [ 0.0, 1.964, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]
886];
887
888const CAT5_NOISE_FACTOR: [f32; REGION_SIZE + 1] = [
889 0.70711, 0.6179, 0.5005, 0.3220, 0.17678, 0.17678, 0.17678, 0.17678, 0.17678, 0.17678,
890 0.17678, 0.17678, 0.17678, 0.17678, 0.17678, 0.17678, 0.17678, 0.17678, 0.17678, 0.17678, 0.0
891];
892const CAT6_NOISE_FACTOR: [f32; REGION_SIZE + 1] = [
893 0.70711, 0.5686, 0.3563, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
894 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.0
895];