forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 5591c0e1dfbc7e0137f2c8d4fb224bfcb05d01baFiltered to crates/ec-aac/src/encode.rsClear filter

2026-08-27

perf(aac): kill the rate loop's powf hot pathAhmet Kaan Gümüş · d08a7f7
perf(aac): kill the rate loop's powf hot path

Profiling encode_frame (perf record --call-graph dwarf on a 10s real-PCM
loop) showed 82% of wall time in libm's powf_fma, all reached through
write_frame's cost closure -> quantise -> band_noise/quantise_one:
band_noise's per-band scalefactor search called band_noise (two powf
calls per coefficient) up to ~255 times per band, linearly walking every
candidate level.

- quantise_one's x^0.75 -> sqrt(x)*sqrt(sqrt(x)): two sqrtf beat one powf.
- band_noise's q^(4/3) -> a precomputed lookup table over q's bounded
  (MAX_QUANT) integer range, since q is always an integer there.
- the scalefactor search itself -> bisection, since the algorithm already
  assumed monotonic noise-vs-level to break on first overage; that's
  exactly what a binary search needs, and it drops ~255 candidate levels
  to ~8 per band.

ec-bench's aac encode row: 3.54x -> 37.83x realtime (10.9x on a
standalone 10s-PCM loop, matching the profiling harness). All ec-aac
tests green.

Also fixes crates/ec-aac/tests/oracle.rs's esds_asc helper, which scanned
raw bytes for a literal 0x05 instead of walking the MPEG-4 descriptor
tree by tag+length: a legitimate byte in the DecoderConfigDescriptor's
avgBitrate field (which shifted with the quantiser's new floating-point
path) could and did false-positive as the DecSpecificInfoTag.

2026-08-20

2026-08-14

feat(aac): AAC-LC decoder, encoder and rusty_aac shimAhmet Kaan Gümüş · 9a848b4
feat(aac): AAC-LC decoder, encoder and rusty_aac shim

Decoder covers AAC-LC end to end: AudioSpecificConfig and ADTS framing,
all four window sequences and both window shapes, section and scalefactor
data, every spectral codebook including the escape one, pulse data, TNS,
M/S and intensity stereo, PNS, and SCE/CPE/LFE/DSE/PCE/FIL elements.
Output is film order FL, FR, FC, LFE, BL, BR (SL, SR), which is the order
the downmix in this family folds, so a 5.1 track needs no caller-side
permutation. HE-AAC's SBR is not reconstructed: such a stream decodes to
its AAC-LC core and reports the core rate rather than claiming the
extension's.

Encoder is a full two-loop search: 2048-point FFT masking with spectral
flatness for tonality, bark-ish spreading, a relative hearing-threshold
floor, transient-driven window switching, per-band mid/side, exact
Huffman bit counts for codebook choice, and a bit reservoir against a CBR
target. Both ADTS and bare raw_data_block output.

The normative tables were derived rather than transcribed: access units
with a chosen spectral payload were decoded by a reference decoder and
read back through the inverse MDCT, which enumerates each codebook by a
binary tree walk. Every one came out with a Kraft sum of exactly 1 and
the entry count the standard prescribes.

forbid(unsafe_code) in both crates.