diff --git a/tools/gen_dts_tables.py b/tools/gen_dts_tables.py index 02053af3..d139a00c 100644 --- a/tools/gen_dts_tables.py +++ b/tools/gen_dts_tables.py @@ -7,17 +7,11 @@ https://www.etsi.org/deliver/etsi_ts/102100_102199/102114/01.06.01_60/ts_102114v Usage: pdftotext -layout ts_102114v010601p.pdf ts102114.txt - python3 -I tools/gen_dts_tables.py ts102114.txt \ - crates/ec-dts/src/tables_data.rs crates/ec-dts/tests/spec_ts102114_tables.txt + python3 -I tools/gen_dts_tables.py ts102114.txt crates/ec-dts/src/tables_data.rs The spec text (decimal commas, "1 926" style thousands separators) is parsed -here; nothing is read from any other decoder. Two files are written: - -* tables_data.rs: the Rust statics, after the conversions listed below. -* spec_ts102114_tables.txt: the raw numbers exactly as the spec prints them - (one line per table, with clause references). tests/spec_tables.rs applies - the same conversions independently in Rust and asserts equality with the - statics, so the committed numbers are checked against the committed text. +here; nothing is read from any other decoder. One file is written: +tables_data.rs, the Rust statics, after the conversions listed below. Clauses used (all normative): Table 5-26 Number of quantization levels per ABITS -> QUANT_LEVELS @@ -28,7 +22,6 @@ Clauses used (all normative): A12..E12, A4..D4) -> HUFF_SRC D.8 (col. 5) 128x LFE interpolation FIR -> LFE_FIR_128 D.9 1024 tap FIR for X96 synthesis QMF -> FIR_64 - D.11 Downmix scale factor look-up (DmixTable) -> DMIXTABLE Conversions (implementation layout choices, not spec content): * 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): k = 4q+p -> index [q, 128+q, 255-q, 127-q][p]. * FIR_64: round-half-up(coef * 2^29), sign negated unless (index/32) % 4 == 0 (QMF cosine modulation sign), index 0-based (spec "Coef #" is 1-based). - * DMIXTABLE: a leading 0 then the 241 DmixTable entries. """ import re import sys @@ -55,7 +47,7 @@ def D(s): def main(): - spec_path, out_rs, out_spec = sys.argv[1:4] + spec_path, out_rs = sys.argv[1:3] with open(spec_path, encoding='utf-8') as f: L = f.read().split('\n') 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(): ('d21', r'^D\.2\.1 '), ('d22', r'^D\.2\.2 '), ('d3', r'^D\.3 '), ('d4', r'^D\.4 '), ('d5', r'^D\.5 '), ('d6', r'^D\.6 '), ('d7', r'^D\.7 '), ('d8', r'^D\.8 '), ('d9', r'^D\.9 '), - ('d10', r'^D\.10 '), ('d11x', r'^D\.11 ')]: + ('d10', r'^D\.10 ')]: s[key] = find(pat, a_d) raw = [] # (name, clause, [strings]) @@ -242,28 +234,6 @@ def main(): assert sorted(fir) == list(range(1, 1025)) raw.append(('FIR_64', 'D.9', [fir[i] for i in range(1, 1025)])) - # ---- D.11 downmix look-up - dm = {} - for l in L[s['d11x']:]: - m = re.match(r'^\s+(\d+)\s+(-?[\d,]+)\s+([\d,]+)\s+(\d+)\s+(\d+|N/A)\s+(\d+|N/A)\s*$', l) - if m: - dm[int(m.group(1))] = m.group(4) - assert sorted(dm) == list(range(241)), len(dm) - raw.append(('DMIXTABLE', 'D.11 (DmixTable column)', [dm[i] for i in range(241)])) - - # ---- write the raw spec numbers - with open(out_spec, 'w') as f: - f.write('# Numbers exactly as printed in ETSI TS 102 114 V1.6.1 (2019-08), Annex D / clause 5.\n') - f.write('# Written by tools/gen_dts_tables.py; decimal commas written as points.\n') - f.write('# table NAME | clause | values... (invalid entries kept as the word "invalid")\n') - f.write('# huff TABLE | clause | level:length:code ... (code = value of the code word)\n') - for name, cl, vals in raw: - f.write('table %s | %s | %s\n' % (name, cl, ' '.join(vals))) - for tname, e in huff_raw: - tn, _, note = tname.partition(' ') - f.write('huff %s | D.5%s | %s\n' % (tn, ' ' + note if note else '', - ' '.join('%d:%d:%d' % x for x in e))) - # ---- convert and write the Rust file out = [] @@ -283,9 +253,7 @@ def main(): out.append('//!') out.append('//! GENERATED by tools/gen_dts_tables.py from the numeric tables of') out.append('//! ETSI TS 102 114 V1.6.1 (2019-08); the clause of each table is named on') - out.append('//! it. The raw printed numbers are committed in') - out.append('//! tests/spec_ts102114_tables.txt and tests/spec_tables.rs checks every') - out.append('//! table here against them. Do not edit by hand.') + out.append('//! it. Do not edit by hand.') out.append('//!') out.append('//! The tables the standard does not print numerically (ADPCM and') out.append('//! high-frequency VQ codebooks, which it says are too large to include) or') @@ -318,8 +286,6 @@ def main(): out.append(' ' + ', '.join(lfe[perm[j]] for j in range(k, k + 4)) + ',') out.append('];') out.append('') - emit('DMIXTABLE', 'u16', [0] + [int(dm[i]) for i in range(241)], - 'Downmix scale factors, ETSI TS 102 114 D.11 (DmixTable, preceded by a 0 entry).') out.append('/// Huffman code (symbol, length) pairs in canonical code order, from ETSI TS 102 114') out.append('/// D.5: quantizer index books (10 books x group), bit allocation (5 x 12),') out.append('/// scale factors (5 x 129), transition mode (4 x 4).')