edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
| 1 | #!/usr/bin/env python3 |
| 2 | """Generate crates/ec-dts/src/tables_data.rs from ETSI TS 102 114. |
| 3 | |
| 4 | Source: ETSI TS 102 114 V1.6.1 (2019-08), "DTS Coherent Acoustics; Core and |
| 5 | Extensions with Additional Profiles", free from |
| 6 | https://www.etsi.org/deliver/etsi_ts/102100_102199/102114/01.06.01_60/ts_102114v010601p.pdf |
| 7 | |
| 8 | Usage: |
| 9 | pdftotext -layout ts_102114v010601p.pdf ts102114.txt |
| 10 | python3 -I tools/gen_dts_tables.py ts102114.txt \ |
| 11 | crates/ec-dts/src/tables_data.rs crates/ec-dts/tests/spec_ts102114_tables.txt |
| 12 | |
| 13 | The spec text (decimal commas, "1 926" style thousands separators) is parsed |
| 14 | here; nothing is read from any other decoder. Two files are written: |
| 15 | |
| 16 | * tables_data.rs: the Rust statics, after the conversions listed below. |
| 17 | * spec_ts102114_tables.txt: the raw numbers exactly as the spec prints them |
| 18 | (one line per table, with clause references). tests/spec_tables.rs applies |
| 19 | the same conversions independently in Rust and asserts equality with the |
| 20 | statics, so the committed numbers are checked against the committed text. |
| 21 | |
| 22 | Clauses used (all normative): |
| 23 | Table 5-26 Number of quantization levels per ABITS -> QUANT_LEVELS |
| 24 | Table 5-27 Scale factor adjustment index (ADJ) -> SCALE_FACTOR_ADJ |
| 25 | D.1.1, D.1.2 6-bit / 7-bit scale factor quantization -> SCALE_FACTOR_QUANT6/7 |
| 26 | D.2.1, D.2.2 Lossy / lossless quantization step sizes -> LOSSY_QUANT, LOSSLESS_QUANT |
| 27 | D.5.x Huffman code books (A3 .. G129, SA129..SE129, |
| 28 | A12..E12, A4..D4) -> HUFF_SRC |
| 29 | D.8 (col. 5) 128x LFE interpolation FIR -> LFE_FIR_128 |
| 30 | D.9 1024 tap FIR for X96 synthesis QMF -> FIR_64 |
| 31 | D.11 Downmix scale factor look-up (DmixTable) -> DMIXTABLE |
| 32 | |
| 33 | Conversions (implementation layout choices, not spec content): |
| 34 | * invalid entries -> 0; tables are padded to their power-of-two length with 0. |
| 35 | * QUANT_LEVELS: ABITS 0 -> 1 (spec: 0, never used as a divisor here); |
| 36 | "33 or 32", "65 or 64", "129 or 128" -> the power of two. |
| 37 | * HUFF_SRC: codes sorted by left-aligned code value (the spec codes are |
| 38 | canonical), stored as (symbol, length) with symbol = level + offset where |
| 39 | offset is 1,2,3,4,6,8,12,16,32,64 for the 3..129 level books, ABITS-1 for |
| 40 | the 12 level books, level for the 4 level books, level+64 for SA..SE129. |
| 41 | Books are laid out in the order consumed by huff.rs. |
| 42 | * LFE_FIR_128: spec column (512 symmetric taps) read in the polyphase order |
| 43 | k = 4q+p -> index [q, 128+q, 255-q, 127-q][p]. |
| 44 | * FIR_64: round-half-up(coef * 2^29), sign negated unless (index/32) % 4 == 0 |
| 45 | (QMF cosine modulation sign), index 0-based (spec "Coef #" is 1-based). |
| 46 | * DMIXTABLE: a leading 0 then the 241 DmixTable entries. |
| 47 | """ |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | return |
| 55 | |
| 56 | |
| 57 | |
| 58 | , , = |
| 59 | |
| 60 | = |
| 61 | assert , |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | return |
| 67 | |
| 68 | |
| 69 | # ---- section boundaries (annex D, after the table of contents) |
| 70 | = |
| 71 | = |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | = |
| 78 | |
| 79 | = # (name, clause, [strings]) |
| 80 | |
| 81 | # ---- Table 5-26 (quantization levels) |
| 82 | = |
| 83 | = |
| 84 | |
| 85 | = |
| 86 | |
| 87 | = |
| 88 | assert == , |
| 89 | |
| 90 | |
| 91 | # ---- Table 5-27 (ADJ) |
| 92 | = |
| 93 | = |
| 94 | |
| 95 | = |
| 96 | |
| 97 | |
| 98 | assert == 4 |
| 99 | |
| 100 | |
| 101 | # ---- D.1.1 / D.1.2 scale factor quantization (index, level, dB triples) |
| 102 | |
| 103 | = |
| 104 | |
| 105 | = |
| 106 | |
| 107 | continue |
| 108 | |
| 109 | |
| 110 | = |
| 111 | assert == , |
| 112 | return |
| 113 | |
| 114 | |
| 115 | |
| 116 | # ---- D.2.x step sizes (index, step x 2^22, nominal) |
| 117 | |
| 118 | = |
| 119 | |
| 120 | = |
| 121 | |
| 122 | = |
| 123 | assert == , |
| 124 | return |
| 125 | |
| 126 | |
| 127 | |
| 128 | # ---- D.5 Huffman code books |
| 129 | = # table name -> [(level, length, code)] |
| 130 | = # in document order |
| 131 | = 0 |
| 132 | = |
| 133 | = False |
| 134 | |
| 135 | = |
| 136 | |
| 137 | # titles on consecutive lines (A33 / B33 C33) form one block |
| 138 | = + |
| 139 | = True |
| 140 | = |
| 141 | |
| 142 | assert not in |
| 143 | = |
| 144 | |
| 145 | continue |
| 146 | = |
| 147 | |
| 148 | continue |
| 149 | = |
| 150 | = 0 |
| 151 | |
| 152 | , , = , , |
| 153 | += 3 |
| 154 | |
| 155 | += |
| 156 | += 1 |
| 157 | |
| 158 | # a ragged first row (table A33 starts one line before B33 and C33) |
| 159 | # (and its tail: the first column has ended, the others have one row left) |
| 160 | = False |
| 161 | # one table printed in several column segments |
| 162 | |
| 163 | continue |
| 164 | assert == or , |
| 165 | = False |
| 166 | = |
| 167 | |
| 168 | |
| 169 | # The printed Table D65 (D.5.11) stops at level +-30: the rows for +-31 and |
| 170 | # +-32 are missing from the standard's text. They are the only symbols |
| 171 | # absent, so their codes are the unassigned part of the code space, which |
| 172 | # must be exactly four 15-bit words; following the printed pairs (the |
| 173 | # positive level has the code one above its negative, and a larger |level| |
| 174 | # has the lower code) they are -32, 32, -31, 31 in ascending order. |
| 175 | = |
| 176 | assert == , |
| 177 | = |
| 178 | |
| 179 | |
| 180 | = |
| 181 | assert == , |
| 182 | |
| 183 | |
| 184 | # Table D129 (D.5.12) prints level -37 as "37" (sign lost), so +37 appears |
| 185 | # twice; as in every other printed pair the negative level has the lower code. |
| 186 | = |
| 187 | = |
| 188 | assert == 2 and == and == + 1, |
| 189 | = |
| 190 | |
| 191 | = |
| 192 | = |
| 193 | assert == 1, |
| 194 | assert == , |
| 195 | |
| 196 | |
| 197 | = |
| 198 | assert == , |
| 199 | return |
| 200 | |
| 201 | = # (table name, symbol offset) in huff.rs consumption order |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | # level column is ABITS 1..12 -> symbol ABITS-1 |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | assert == , ^ |
| 214 | = |
| 215 | = |
| 216 | |
| 217 | |
| 218 | = |
| 219 | assert == 12 |
| 220 | |
| 221 | = |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | = |
| 227 | assert == 2709, |
| 228 | |
| 229 | # ---- D.8 128x LFE FIR (last column) and D.9 FIR_64 |
| 230 | = |
| 231 | |
| 232 | = |
| 233 | |
| 234 | |
| 235 | assert == 512 |
| 236 | |
| 237 | |
| 238 | = |
| 239 | |
| 240 | |
| 241 | = |
| 242 | assert == |
| 243 | |
| 244 | |
| 245 | # ---- D.11 downmix look-up |
| 246 | = |
| 247 | |
| 248 | = |
| 249 | |
| 250 | = |
| 251 | assert == , |
| 252 | |
| 253 | |
| 254 | # ---- write the raw spec numbers |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | , , = |
| 264 | |
| 265 | |
| 266 | |
| 267 | # ---- convert and write the Rust file |
| 268 | = |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | = |
| 280 | return + * |
| 281 | = |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | = |
| 310 | |
| 311 | |
| 312 | |
| 313 | = |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 |