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