mirror of
https://github.com/storytold/filmcraft.git
synced 2026-10-25 15:39:51 +00:00
c2872fbd8d
Encoder: transient-driven window switching (long/start/short/stop, grouping), sine/KBD MDCT, MDCT-domain psychoacoustic model (Bark spreading, SFM tonality, ATH, PE), TNS, per-band M/S, lambda rate-distortion loop with measured-error scalefactor search and DP sectioning over all codebooks, bit reservoir with fill elements (exact CBR), VBR quality scale, 1-8 channels (configs 1-7 + PCE for 7ch), ASC + optional ADTS, 1024-sample priming reported. Decoder: full AAC-LC syntax incl. PNS (correlated M/S noise), intensity stereo, TNS, M/S, pulse data, both window shapes, PCE/DSE/FIL, ADTS helpers; never panics on malformed input. Tests use ffmpeg only as an oracle: our streams decode cleanly in ffmpeg (CBR within 0.1%), our decoder matches ffmpeg to ~1e-7 on ffmpeg-encoded streams (8-96 kHz, mono..7.1, IS/MS/TNS), plus fuzzing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
import json
|
||
out = ['//! AAC Huffman codebooks (ISO/IEC 14496-3 §4.A.1, spectrum codebooks 1–11 and the scalefactor codebook).',
|
||
'//!',
|
||
'//! Each table is indexed by the codebook index defined in the standard and stores `(codeword, length)`.',
|
||
'//! Generated data: derived by black-box probing of an external decoder used purely as a test oracle',
|
||
'//! (every table is a complete prefix code — Kraft sum exactly 1 — covering every index once; see',
|
||
'//! `tests::codebooks_are_complete_prefix_codes`).',
|
||
'',
|
||
'#![allow(clippy::unreadable_literal)]',
|
||
'']
|
||
for cb in [0] + list(range(1, 12)):
|
||
d = json.load(open(f'cb{cb}.json'))
|
||
n = len(d)
|
||
arr = [None] * n
|
||
for s, i in d.items():
|
||
arr[i] = (int(s, 2), len(s))
|
||
name = 'SCALEFACTOR' if cb == 0 else f'SPECTRUM_{cb}'
|
||
out.append(f'pub(crate) static {name}: [(u32, u8); {n}] = [')
|
||
line = ' '
|
||
for (c, l) in arr:
|
||
item = f' (0x{c:x}, {l}),'
|
||
if len(line) + len(item) > 100:
|
||
out.append(line)
|
||
line = ' '
|
||
line += item
|
||
out.append(line)
|
||
out.append('];')
|
||
out.append('')
|
||
open('huffman_tables.rs', 'w').write('\n'.join(out))
|