Commits
Commits on
e2fa4f01a3b96f73a4cbb02db75df82b0790d686Filtered to crates/ec-aac/src/encode.rsClear filter2026-09-13
perf(aac): the outer rate loop warm-starts at last frame's working point and gallops to the edge -- bits fall monotonically as the offset rises, so fits-the-budget is true on an upper interval and the full-range bisection and a gallop from the previous frame's answer find the same left edge; steady state costs a probe at 240, one at the warm offset and two-to-three bracket probes instead of nine (warm_offset field, AacEncoder). The requant passes skip bands the +/-60 delta chain left alone (dirty vector) -- measured neutral on its own, kept because it is the same class of work the noise memo already avoids. Byte-identical on stereo 256k and 5.1 512k vs the base build; stereo 59.1 -> 103.1x RT (1.31x rusty_aac's 78.4x single-thread, was 0.44x at the lane start), 5.1 21.8 -> 44.3x (1.44x rusty's 30.8x); ec-aac suite green 75/75; quality rows unchanged (0.8857/0.9827/0.9829 worst-channel vs the same synthetic program, ec still clearing rusty on every one)Ahmet Kaan Gümüş · 17417bc
perf(aac): the outer rate loop warm-starts at last frame's working point and gallops to the edge -- bits fall monotonically as the offset rises, so fits-the-budget is true on an upper interval and the full-range bisection and a gallop from the previous frame's answer find the same left edge; steady state costs a probe at 240, one at the warm offset and two-to-three bracket probes instead of nine (warm_offset field, AacEncoder). The requant passes skip bands the +/-60 delta chain left alone (dirty vector) -- measured neutral on its own, kept because it is the same class of work the noise memo already avoids. Byte-identical on stereo 256k and 5.1 512k vs the base build; stereo 59.1 -> 103.1x RT (1.31x rusty_aac's 78.4x single-thread, was 0.44x at the lane start), 5.1 21.8 -> 44.3x (1.44x rusty's 30.8x); ec-aac suite green 75/75; quality rows unchanged (0.8857/0.9827/0.9829 worst-channel vs the same synthetic program, ec still clearing rusty on every one)
perf(aac): the frame's noise search is memoised per (channel, band, scalefactor) -- band_noise is pure for one frame's coefficients, and the outer bisection's probes re-ask the same pairs, so each pair computes at most once per frame (stamp/cur generation, no clearing pass); fresh NoiseMemo per write_frame, capacity channels*max_sfb*256. The first cut keyed (band, sf) only and the byte-identity gate caught it instantly: stereo's two channels collided in the slots and one channel replayed the other's noise (10x deltas) -- the key now carries the channel slot. Byte-identical on stereo 256k and 5.1 512k vs base; stereo 42.1 -> 59.1x RT, 5.1 15.6 -> 21.8x (quiet-core min-of-7, both harnesses agreeing); ec-aac suite green 75/75Ahmet Kaan Gümüş · 6d09e0a
perf(aac): the frame's noise search is memoised per (channel, band, scalefactor) -- band_noise is pure for one frame's coefficients, and the outer bisection's probes re-ask the same pairs, so each pair computes at most once per frame (stamp/cur generation, no clearing pass); fresh NoiseMemo per write_frame, capacity channels*max_sfb*256. The first cut keyed (band, sf) only and the byte-identity gate caught it instantly: stereo's two channels collided in the slots and one channel replayed the other's noise (10x deltas) -- the key now carries the channel slot. Byte-identical on stereo 256k and 5.1 512k vs base; stereo 42.1 -> 59.1x RT, 5.1 15.6 -> 21.8x (quiet-core min-of-7, both harnesses agreeing); ec-aac suite green 75/75
perf(aac): the rate loop's per-coefficient powf becomes two lookup tables -- pow_quarter carries 2^(v/4) for every integer v in -155..=155 (band_noise's gain, quantise_one's reciprocal) and POW_HALF carries the bisection's 2^(offset/2) mask scale in -240..=240; every entry is built by the identical powf expression it replaces, so the values -- and the bitstream -- are unchanged. The band gain is hoisted to per-band granularity in band_noise and the requant pass instead of being recomputed per coefficient. Byte-identical on stereo 256k and 5.1 512k vs base; stereo 37.9 -> 42.1x RT, 5.1 14.2 -> 15.6x; ec-aac suite green (43+1+1+14, remaining two suites landed green)Ahmet Kaan Gümüş · 0fe46e1
perf(aac): the rate loop's per-coefficient powf becomes two lookup tables -- pow_quarter carries 2^(v/4) for every integer v in -155..=155 (band_noise's gain, quantise_one's reciprocal) and POW_HALF carries the bisection's 2^(offset/2) mask scale in -240..=240; every entry is built by the identical powf expression it replaces, so the values -- and the bitstream -- are unchanged. The band gain is hoisted to per-band granularity in band_noise and the requant pass instead of being recomputed per coefficient. Byte-identical on stereo 256k and 5.1 512k vs base; stereo 37.9 -> 42.1x RT, 5.1 14.2 -> 15.6x; ec-aac suite green (43+1+1+14, remaining two suites landed green)
perf(aac): rate-loop band invariants hoisted out of the offset probes -- per-band peak, energy, count and escape floor on the post-M/S coefficients are offset-independent, so write_frame computes them once per channel (band_profile) and every bisection probe reads them back instead of rescanning 1024 lines ten-plus times per frame; the redundant final cost probe at the bisection's end is gone (coded already is the probe at lo: hi only moves to taken probes and lo converges to hi). Byte-identical output on stereo 256k and 5.1 512k synthetic program vs the base build; stereo 34.4 -> 37.9x RT, 5.1 12.9 -> 14.2x; ec-aac suite greenAhmet Kaan Gümüş · 44ea57e
perf(aac): rate-loop band invariants hoisted out of the offset probes -- per-band peak, energy, count and escape floor on the post-M/S coefficients are offset-independent, so write_frame computes them once per channel (band_profile) and every bisection probe reads them back instead of rescanning 1024 lines ten-plus times per frame; the redundant final cost probe at the bisection's end is gone (coded already is the probe at lo: hi only moves to taken probes and lo converges to hi). Byte-identical output on stereo 256k and 5.1 512k synthetic program vs the base build; stereo 34.4 -> 37.9x RT, 5.1 12.9 -> 14.2x; ec-aac suite green
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.