]> git.nihav.org Git - nihav.git/blame - nihav-mpeg/src/codecs/aac/sbr/bs.rs
nihav_itu: ignore high-profile extradata tail when it is not correct
[nihav.git] / nihav-mpeg / src / codecs / aac / sbr / bs.rs
CommitLineData
0e18270d
KS
1use nihav_core::codecs::{DecoderResult, DecoderError};
2use nihav_core::io::bitreader::*;
3use nihav_core::io::codebook::*;
4
5use super::{MAX_SLOTS, NUM_ENVELOPES, SBR_BANDS, SBRState, SBRChannel};
6use super::synth::QuantMode;
7
8#[derive(Clone,Copy,Debug,PartialEq)]
9pub enum FrameClass {
10 FixFix,
11 FixVar,
12 VarFix,
13 VarVar,
14}
15
16impl FrameClass {
17 fn read(br: &mut BitReader) -> DecoderResult<Self> {
18 Ok(match br.read(2)? {
19 0 => Self::FixFix,
20 1 => Self::FixVar,
21 2 => Self::VarFix,
22 _ => Self::VarVar,
23 })
24 }
25}
26
27pub fn sbr_read_sce(br: &mut BitReader, orig_amp_res: bool, state: &SBRState, cbs: &SBRCodebooks, ch: &mut SBRChannel) -> DecoderResult<()> {
28 ch.qmode = QuantMode::Single;
29 if br.read_bool()? {
30 br.skip(4)?;
31 }
32 read_grid(br, ch)?;
33 read_dtdf(br, ch)?;
34 read_invf(br, ch, state)?;
35 ch.set_amp_res(orig_amp_res);
36 read_envelope(br, ch, false, cbs, state)?;
37 read_noise(br, ch, false, cbs, state)?;
38 read_sinusoidal_coding(br, ch, state)?;
39 read_extensions(br)?;
40
41 Ok(())
42}
43pub fn sbr_read_cpe(br: &mut BitReader, orig_amp_res: bool, state: &SBRState, cbs: &SBRCodebooks, ch: &mut [SBRChannel; 2]) -> DecoderResult<()> {
44 if br.read_bool()? {
45 br.skip(4)?;
46 br.skip(4)?;
47 }
48 let coupling = br.read_bool()?;
49 if coupling {
50 ch[0].qmode = QuantMode::Left;
51 ch[1].qmode = QuantMode::Right;
52 read_grid(br, &mut ch[0])?;
53 ch[1].fclass = ch[0].fclass;
54 ch[1].num_env = ch[0].num_env;
55 ch[1].env_border = ch[0].env_border;
56 ch[1].freq_res = ch[0].freq_res;
57 ch[1].pointer = ch[0].pointer;
58 ch[1].num_noise = ch[0].num_noise;
59 ch[1].noise_env_border = ch[0].noise_env_border;
60
61 read_dtdf(br, &mut ch[0])?;
62 read_dtdf(br, &mut ch[1])?;
63 read_invf(br, &mut ch[0], state)?;
64 ch[1].invf_mode = ch[0].invf_mode;
65
66 ch[0].set_amp_res(orig_amp_res);
67 read_envelope(br, &mut ch[0], false, cbs, state)?;
68 read_noise(br, &mut ch[0], false, cbs, state)?;
69 ch[1].set_amp_res(orig_amp_res);
70 read_envelope(br, &mut ch[1], true, cbs, state)?;
71 read_noise(br, &mut ch[1], true, cbs, state)?;
72
73 ch[0].data_env2 = ch[1].data_env;
74 ch[0].data_noise2 = ch[1].data_noise;
75 ch[1].data_env2 = ch[0].data_env;
76 ch[1].data_noise2 = ch[0].data_noise;
77 } else {
78 ch[0].qmode = QuantMode::Single;
79 ch[1].qmode = QuantMode::Single;
80 read_grid(br, &mut ch[0])?;
81 read_grid(br, &mut ch[1])?;
82 read_dtdf(br, &mut ch[0])?;
83 read_dtdf(br, &mut ch[1])?;
84 read_invf(br, &mut ch[0], state)?;
85 read_invf(br, &mut ch[1], state)?;
86
87 ch[0].set_amp_res(orig_amp_res);
88 read_envelope(br, &mut ch[0], false, cbs, state)?;
89 ch[1].set_amp_res(orig_amp_res);
90 read_envelope(br, &mut ch[1], false, cbs, state)?;
91 read_noise(br, &mut ch[0], false, cbs, state)?;
92 read_noise(br, &mut ch[1], false, cbs, state)?;
93 }
94 read_sinusoidal_coding(br, &mut ch[0], state)?;
95 read_sinusoidal_coding(br, &mut ch[1], state)?;
96 read_extensions(br)?;
97
98 Ok(())
99}
100
101fn read_grid(br: &mut BitReader, chan: &mut SBRChannel) -> DecoderResult<()> {
102 chan.fclass = FrameClass::read(br)?;
103 match chan.fclass {
104 FrameClass::FixFix => {
105 chan.num_env = 1 << br.read(2)?;
106 let freq_res = br.read_bool()?;
107 for el in chan.freq_res[..chan.num_env].iter_mut() {
108 *el = freq_res;
109 }
e36af157 110 chan.env_border[0] = 0;
0e18270d
KS
111 if chan.num_env > 1 {
112 let delta = (MAX_SLOTS + chan.num_env / 2) / chan.num_env;
e36af157
KS
113 for i in 1..chan.num_env {
114 chan.env_border[i] = chan.env_border[i - 1] + delta;
0e18270d
KS
115 }
116 }
e36af157 117 chan.env_border[chan.num_env] = MAX_SLOTS;
0e18270d
KS
118 },
119 FrameClass::FixVar => {
120 let var_bord_1 = br.read(2)? as u8;
121 chan.num_env = br.read(2)? as usize + 1;
122 let mut rel_bord_1 = [0u8; NUM_ENVELOPES];
123 for el in rel_bord_1[..chan.num_env - 1].iter_mut() {
124 *el = 2 * (br.read(2)? as u8) + 2;
125 }
126 let ptr_bits = 8 - (chan.num_env as u8).leading_zeros();
127 chan.pointer = br.read(ptr_bits as u8)? as u8;
128 for el in chan.freq_res[..chan.num_env].iter_mut().rev() {
129 *el = br.read_bool()?;
130 }
131
e36af157
KS
132 chan.env_border[0] = 0;
133 chan.env_border[chan.num_env] = MAX_SLOTS + usize::from(var_bord_1);
0e18270d 134 for (i, &delta) in (1..chan.num_env).rev().zip(rel_bord_1.iter()) {
e36af157 135 chan.env_border[i] = chan.env_border[i + 1] - usize::from(delta);
0e18270d
KS
136 }
137 },
138 FrameClass::VarFix => {
139 let var_bord_0 = br.read(2)? as u8;
140 chan.num_env = br.read(2)? as usize + 1;
141 let mut rel_bord_0 = [0u8; NUM_ENVELOPES];
142 for el in rel_bord_0[..chan.num_env - 1].iter_mut() {
143 *el = 2 * (br.read(2)? as u8) + 2;
144 }
145 let ptr_bits = 8 - (chan.num_env as u8).leading_zeros();
146 chan.pointer = br.read(ptr_bits as u8)? as u8;
147 for el in chan.freq_res[..chan.num_env].iter_mut() {
148 *el = br.read_bool()?;
149 }
150
e36af157
KS
151 chan.env_border[0] = usize::from(var_bord_0);
152 for i in 0..chan.num_env - 1 {
153 chan.env_border[i + 1] = chan.env_border[i] + usize::from(rel_bord_0[i]);
0e18270d 154 }
e36af157 155 chan.env_border[chan.num_env] = MAX_SLOTS;
0e18270d
KS
156 },
157 FrameClass::VarVar => {
158 let var_bord_0 = br.read(2)? as u8;
159 let var_bord_1 = br.read(2)? as u8;
160 let num_rel_0 = br.read(2)? as usize;
161 let num_rel_1 = br.read(2)? as usize;
e6aaad5c 162 chan.num_env = num_rel_0 + num_rel_1 + 1;
0e18270d
KS
163 let mut rel_bord_0 = [0u8; NUM_ENVELOPES];
164 let mut rel_bord_1 = [0u8; NUM_ENVELOPES];
165 for el in rel_bord_0[..num_rel_0].iter_mut() {
166 *el = 2 * (br.read(2)? as u8) + 2;
167 }
168 for el in rel_bord_1[..num_rel_1].iter_mut() {
169 *el = 2 * (br.read(2)? as u8) + 2;
170 }
171 let ptr_bits = 8 - (chan.num_env as u8).leading_zeros();
172 chan.pointer = br.read(ptr_bits as u8)? as u8;
173 for el in chan.freq_res[..chan.num_env].iter_mut() {
174 *el = br.read_bool()?;
175 }
176
e36af157
KS
177 chan.env_border[0] = usize::from(var_bord_0);
178 for i in 0..num_rel_0 {
179 chan.env_border[i + 1] = chan.env_border[i] + usize::from(rel_bord_0[i]);
0e18270d 180 }
e36af157 181 chan.env_border[chan.num_env] = MAX_SLOTS + usize::from(var_bord_1);
0e18270d 182 for i in 0..num_rel_1 {
e36af157 183 chan.env_border[chan.num_env - 1 - i] = chan.env_border[chan.num_env - i] - usize::from(rel_bord_1[i]);
0e18270d
KS
184 }
185 },
186 };
e36af157 187 for i in 0..chan.num_env {
0e18270d
KS
188 validate!(chan.env_border[i] < chan.env_border[i + 1]);
189 }
190
191 if chan.num_env > 1 {
192 chan.num_noise = 2;
193 let mid = match (chan.fclass, chan.pointer) {
e36af157
KS
194 (FrameClass::FixFix, _) => chan.num_env / 2,
195 (FrameClass::VarFix, 0) => 1,
196 (FrameClass::VarFix, 1) => chan.num_env - 1,
197 (FrameClass::VarFix, _) => chan.pointer as usize - 1,
198 (_, 0) | (_, 1) => chan.num_env - 1,
199 (_, _) => chan.num_env + 1 - (chan.pointer as usize),
0e18270d 200 };
e36af157
KS
201 chan.noise_env_border[0] = chan.env_border[0];
202 chan.noise_env_border[1] = chan.env_border[mid];
203 chan.noise_env_border[2] = chan.env_border[chan.num_env];
0e18270d
KS
204 } else {
205 chan.num_noise = 1;
206 chan.noise_env_border[0] = chan.env_border[0];
e36af157 207 chan.noise_env_border[1] = chan.env_border[1];
0e18270d 208 }
cd72fd8a 209
0e18270d
KS
210
211 Ok(())
212}
213fn read_dtdf(br: &mut BitReader, chan: &mut SBRChannel) -> DecoderResult<()> {
214 for el in chan.df_env[..chan.num_env].iter_mut() {
215 *el = br.read_bool()?;
216 }
217 for el in chan.df_noise[..chan.num_noise].iter_mut() {
218 *el = br.read_bool()?;
219 }
220 Ok(())
221}
222fn read_invf(br: &mut BitReader, chan: &mut SBRChannel, state: &SBRState) -> DecoderResult<()> {
223 for el in chan.invf_mode[..state.num_noise_bands].iter_mut() {
224 *el = br.read(2)? as u8;
225 }
226 Ok(())
227}
228fn read_envelope(br: &mut BitReader, chan: &mut SBRChannel, coupled: bool, cbs: &SBRCodebooks, state: &SBRState) -> DecoderResult<()> {
229 let (f_cb, t_cb) = if coupled {
230 if chan.amp_res {
231 (&cbs.env_bal_3_0db_f_cb, &cbs.env_bal_3_0db_t_cb)
232 } else {
233 (&cbs.env_bal_1_5db_f_cb, &cbs.env_bal_1_5db_t_cb)
234 }
235 } else {
236 if chan.amp_res {
237 (&cbs.env_3_0db_f_cb, &cbs.env_3_0db_t_cb)
238 } else {
239 (&cbs.env_1_5db_f_cb, &cbs.env_1_5db_t_cb)
240 }
241 };
242 let scale = if coupled { 2 } else { 1 };
243 for (envelope, (&df_env, &freq_res)) in chan.data_env[..chan.num_env].iter_mut().zip(chan.df_env.iter().zip(chan.freq_res.iter())) {
244 let num_env_bands = state.num_env_bands[freq_res as usize];
245 if !df_env {
246 if coupled {
247 envelope[0] = br.read(5 + (!chan.amp_res as u8))? as i8;
248 } else {
249 envelope[0] = br.read(6 + (!chan.amp_res as u8))? as i8;
250 }
251 envelope[0] *= scale;
252 let mut last = envelope[0];
253 for band_env in envelope[1..num_env_bands].iter_mut() {
254 let delta = br.read_cb(f_cb)?;
255 *band_env = last + delta * scale;
256 last = *band_env
257 }
258 } else {
259 for (i, band_env) in envelope[..num_env_bands].iter_mut().enumerate() {
260 let delta = br.read_cb(t_cb)?;
261 let last = match (freq_res, chan.last_freq_res) {
5f9bf764
KS
262 (false, true) => chan.last_envelope[state.high_to_low_res[i]],
263 (true, false) => chan.last_envelope[state.low_to_high_res[i]],
0e18270d
KS
264 _ => chan.last_envelope[i],
265 };
266 *band_env = last + delta * scale;
267 }
268 }
269 chan.last_envelope = *envelope;
270 chan.last_freq_res = freq_res;
271 }
272 Ok(())
273}
274fn read_noise(br: &mut BitReader, chan: &mut SBRChannel, coupled: bool, cbs: &SBRCodebooks, state: &SBRState) -> DecoderResult<()> {
275 let (f_cb, t_cb) = if coupled {
276 (&cbs.env_bal_3_0db_f_cb, &cbs.noise_bal_3_0db_t_cb)
277 } else {
278 (&cbs.env_3_0db_f_cb, &cbs.noise_3_0db_t_cb)
279 };
280 let scale = if coupled { 2 } else { 1 };
281 for (noise, &df_noise) in chan.data_noise[..chan.num_noise].iter_mut().zip(chan.df_noise.iter()) {
282 if !df_noise {
283 noise[0] = (br.read(5)? as i8) * scale;
284 let mut last = noise[0];
285 for band_noise in noise[1..state.num_noise_bands].iter_mut() {
286 let delta = br.read_cb(f_cb)?;
287 *band_noise = last + scale * delta;
288 last = *band_noise;
289 }
290 } else {
291 for (band_noise, &last) in noise[..state.num_noise_bands].iter_mut().zip(chan.last_noise_env.iter()) {
292 let delta = br.read_cb(t_cb)?;
293 *band_noise = last + delta * scale;
294 }
295 }
296 chan.last_noise_env = *noise;
297 }
298 Ok(())
299}
300fn read_sinusoidal_coding(br: &mut BitReader, chan: &mut SBRChannel, state: &SBRState) -> DecoderResult<()> {
301 if !br.read_bool()? {
302 chan.add_harmonic = [false; SBR_BANDS];
303 return Ok(());
304 }
305 for el in chan.add_harmonic[..state.num_env_bands[1]].iter_mut() {
306 *el = br.read_bool()?;
307 }
308 Ok(())
309}
310fn read_extensions(br: &mut BitReader) -> DecoderResult<()> {
311 if br.read_bool()? {
312 let mut size = br.read(4)? as usize;
313 if size == 15 {
314 size += br.read(8)? as usize;
315 }
316 validate!(br.left() >= ((size * 8) as isize));
317 let end = br.tell() + size * 8;
318 while br.tell() + 7 < end {
319 let _extension_id = br.read(2)?;
320 // todo parse PS?
321 }
322 }
323 Ok(())
324}
325
326pub struct SBRCodebooks {
327 env_bal_1_5db_f_cb: Codebook<i8>,
328 env_bal_1_5db_t_cb: Codebook<i8>,
329 env_bal_3_0db_f_cb: Codebook<i8>,
330 env_bal_3_0db_t_cb: Codebook<i8>,
331 env_1_5db_f_cb: Codebook<i8>,
332 env_1_5db_t_cb: Codebook<i8>,
333 env_3_0db_f_cb: Codebook<i8>,
334 env_3_0db_t_cb: Codebook<i8>,
335 noise_bal_3_0db_t_cb: Codebook<i8>,
336 noise_3_0db_t_cb: Codebook<i8>,
337}
338
339fn map_idx12(idx: usize) -> i8 { idx as i8 - 12 }
340fn map_idx24(idx: usize) -> i8 { idx as i8 - 24 }
341fn map_idx31(idx: usize) -> i8 { idx as i8 - 31 }
342fn map_idx60(idx: usize) -> i8 { idx as i8 - 60 }
343
344impl SBRCodebooks {
345 pub fn new() -> Self {
346 let mut cbr = TableCodebookDescReader::new(ENV_BAL_1_5DB_F_BITS, ENV_BAL_1_5DB_F_LENS, map_idx24);
347 let env_bal_1_5db_f_cb = Codebook::new(&mut cbr, CodebookMode::MSB).unwrap();
348 let mut cbr = TableCodebookDescReader::new(ENV_BAL_1_5DB_T_BITS, ENV_BAL_1_5DB_T_LENS, map_idx24);
349 let env_bal_1_5db_t_cb = Codebook::new(&mut cbr, CodebookMode::MSB).unwrap();
350
351 let mut cbr = TableCodebookDescReader::new(ENV_1_5DB_F_BITS, ENV_1_5DB_F_LENS, map_idx60);
352 let env_1_5db_f_cb = Codebook::new(&mut cbr, CodebookMode::MSB).unwrap();
353 let mut cbr = TableCodebookDescReader::new(ENV_1_5DB_T_BITS, ENV_1_5DB_T_LENS, map_idx60);
354 let env_1_5db_t_cb = Codebook::new(&mut cbr, CodebookMode::MSB).unwrap();
355
356 let mut cbr = TableCodebookDescReader::new(ENV_BAL_3_0DB_F_BITS, ENV_BAL_3_0DB_F_LENS, map_idx12);
357 let env_bal_3_0db_f_cb = Codebook::new(&mut cbr, CodebookMode::MSB).unwrap();
358 let mut cbr = TableCodebookDescReader::new(ENV_BAL_3_0DB_T_BITS, ENV_BAL_3_0DB_T_LENS, map_idx12);
359 let env_bal_3_0db_t_cb = Codebook::new(&mut cbr, CodebookMode::MSB).unwrap();
360
361 let mut cbr = TableCodebookDescReader::new(ENV_3_0DB_F_BITS, ENV_3_0DB_F_LENS, map_idx31);
362 let env_3_0db_f_cb = Codebook::new(&mut cbr, CodebookMode::MSB).unwrap();
363 let mut cbr = TableCodebookDescReader::new(ENV_3_0DB_T_BITS, ENV_3_0DB_T_LENS, map_idx31);
364 let env_3_0db_t_cb = Codebook::new(&mut cbr, CodebookMode::MSB).unwrap();
365
366 let mut cbr = TableCodebookDescReader::new(NOISE_BAL_3_0DB_T_BITS, NOISE_BAL_3_0DB_T_LENS, map_idx12);
367 let noise_bal_3_0db_t_cb = Codebook::new(&mut cbr, CodebookMode::MSB).unwrap();
368 let mut cbr = TableCodebookDescReader::new(NOISE_3_0DB_T_BITS, NOISE_3_0DB_T_LENS, map_idx31);
369 let noise_3_0db_t_cb = Codebook::new(&mut cbr, CodebookMode::MSB).unwrap();
370
371 Self {
372 env_bal_1_5db_f_cb, env_bal_1_5db_t_cb,
373 env_1_5db_f_cb, env_1_5db_t_cb,
374 env_bal_3_0db_f_cb, env_bal_3_0db_t_cb,
375 env_3_0db_f_cb, env_3_0db_t_cb,
376 noise_3_0db_t_cb, noise_bal_3_0db_t_cb
377 }
378 }
379}
380
381const ENV_1_5DB_F_BITS: &[u32; 121] = &[
382 0x7ffe7, 0x7ffe8, 0xfffd2, 0xfffd3, 0xfffd4, 0xfffd5, 0xfffd6, 0xfffd7,
383 0xfffd8, 0x7ffda, 0xfffd9, 0xfffda, 0xfffdb, 0xfffdc, 0x7ffdb, 0xfffdd,
384 0x7ffdc, 0x7ffdd, 0xfffde, 0x3ffe4, 0xfffdf, 0xfffe0, 0xfffe1, 0x7ffde,
385 0xfffe2, 0xfffe3, 0xfffe4, 0x7ffdf, 0xfffe5, 0x7ffe0, 0x3ffe8, 0x7ffe1,
386 0x3ffe0, 0x3ffe9, 0x1ffef, 0x3ffe5, 0x1ffec, 0x1ffed, 0x1ffee, 0x0fff4,
387 0x0fff3, 0x0fff0, 0x07ff7, 0x07ff6, 0x03ffa, 0x01ffa, 0x01ff9, 0x00ffa,
388 0x00ff8, 0x007f9, 0x003fb, 0x001fc, 0x001fa, 0x000fb, 0x0007c, 0x0003c,
389 0x0001c, 0x0000c, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000d, 0x0001d,
390 0x0003d, 0x000fa, 0x000fc, 0x001fb, 0x003fa, 0x007f8, 0x007fa, 0x007fb,
391 0x00ff9, 0x00ffb, 0x01ff8, 0x01ffb, 0x03ff8, 0x03ff9, 0x0fff1, 0x0fff2,
392 0x1ffea, 0x1ffeb, 0x3ffe1, 0x3ffe2, 0x3ffea, 0x3ffe3, 0x3ffe6, 0x3ffe7,
393 0x3ffeb, 0xfffe6, 0x7ffe2, 0xfffe7, 0xfffe8, 0xfffe9, 0xfffea, 0xfffeb,
394 0xfffec, 0x7ffe3, 0xfffed, 0xfffee, 0xfffef, 0xffff0, 0x7ffe4, 0xffff1,
395 0x3ffec, 0xffff2, 0xffff3, 0x7ffe5, 0x7ffe6, 0xffff4, 0xffff5, 0xffff6,
396 0xffff7, 0xffff8, 0xffff9, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe,
397 0xfffff
398];
399const ENV_1_5DB_F_LENS: &[u8; 121] = &[
400 19, 19, 20, 20, 20, 20, 20, 20,
401 20, 19, 20, 20, 20, 20, 19, 20,
402 19, 19, 20, 18, 20, 20, 20, 19,
403 20, 20, 20, 19, 20, 19, 18, 19,
404 18, 18, 17, 18, 17, 17, 17, 16,
405 16, 16, 15, 15, 14, 13, 13, 12,
406 12, 11, 10, 9, 9, 8, 7, 6,
407 5, 4, 3, 2, 2, 3, 4, 5,
408 6, 8, 8, 9, 10, 11, 11, 11,
409 12, 12, 13, 13, 14, 14, 16, 16,
410 17, 17, 18, 18, 18, 18, 18, 18,
411 18, 20, 19, 20, 20, 20, 20, 20,
412 20, 19, 20, 20, 20, 20, 19, 20,
413 18, 20, 20, 19, 19, 20, 20, 20,
414 20, 20, 20, 20, 20, 20, 20, 20,
415 20
416];
417const ENV_1_5DB_T_BITS: &[u32; 121] = &[
418 0x3ffd6, 0x3ffd7, 0x3ffd8, 0x3ffd9, 0x3ffda, 0x3ffdb, 0x7ffb8, 0x7ffb9,
419 0x7ffba, 0x7ffbb, 0x7ffbc, 0x7ffbd, 0x7ffbe, 0x7ffbf, 0x7ffc0, 0x7ffc1,
420 0x7ffc2, 0x7ffc3, 0x7ffc4, 0x7ffc5, 0x7ffc6, 0x7ffc7, 0x7ffc8, 0x7ffc9,
421 0x7ffca, 0x7ffcb, 0x7ffcc, 0x7ffcd, 0x7ffce, 0x7ffcf, 0x7ffd0, 0x7ffd1,
422 0x7ffd2, 0x7ffd3, 0x1ffe6, 0x3ffd4, 0x0fff0, 0x1ffe9, 0x3ffd5, 0x1ffe7,
423 0x0fff1, 0x0ffec, 0x0ffed, 0x0ffee, 0x07ff4, 0x03ff9, 0x03ff7, 0x01ffa,
424 0x01ff9, 0x00ffb, 0x007fc, 0x003fc, 0x001fd, 0x000fd, 0x0007d, 0x0003d,
425 0x0001d, 0x0000d, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000c, 0x0001c,
426 0x0003c, 0x0007c, 0x000fc, 0x001fc, 0x003fd, 0x00ffa, 0x01ff8, 0x03ff6,
427 0x03ff8, 0x07ff5, 0x0ffef, 0x1ffe8, 0x0fff2, 0x7ffd4, 0x7ffd5, 0x7ffd6,
428 0x7ffd7, 0x7ffd8, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd, 0x7ffde,
429 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffe6,
430 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffec, 0x7ffed, 0x7ffee,
431 0x7ffef, 0x7fff0, 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6,
432 0x7fff7, 0x7fff8, 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe,
433 0x7ffff
434];
435const ENV_1_5DB_T_LENS: &[u8; 121] = &[
436 18, 18, 18, 18, 18, 18, 19, 19,
437 19, 19, 19, 19, 19, 19, 19, 19,
438 19, 19, 19, 19, 19, 19, 19, 19,
439 19, 19, 19, 19, 19, 19, 19, 19,
440 19, 19, 17, 18, 16, 17, 18, 17,
441 16, 16, 16, 16, 15, 14, 14, 13,
442 13, 12, 11, 10, 9, 8, 7, 6,
443 5, 4, 3, 2, 2, 3, 4, 5,
444 6, 7, 8, 9, 10, 12, 13, 14,
445 14, 15, 16, 17, 16, 19, 19, 19,
446 19, 19, 19, 19, 19, 19, 19, 19,
447 19, 19, 19, 19, 19, 19, 19, 19,
448 19, 19, 19, 19, 19, 19, 19, 19,
449 19, 19, 19, 19, 19, 19, 19, 19,
450 19, 19, 19, 19, 19, 19, 19, 19,
451 19
452];
453
454const ENV_BAL_1_5DB_F_BITS: &[u32; 49] = &[
455 0x3ffe2, 0x3ffe3, 0x3ffe4, 0x3ffe5, 0x3ffe6, 0x3ffe7, 0x3ffe8, 0x3ffe9,
456 0x3ffea, 0x3ffeb, 0x3ffec, 0x3ffed, 0x3ffee, 0x3ffef, 0x3fff0, 0x0fff7,
457 0x1fff0, 0x03ffc, 0x007fe, 0x007fc, 0x000fe, 0x0007e, 0x0000e, 0x00002,
458 0x00000, 0x00006, 0x0001e, 0x0003e, 0x001fe, 0x007fd, 0x00ffe, 0x07ffa,
459 0x0fff6, 0x3fff1, 0x3fff2, 0x3fff3, 0x3fff4, 0x3fff5, 0x3fff6, 0x3fff7,
460 0x3fff8, 0x3fff9, 0x3fffa, 0x3fffb, 0x3fffc, 0x3fffd, 0x3fffe, 0x7fffe,
461 0x7ffff
462];
463const ENV_BAL_1_5DB_F_LENS: &[u8; 49] = &[
464 18, 18, 18, 18, 18, 18, 18, 18,
465 18, 18, 18, 18, 18, 18, 18, 16,
466 17, 14, 11, 11, 8, 7, 4, 2,
467 1, 3, 5, 6, 9, 11, 12, 15,
468 16, 18, 18, 18, 18, 18, 18, 18,
469 18, 18, 18, 18, 18, 18, 18, 19,
470 19
471];
472const ENV_BAL_1_5DB_T_BITS: &[u32; 49] = &[
473 0x0ffe4, 0x0ffe5, 0x0ffe6, 0x0ffe7, 0x0ffe8, 0x0ffe9, 0x0ffea, 0x0ffeb,
474 0x0ffec, 0x0ffed, 0x0ffee, 0x0ffef, 0x0fff0, 0x0fff1, 0x0fff2, 0x0fff3,
475 0x0fff4, 0x0ffe2, 0x00ffc, 0x007fc, 0x001fe, 0x0007e, 0x0001e, 0x00006,
476 0x00000, 0x00002, 0x0000e, 0x0003e, 0x000fe, 0x007fd, 0x00ffd, 0x07ff0,
477 0x0ffe3, 0x0fff5, 0x0fff6, 0x0fff7, 0x0fff8, 0x0fff9, 0x0fffa, 0x1fff6,
478 0x1fff7, 0x1fff8, 0x1fff9, 0x1fffa, 0x1fffb, 0x1fffc, 0x1fffd, 0x1fffe,
479 0x1ffff
480];
481const ENV_BAL_1_5DB_T_LENS: &[u8; 49] = &[
482 16, 16, 16, 16, 16, 16, 16, 16,
483 16, 16, 16, 16, 16, 16, 16, 16,
484 16, 16, 12, 11, 9, 7, 5, 3,
485 1, 2, 4, 6, 8, 11, 12, 15,
486 16, 16, 16, 16, 16, 16, 16, 17,
487 17, 17, 17, 17, 17, 17, 17, 17,
488 17
489];
490
491const ENV_3_0DB_F_BITS: &[u32; 63] = &[
492 0xffff0, 0xffff1, 0xffff2, 0xffff3, 0xffff4, 0xffff5, 0xffff6, 0x3fff3,
493 0x7fff5, 0x7ffee, 0x7ffef, 0x7fff6, 0x3fff4, 0x3fff2, 0xffff7, 0x7fff0,
494 0x1fff5, 0x3fff0, 0x1fff4, 0x0fff7, 0x0fff6, 0x07ff8, 0x03ffb, 0x00ffd,
495 0x007fd, 0x003fd, 0x001fd, 0x000fd, 0x0003e, 0x0000e, 0x00002, 0x00000,
496 0x00006, 0x0001e, 0x000fc, 0x001fc, 0x003fc, 0x007fc, 0x00ffc, 0x01ffc,
497 0x03ffa, 0x07ff9, 0x07ffa, 0x0fff8, 0x0fff9, 0x1fff6, 0x1fff7, 0x3fff5,
498 0x3fff6, 0x3fff1, 0xffff8, 0x7fff1, 0x7fff2, 0x7fff3, 0xffff9, 0x7fff7,
499 0x7fff4, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe, 0xfffff
500];
501const ENV_3_0DB_F_LENS: &[u8; 63] = &[
502 20, 20, 20, 20, 20, 20, 20, 18,
503 19, 19, 19, 19, 18, 18, 20, 19,
504 17, 18, 17, 16, 16, 15, 14, 12,
505 11, 10, 9, 8, 6, 4, 2, 1,
506 3, 5, 8, 9, 10, 11, 12, 13,
507 14, 15, 15, 16, 16, 17, 17, 18,
508 18, 18, 20, 19, 19, 19, 20, 19,
509 19, 20, 20, 20, 20, 20, 20
510];
511const ENV_3_0DB_T_BITS: &[u32; 63] = &[
512 0x3ffed, 0x3ffee, 0x7ffde, 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3,
513 0x7ffe4, 0x7ffe5, 0x7ffe6, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb,
514 0x7ffec, 0x1fff4, 0x0fff7, 0x0fff9, 0x0fff8, 0x03ffb, 0x03ffa, 0x03ff8,
515 0x01ffa, 0x00ffc, 0x007fc, 0x000fe, 0x0003e, 0x0000e, 0x00002, 0x00000,
516 0x00006, 0x0001e, 0x0007e, 0x001fe, 0x007fd, 0x01ffb, 0x03ff9, 0x03ffc,
517 0x07ffa, 0x0fff6, 0x1fff5, 0x3ffec, 0x7ffed, 0x7ffee, 0x7ffef, 0x7fff0,
518 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6, 0x7fff7, 0x7fff8,
519 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe, 0x7ffff
520];
521const ENV_3_0DB_T_LENS: &[u8; 63] = &[
522 18, 18, 19, 19, 19, 19, 19, 19,
523 19, 19, 19, 19, 19, 19, 19, 19,
524 19, 17, 16, 16, 16, 14, 14, 14,
525 13, 12, 11, 8, 6, 4, 2, 1,
526 3, 5, 7, 9, 11, 13, 14, 14,
527 15, 16, 17, 18, 19, 19, 19, 19,
528 19, 19, 19, 19, 19, 19, 19, 19,
529 19, 19, 19, 19, 19, 19, 19
530];
531
532const ENV_BAL_3_0DB_F_BITS: &[u16; 25] = &[
533 0x1ff7, 0x1ff8, 0x1ff9, 0x1ffa, 0x1ffb, 0x3ff8, 0x3ff9, 0x07fc,
534 0x00fe, 0x007e, 0x000e, 0x0002, 0x0000, 0x0006, 0x001e, 0x003e,
535 0x01fe, 0x0ffa, 0x1ff6, 0x3ffa, 0x3ffb, 0x3ffc, 0x3ffd, 0x3ffe,
536 0x3fff
537];
538const ENV_BAL_3_0DB_F_LENS: &[u8; 25] = &[
539 13, 13, 13, 13, 13, 14, 14, 11,
540 8, 7, 4, 2, 1, 3, 5, 6,
541 9, 12, 13, 14, 14, 14, 14, 14,
542 14
543];
544const ENV_BAL_3_0DB_T_BITS: &[u16; 25] = &[
545 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x0ff8,
546 0x00fe, 0x007e, 0x000e, 0x0006, 0x0000, 0x0002, 0x001e, 0x003e,
547 0x01fe, 0x1ff9, 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe,
548 0x3fff
549];
550const ENV_BAL_3_0DB_T_LENS: &[u8; 25] = &[
551 13, 13, 13, 13, 13, 13, 13, 12,
552 8, 7, 4, 3, 1, 2, 5, 6,
553 9, 13, 13, 13, 13, 13, 13, 14,
554 14
555];
556
557const NOISE_3_0DB_T_BITS: &[u16; 63] = &[
558 0x1fce, 0x1fcf, 0x1fd0, 0x1fd1, 0x1fd2, 0x1fd3, 0x1fd4, 0x1fd5,
559 0x1fd6, 0x1fd7, 0x1fd8, 0x1fd9, 0x1fda, 0x1fdb, 0x1fdc, 0x1fdd,
560 0x1fde, 0x1fdf, 0x1fe0, 0x1fe1, 0x1fe2, 0x1fe3, 0x1fe4, 0x1fe5,
561 0x1fe6, 0x1fe7, 0x07f2, 0x00fd, 0x003e, 0x000e, 0x0006, 0x0000,
562 0x0002, 0x001e, 0x00fc, 0x03f8, 0x1fcc, 0x1fe8, 0x1fe9, 0x1fea,
563 0x1feb, 0x1fec, 0x1fcd, 0x1fed, 0x1fee, 0x1fef, 0x1ff0, 0x1ff1,
564 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x1ff9,
565 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe, 0x3fff
566];
567const NOISE_3_0DB_T_LENS: &[u8; 63] = &[
568 13, 13, 13, 13, 13, 13, 13, 13,
569 13, 13, 13, 13, 13, 13, 13, 13,
570 13, 13, 13, 13, 13, 13, 13, 13,
571 13, 13, 11, 8, 6, 4, 3, 1,
572 2, 5, 8, 10, 13, 13, 13, 13,
573 13, 13, 13, 13, 13, 13, 13, 13,
574 13, 13, 13, 13, 13, 13, 13, 13,
575 13, 13, 13, 13, 13, 14, 14
576];
577const NOISE_BAL_3_0DB_T_BITS: &[u8; 25] = &[
578 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3,
579 0xf4, 0xf5, 0x1c, 0x02, 0x00, 0x06, 0x3a, 0xf6,
580 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe,
581 0xff
582];
583const NOISE_BAL_3_0DB_T_LENS: &[u8; 25] = &[
584 8, 8, 8, 8, 8, 8, 8, 8,
585 8, 8, 5, 2, 1, 3, 6, 8,
586 8, 8, 8, 8, 8, 8, 8, 8, 8
587];