edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB682c080Tahinli2 months ago2434 commits
| 1 | #!/usr/bin/env python3 |
| 2 | """Dev-time fixture generator for the SBR payload parser test (`sbr_payload.rs`). |
| 3 | |
| 4 | Reuses `sbrtables.py`'s validated header/band/codebook machinery and its |
| 5 | `recipe_config`/`plan`/`sbr_bits` writer verbatim for FIXFIX fixtures (those |
| 6 | paths are already proven against the reference decoder by the table |
| 7 | derivation). Adds a grid writer for the three classes `sbrtables.py` never |
| 8 | needed (FIXVAR/VARFIX/VARVAR) and a non-coupled CPE path, both validated here |
| 9 | against the same byte-accounting oracle before being trusted. |
| 10 | |
| 11 | Prints Rust byte-array literals plus the expected parsed fields, pasted |
| 12 | directly into `crates/ec-aac/src/sbr_payload.rs`'s test module. |
| 13 | """ |
| 14 | |
| 15 | |
| 16 | |
| 17 | = |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | = 7 # 44100 Hz core -> 44100 Hz SBR rate... (SBR_RATE_FOR_SF[7] = 44100) |
| 24 | = |
| 25 | |
| 26 | # --------------------------------------------------------------- grid writer |
| 27 | |
| 28 | |
| 29 | """`ceil(log2(num_env+1))`: width of `bs_pointer`, which ranges `0..=num_env`.""" |
| 30 | = 1 |
| 31 | |
| 32 | += 1 |
| 33 | return |
| 34 | |
| 35 | |
| 36 | |
| 37 | """Writes one `sbr_grid()`; returns `(num_env, freq_res_list)`. |
| 38 | |
| 39 | Field widths validated against the reference decoder's byte accounting in |
| 40 | `gridcheck.py` (kept alongside this file): FIXVAR/VARFIX/VARVAR all use |
| 41 | `var_bord`(2 bits), `bs_num_rel`(2 bits) and `bs_rel_bord`(2 bits, value |
| 42 | `2*n+2`), agreeing with the reference parser's consumed byte count for |
| 43 | every `num_rel` combination whose total envelope count lands in `2..=5` |
| 44 | (below or above that the reference decoder takes a different, unmeasured |
| 45 | path -- so the Rust parser refuses those rather than guessing). Between |
| 46 | the relative borders and `bs_freq_res` sits `bs_pointer` |
| 47 | (`ptr_bits(num_env)` bits) -- confirmed present by `sbrgrid_probe.py` |
| 48 | against a non-uniform freq_res list (a uniform one hides it entirely, |
| 49 | which is how earlier fixtures missed it). FIXVAR alone transmits |
| 50 | `bs_freq_res` in reverse time order (probed the same way); VARFIX/VARVAR |
| 51 | transmit it forward. |
| 52 | """ |
| 53 | = |
| 54 | |
| 55 | |
| 56 | = |
| 57 | |
| 58 | = |
| 59 | |
| 60 | return , * |
| 61 | |
| 62 | |
| 63 | = |
| 64 | |
| 65 | = + 1 |
| 66 | |
| 67 | |
| 68 | |
| 69 | = |
| 70 | = |
| 71 | |
| 72 | |
| 73 | return , |
| 74 | # VARVAR |
| 75 | |
| 76 | |
| 77 | = |
| 78 | = |
| 79 | |
| 80 | |
| 81 | = + + 1 |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | = |
| 88 | |
| 89 | |
| 90 | return , |
| 91 | |
| 92 | |
| 93 | |
| 94 | """Like `sbrtables.sbr_bits`, but the grid can be any of the four classes |
| 95 | and a CPE need not be coupled (two independent grids/invf in that case).""" |
| 96 | = |
| 97 | = |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | = == |
| 123 | = 1 |
| 124 | |
| 125 | |
| 126 | |
| 127 | = |
| 128 | |
| 129 | |
| 130 | = |
| 131 | |
| 132 | , = |
| 133 | = |
| 134 | = |
| 135 | |
| 136 | , = , |
| 137 | |
| 138 | , = |
| 139 | |
| 140 | |
| 141 | |
| 142 | = |
| 143 | = 1 |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | # sbr_channel_pair_element's envelope/noise interleave depends on |
| 156 | # bs_coupling: COUPLED reads sbr_envelope(ch)/sbr_noise(ch) interleaved |
| 157 | # per channel; UNCOUPLED reads two separate passes -- both channels' |
| 158 | # sbr_envelope(), then both channels' sbr_noise() (matches the Rust |
| 159 | # parser's `separated` split in sbr_payload.rs). |
| 160 | |
| 161 | = 1 |
| 162 | = |
| 163 | = |
| 164 | = 0 |
| 165 | |
| 166 | = |
| 167 | |
| 168 | = |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | = 1 |
| 178 | = |
| 179 | = 1 |
| 180 | |
| 181 | |
| 182 | = |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | = and not and == 2 |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | = |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | return |
| 213 | |
| 214 | |
| 215 | |
| 216 | = |
| 217 | |
| 218 | = |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | return |
| 230 | |
| 231 | |
| 232 | |
| 233 | """A header whose bands are n_high=2, n_low=1, n_q=1: one band at |
| 234 | `freq_res=0`, two at `freq_res=1`, no Huffman codewords needed for a |
| 235 | DF-coded (raw-only) envelope or noise floor.""" |
| 236 | = |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | assert , |
| 242 | return |
| 243 | |
| 244 | |
| 245 | |
| 246 | = |
| 247 | = // 8 |
| 248 | = b |
| 249 | = |
| 250 | = |
| 251 | # "channel element 0.1 is not allocated" fires on every mono SCE probe |
| 252 | # regardless of success (dead-end noted in the project ledger); the byte |
| 253 | # count against the caller's own prediction is the real discriminator. |
| 254 | = is not None and |
| 255 | |
| 256 | return , |
| 257 | |
| 258 | |
| 259 | |
| 260 | return + + |
| 261 | |
| 262 | |
| 263 | |
| 264 | """Prints the `sbr_extension_data()` payload alone (no ADTS/core/FIL |
| 265 | framing), byte-packed, plus the exact bit count it should consume: this |
| 266 | is the entry point `sbr_payload.rs`'s parser actually reads.""" |
| 267 | = |
| 268 | = |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | = |
| 275 | , = |
| 276 | |
| 277 | |
| 278 | |
| 279 | # FIXVAR, SCE, all-DF (band=1, no Huffman), 3 envelopes. |
| 280 | = |
| 281 | = |
| 282 | , = |
| 283 | assert |
| 284 | |
| 285 | |
| 286 | # VARFIX, SCE, all-DF. |
| 287 | = |
| 288 | , = |
| 289 | assert |
| 290 | |
| 291 | |
| 292 | # VARVAR, SCE, all-DF: (var_bord0=1, var_bord1=1, num_rel0=1, num_rel1=0) |
| 293 | # measured bit-exact against the reference decoder in the sweep this |
| 294 | # module's tests reproduce. num_env=3 (any nr0+nr1 split) measured off by |
| 295 | # one byte for a reason not tracked further (see ledger); num_env=2 here |
| 296 | # is exact and passes the decoder's own border-monotonicity check. |
| 297 | = |
| 298 | |
| 299 | , = |
| 300 | assert |
| 301 | |
| 302 | |
| 303 | # FIXFIX, SCE, DT second envelope: env0 raw, env1 DT via ENV15_T[0]=(2,0,0) delta 0. |
| 304 | = |
| 305 | = |
| 306 | = # ENV15_T first codeword, delta 0 |
| 307 | = # NOISE_T first codeword, delta 0 |
| 308 | , = |
| 309 | assert |
| 310 | |
| 311 | |
| 312 | # Non-coupled CPE, FIXFIX, both channels DF raw-only. |
| 313 | = |
| 314 | = |
| 315 | , = |
| 316 | assert |
| 317 | |
| 318 | |
| 319 | # Header + extension data (FIXFIX, 1 envelope, extended=1 -> 1 byte of padding). |
| 320 | = |
| 321 | , = |
| 322 | assert |
| 323 | |
| 324 | |
| 325 | # Headerless frame reusing the prior header: verified as a lead(header=1) |
| 326 | # + tail(header=0) pair against the reference decoder's own byte |
| 327 | # accounting (the tail's own "Expected to read" diagnostic is masked by |
| 328 | # a decoder-side mono/implicit-stereo quirk downstream of it -- see |
| 329 | # ledger -- so this checks the LEAD frame's consumption against the |
| 330 | # oracle and the TAIL frame's body via this module's own, independently |
| 331 | # cross-checked bit accounting only). |
| 332 | = |
| 333 | = |
| 334 | , = |
| 335 | assert |
| 336 | |
| 337 | |
| 338 | |
| 339 | # CPE with coupling=1, real balance Huffman book (ENVB15_T) via the |
| 340 | # existing, already-verified recipe. |
| 341 | |
| 342 | = |
| 343 | |
| 344 | |
| 345 | = |
| 346 | return |
| 347 | |
| 348 | = |
| 349 | = |
| 350 | |
| 351 | = |
| 352 | assert |
| 353 | , = |
| 354 | , = |
| 355 | # A codeword partway through the book, not the first (delta 0) one. |
| 356 | , , = |
| 357 | = |
| 358 | = |
| 359 | assert is not None |
| 360 | = |
| 361 | , = |
| 362 | assert |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 |