U12: dts generator stops emitting DMIXTABLE (dead) and the spec-text dump whose test was removed; keeps generated tables_data.rs reproducible
Browse files at this commit3bd4fa1ad2f62686753d63494475795b6c321515Parent: 9ec72651 changed file +6 -40
- tools/gen_dts_tables.py +6 -40
tools/gen_dts_tables.pymodified+6 -40
| @@ -7,17 +7,11 @@ https://www.etsi.org/deliver/etsi_ts/102100_102199/102114/01.06.01_60/ts_102114v | |||
| 7 | 7 | ||
| 8 | Usage: | 8 | Usage: |
| 9 | pdftotext -layout ts_102114v010601p.pdf ts102114.txt | 9 | pdftotext -layout ts_102114v010601p.pdf ts102114.txt |
| 10 | - python3 -I tools/gen_dts_tables.py ts102114.txt \ | 10 | + python3 -I tools/gen_dts_tables.py ts102114.txt crates/ec-dts/src/tables_data.rs |
| 11 | - crates/ec-dts/src/tables_data.rs crates/ec-dts/tests/spec_ts102114_tables.txt | ||
| 12 | 11 | ||
| 13 | The spec text (decimal commas, "1 926" style thousands separators) is parsed | 12 | 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: | 13 | +here; nothing is read from any other decoder. One file is written: |
| 15 | - | 14 | +tables_data.rs, the Rust statics, after the conversions listed below. |
| 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 | 15 | ||
| 22 | Clauses used (all normative): | 16 | Clauses used (all normative): |
| 23 | Table 5-26 Number of quantization levels per ABITS -> QUANT_LEVELS | 17 | Table 5-26 Number of quantization levels per ABITS -> QUANT_LEVELS |
| @@ -28,7 +22,6 @@ Clauses used (all normative): | |||
| 28 | A12..E12, A4..D4) -> HUFF_SRC | 22 | A12..E12, A4..D4) -> HUFF_SRC |
| 29 | D.8 (col. 5) 128x LFE interpolation FIR -> LFE_FIR_128 | 23 | D.8 (col. 5) 128x LFE interpolation FIR -> LFE_FIR_128 |
| 30 | D.9 1024 tap FIR for X96 synthesis QMF -> FIR_64 | 24 | D.9 1024 tap FIR for X96 synthesis QMF -> FIR_64 |
| 31 | - D.11 Downmix scale factor look-up (DmixTable) -> DMIXTABLE | ||
| 32 | 25 | ||
| 33 | Conversions (implementation layout choices, not spec content): | 26 | Conversions (implementation layout choices, not spec content): |
| 34 | * invalid entries -> 0; tables are padded to their power-of-two length with 0. | 27 | * invalid entries -> 0; tables are padded to their power-of-two length with 0. |
| @@ -43,7 +36,6 @@ Conversions (implementation layout choices, not spec content): | |||
| 43 | k = 4q+p -> index [q, 128+q, 255-q, 127-q][p]. | 36 | 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 | 37 | * 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). | 38 | (QMF cosine modulation sign), index 0-based (spec "Coef #" is 1-based). |
| 46 | - * DMIXTABLE: a leading 0 then the 241 DmixTable entries. | ||
| 47 | """ | 39 | """ |
| 48 | import re | 40 | import re |
| 49 | import sys | 41 | import sys |
| @@ -55,7 +47,7 @@ def D(s): | |||
| 55 | 47 | ||
| 56 | 48 | ||
| 57 | def main(): | 49 | def main(): |
| 58 | - spec_path, out_rs, out_spec = sys.argv[1:4] | 50 | + spec_path, out_rs = sys.argv[1:3] |
| 59 | with open(spec_path, encoding='utf-8') as f: | 51 | with open(spec_path, encoding='utf-8') as f: |
| 60 | L = f.read().split('\n') | 52 | L = f.read().split('\n') |
| 61 | assert any('V1.6.1 (2019-08)' in l for l in L[:3000]), 'spec is not V1.6.1' | 53 | assert any('V1.6.1 (2019-08)' in l for l in L[:3000]), 'spec is not V1.6.1' |
| @@ -73,7 +65,7 @@ def main(): | |||
| 73 | ('d21', r'^D\.2\.1 '), ('d22', r'^D\.2\.2 '), ('d3', r'^D\.3 '), | 65 | ('d21', r'^D\.2\.1 '), ('d22', r'^D\.2\.2 '), ('d3', r'^D\.3 '), |
| 74 | ('d4', r'^D\.4 '), ('d5', r'^D\.5 '), ('d6', r'^D\.6 '), | 66 | ('d4', r'^D\.4 '), ('d5', r'^D\.5 '), ('d6', r'^D\.6 '), |
| 75 | ('d7', r'^D\.7 '), ('d8', r'^D\.8 '), ('d9', r'^D\.9 '), | 67 | ('d7', r'^D\.7 '), ('d8', r'^D\.8 '), ('d9', r'^D\.9 '), |
| 76 | - ('d10', r'^D\.10 '), ('d11x', r'^D\.11 ')]: | 68 | + ('d10', r'^D\.10 ')]: |
| 77 | s[key] = find(pat, a_d) | 69 | s[key] = find(pat, a_d) |
| 78 | 70 | ||
| 79 | raw = [] # (name, clause, [strings]) | 71 | raw = [] # (name, clause, [strings]) |
| @@ -242,28 +234,6 @@ def main(): | |||
| 242 | assert sorted(fir) == list(range(1, 1025)) | 234 | assert sorted(fir) == list(range(1, 1025)) |
| 243 | raw.append(('FIR_64', 'D.9', [fir[i] for i in range(1, 1025)])) | 235 | raw.append(('FIR_64', 'D.9', [fir[i] for i in range(1, 1025)])) |
| 244 | 236 | ||
| 245 | - # ---- D.11 downmix look-up | ||
| 246 | - dm = {} | ||
| 247 | - for l in L[s['d11x']:]: | ||
| 248 | - m = re.match(r'^\s+(\d+)\s+(-?[\d,]+)\s+([\d,]+)\s+(\d+)\s+(\d+|N/A)\s+(\d+|N/A)\s*$', l) | ||
| 249 | - if m: | ||
| 250 | - dm[int(m.group(1))] = m.group(4) | ||
| 251 | - assert sorted(dm) == list(range(241)), len(dm) | ||
| 252 | - raw.append(('DMIXTABLE', 'D.11 (DmixTable column)', [dm[i] for i in range(241)])) | ||
| 253 | - | ||
| 254 | - # ---- write the raw spec numbers | ||
| 255 | - with open(out_spec, 'w') as f: | ||
| 256 | - f.write('# Numbers exactly as printed in ETSI TS 102 114 V1.6.1 (2019-08), Annex D / clause 5.\n') | ||
| 257 | - f.write('# Written by tools/gen_dts_tables.py; decimal commas written as points.\n') | ||
| 258 | - f.write('# table NAME | clause | values... (invalid entries kept as the word "invalid")\n') | ||
| 259 | - f.write('# huff TABLE | clause | level:length:code ... (code = value of the code word)\n') | ||
| 260 | - for name, cl, vals in raw: | ||
| 261 | - f.write('table %s | %s | %s\n' % (name, cl, ' '.join(vals))) | ||
| 262 | - for tname, e in huff_raw: | ||
| 263 | - tn, _, note = tname.partition(' ') | ||
| 264 | - f.write('huff %s | D.5%s | %s\n' % (tn, ' ' + note if note else '', | ||
| 265 | - ' '.join('%d:%d:%d' % x for x in e))) | ||
| 266 | - | ||
| 267 | # ---- convert and write the Rust file | 237 | # ---- convert and write the Rust file |
| 268 | out = [] | 238 | out = [] |
| 269 | 239 | ||
| @@ -283,9 +253,7 @@ def main(): | |||
| 283 | out.append('//!') | 253 | out.append('//!') |
| 284 | out.append('//! GENERATED by tools/gen_dts_tables.py from the numeric tables of') | 254 | out.append('//! GENERATED by tools/gen_dts_tables.py from the numeric tables of') |
| 285 | out.append('//! ETSI TS 102 114 V1.6.1 (2019-08); the clause of each table is named on') | 255 | out.append('//! ETSI TS 102 114 V1.6.1 (2019-08); the clause of each table is named on') |
| 286 | - out.append('//! it. The raw printed numbers are committed in') | 256 | + out.append('//! it. Do not edit by hand.') |
| 287 | - out.append('//! tests/spec_ts102114_tables.txt and tests/spec_tables.rs checks every') | ||
| 288 | - out.append('//! table here against them. Do not edit by hand.') | ||
| 289 | out.append('//!') | 257 | out.append('//!') |
| 290 | out.append('//! The tables the standard does not print numerically (ADPCM and') | 258 | out.append('//! The tables the standard does not print numerically (ADPCM and') |
| 291 | out.append('//! high-frequency VQ codebooks, which it says are too large to include) or') | 259 | out.append('//! high-frequency VQ codebooks, which it says are too large to include) or') |
| @@ -318,8 +286,6 @@ def main(): | |||
| 318 | out.append(' ' + ', '.join(lfe[perm[j]] for j in range(k, k + 4)) + ',') | 286 | out.append(' ' + ', '.join(lfe[perm[j]] for j in range(k, k + 4)) + ',') |
| 319 | out.append('];') | 287 | out.append('];') |
| 320 | out.append('') | 288 | out.append('') |
| 321 | - emit('DMIXTABLE', 'u16', [0] + [int(dm[i]) for i in range(241)], | ||
| 322 | - 'Downmix scale factors, ETSI TS 102 114 D.11 (DmixTable, preceded by a 0 entry).') | ||
| 323 | out.append('/// Huffman code (symbol, length) pairs in canonical code order, from ETSI TS 102 114') | 289 | out.append('/// Huffman code (symbol, length) pairs in canonical code order, from ETSI TS 102 114') |
| 324 | out.append('/// D.5: quantizer index books (10 books x group), bit allocation (5 x 12),') | 290 | out.append('/// D.5: quantizer index books (10 books x group), bit allocation (5 x 12),') |
| 325 | out.append('/// scale factors (5 x 129), transition mode (4 x 4).') | 291 | out.append('/// scale factors (5 x 129), transition mode (4 x 4).') |