oxideav-ac4
Pure-Rust Dolby AC-4 audio decoder foundation — sync / TOC / presentation
/ substream parsing, plus a stub decode path that emits silence at the
correct channel count and sample rate so container fixtures can round-trip
without crashing. Zero C dependencies, no FFI, no *-sys crates.
Part of the oxideav framework but usable standalone.
Status: Foundation. AC-4 is a complex codec. This crate parses the bitstream framing, the table of contents (
ac4_toc()), presentations and substream descriptors per ETSI TS 103 190-1 V1.4.1, and exposes a decoder that emits PCM with the right shape. Mono ASF, stereo CPE (split + joint MDCT), full A-SPX front-end, A-CPL channel-pair synthesis (ASPX_ACPL_1 / ASPX_ACPL_2), DRC + DE + outer metadata walker are all implemented. Round 20 unblocks the ETSI Huffman-table audit (60 codebooks validated byte-for-byte against the canonical ETSI accompaniment file intests/etsi_table_validation.rs) and wires the 5.X channel-element walker family's Cfg0 / Cfg1 / Cfg2 outer shells plus a Table-21-correctsf_info_lfe()parser. Round 21 lands the §5.7.7.6.2 ASPX_ACPL_3 transform-matrix synthesis math (Pseudocodes 118/119 —Transform(),ACplModule2(),ACplModule3()and the full 5-channel pipelinerun_pseudocode_118_5x()). Round 22 lands §5.7.7.6.1 ASPX_ACPL_1 / ASPX_ACPL_2 multichannel wrappers (Pseudocode 117 —run_pseudocode_117_5x(): two parallel ACplModule's with D0/D1 decorrelators) plus the 5_X-walker glue: PCM-level helpersrun_acpl_5x_pair_pcm()(ASPX_ACPL_1/2) andrun_acpl_5x_mch_pcm()(ASPX_ACPL_3) consume the parsedacpl_config_*+acpl_data_*to produce 5-channel L/R/C/Ls/Rs PCM end-to-end via QMF analysis → A-CPL → QMF synthesis. Round 23 wires the per-channelsf_data(ASF)Huffman bodies for the multichannel layouts (Tables 26 / 27 / 28 / 29):parse_two_channel_data/parse_three_channel_data/parse_four_channel_data/parse_five_channel_datanow also walk the trailing 2 / 3 / 4 / 5sf_data(ASF)calls throughdecode_mch_sf_data_channels()and deposit the per-channel scaled MDCT spectra on each*ChannelData::scaled_spec_per_channelfor the long-frame, single-window-group case. The Huffman codebook IDs reused areHCB_1..HCB_11(spectral lines),HCB_SCALEFAC(scale-factor DPCM) andHCB_SNF(spectral noise fill) — Annex A.1 shares the codebooks across mono / stereo / multichannel; there is no separate "MCH" codebook set. Round 24 closes the two r23 follow-ups: (1) the grouped / short-frame multichannelsf_data(ASF)walker (num_window_groups > 1) is now driven bydecode_asf_grouped_mono_body_with_max_sfb()— each per-channel spectrum is the concatenation ofnum_window_groupsindependent(section + spectral + scalefac + snf)chains, group-major; (2) the ASPX_ACPL_3 inner body walker is now wired inparse_5x_audio_data_outer— on an I-frame the walker chainsstereo_data() + aspx_data_2ch() + acpl_data_2ch()and the parsedtools.acpl_data_2chflows straight into the §5.7.7.6.2 Pseudocode-118 5_X synthesis pipeline. The Table-52aspx_data_2ch()body parser was factored out of the stereo CPE ASPX path into a sharedparse_aspx_data_2ch_body()helper — both the stereo CPE mode and the 5_X ASPX_ACPL_3 mode use the same parser. Round 25 wires the ASPX_ACPL_1 / ASPX_ACPL_2 inner body walker inparse_5x_audio_data_outerper §4.2.6.6 Table 25 (case ASPX_ACPL_1: case ASPX_ACPL_2:): a newparse_aspx_acpl_1_2_inner_body()helper walkstwo_channel_data() / three_channel_data()(selected by the 1-bitcoding_config), the ASPX_ACPL_1-only joint-MDCT residual layer (max_sfb_master + 2x chparam_info + 2x sf_data(ASF)over the dominant transform length signalled by the upstream channel data —n_side_bitsis derived per the §4.2.6.6 NOTE), the optional Cfg0 trailermono_data(0), thenaspx_data_2ch()+aspx_data_1ch()and finally the two parallelacpl_data_1ch()calls per Pseudocode 117. The pair lands intools.acpl_data_1ch_pair[0/1](D0 / D1 ACplModule). The walker is try-and-bail: any inner Huffman / parse miss leaves the already-populatedtools.*slots intact and returns silently. Round 27 lands the 7_X channel-element walker (parse_7x_audio_data_outer) per §4.2.6.14 Table 33 — immersive 7.0 and 7.1 streams now parse end-to-end. The 7.X walker mirrors the 5_X SIMPLE/ASPX path'scoding_configselector but has its own quirks: 2-bit7_X_codec_mode(no ASPX_ACPL_3 in 7.X),companding_control(5)only on ASPX_ACPL_{1,2}, the centre/back monos move out of the coding_config switch into a single trailingmono_data(0)gated oncoding_config in {0, 2}, and a SIMPLE/ASPX-only additional-channel block (b_use_sap_add_ch + optional chparam_info×2 + two_channel_data) carries the front-extension / back-surround pair beyond the 5.X core.walk_ac4_substreamnow dispatcheschannels == 7/8(7.0/7.1) into the new walker. Round 28 lands the mono / stereo short-framesf_data(ASF)walker per ETSI TS 103 190-1 §4.2.8.3-6 Tables 39-42: new spec-correct_groupedpayload parsers inasf_data.rs(each with its own outerfor (g = 0; g < num_window_groups; g++)loop, a single 8-bitreference_scale_factorat the head ofasf_scalefac_data()withfirst_scf_foundcarrying across groups, and a single 1-bitb_snf_data_existsgate at the head ofasf_snf_data()), plusderive_per_group()helpers that resolve per-group(transf_length_idx, transform_length, max_sfb)from(ti, psy)per Pseudocodes 2 / 3 / 5 (handling theb_different_framinghalf-frame split). New body decodersdecode_asf_grouped_mono_body[_with_max_sfb]()anddecode_asf_grouped_stereo_joint_body()(shared section, per-groupms_used[g][sfb], inverse M/S) are wired into all four mono / stereo call sites:parse_mono_audio_data_outer,parse_aspx_acpl2_mdct_body,parse_aspx_acpl1_mdct_body(joint + split) andparse_stereo_data_body(joint + split). Real Dolby AC-4 mono / stereo streams using short-window sub-frames now decode end-to-end without bailing at the previousnum_window_groups != 1guard. Round 29 lands the full §5.2.8 SSF arithmetic decoder + Annex C scalar inventory + 37 prediction-coefficient matrices — 705-entryCDF_TABLE,PREDICTOR_GAIN_CDF_LUT,ENVELOPE_CDF_LUT,DITHER_TABLE/RANDOM_NOISE_TABLE,STEP_SIZES_Q4_15,AC_COEFF_MAX_INDEX, the four C.14 dB↔linear LUTs, plusAcState(init/decode_target/decode_symbol_ext_cdf/decode_symbol_calc_cdf/decode_finishper Pseudocodes 41-47), theIdx2Reconstruction + CdfEstcomputed-CDF path (Pseudocodes 51-53), envelope / predictor-gain / coefficient convenience entry points (Pseudocodes 48-50), and theSsfRandGenStatedither + noise RNG (Pseudocodes 54-57). Round 30 lands the SSF bitstream walker (ssf::parse_ssf_data/parse_ssf_granule/parse_ssf_st_data/parse_ssf_ac_dataper Tables 43-46), the Annex C.1 SSF-bandwidths matrix (SSF_BANDWIDTHS, 19 bands × 8 block-length columns),SsfBinLayout::build()(Pseudocode 7 —start_bin[]/end_bin[]/num_bins),SsfFrameConfig(Tables 112-113), and theSsfChannelStatecarrying RNG /prev_pred_lag_idx/last_num_bands/env_prev[]across granules. Wired intowalk_ac4_substreamfor mono SIMPLE/ASPX, split-MDCT stereo, and the ASPX_ACPL_1 split residual layer —spec_frontend == SSFno longer falls through silently. Round 31 lands the §5.2.3-5.2.7 SSF PCM synthesis chain in a newssf_synthmodule: envelope decoder + predictor + helpers + lossless decode + inverse-quant + subband predictor + inverse-flattening (Pseudocodes 4a / 4b / 4c / 4d / 4e / 26 / 31 / 32 / 33 / 34 / 35 / 36 / 37 / 38) plus the C-matrix reconstruction (Pseudocode 39) for all 37tab_idxvalues.synthesize_ssf_data()threadsenv_prev[]between granules.Ac4Decodernow carries a per-channelVec<SsfSynthState>and consumestools.ssf_data_primary/tools.ssf_data_secondaryafter the ASF/A-CPL pipeline: each granule'snum_blocks * n_mdctspectrum is split per-block and IMDCT'd through the existing KBD overlap-add path. SSF substreams now emit real PCM in place of silence. §5.2.5.2.2 Heuristic Scaling (Pseudocodes 27 / 28 / 29 / 30) is deferred — the spec'sf_rfu == 0short-circuit covers any block with the predictor disabled, which the current synth supports. Round 32 closes the SHORT_STRIDE P-frame correctness gap by addingenv_prev: Vec<i32>toSsfSynthState:synthesize_granule()latches the resolved envelope (post-decode_envelopeδ-chain) at the end of each granule so that a SHORT_STRIDE P-granule with no caller-suppliedenv_prev[]interpolates against the previous frame's envelope rather than a zero fallback (§5.2.3.0 Note 2). The walker side gets a parallel hoist:Ac4Decodernow owns aVec<SsfChannelState>(ssf_walker_state) and a newwalk_ac4_substream_stateful()threads it through the SSF body parses so dither / noise RNGs (Pseudocodes 54-57) andprev_pred_lag_idx/last_num_bandspersist across frames — pre-r32 the walker built a fresh state per frame and dropped it. Round 33 lands §5.2.5.2.2 Heuristic Scaling (Pseudocodes 27/28/29/30) — the predictor-enabled spectrum-decoding branch the spec'sf_rfu == 0short-circuit previously skipped. Newmap_db_to_lin_q10()/map_lin_to_db_q10()Q.10 fixed-point converters use the Annex C.14 LUTs;heuristic_scaling()runs the full Pseudocode 28 chain (dynamic-range compression ofenv_in[], sorted-descendingMap_dB_to_Lin,iRfu²-weighted reverse water-filling,Map_Lin_to_dB-driven per-band weight);apply_heuristic_scaling()wraps it with the Pseudocode 27env_in = 3 * env_allocpre-multiply, LF-boost, and(env_alloc_mod, f_gain_q)post-processing.synthesize_granule()dispatches the §5.2.5.2.0 selector — whenf_rfu > 0 && !variance_preservingthe heuristic-scaling branch fires andinverse_heuristic_scale()consumes the resultingf_gain_q[]instead of the all-1 stub;variance_preservingblocks correctly skip the inverse-scale call per §5.2.5.2.0 step 5. Round 34 lands FIXVAR / VARFIX / VARVAR atsg border derivation (§5.7.6.3.3.2 Pseudocode 77) — newderive_fixvar_atsg(),derive_varfix_atsg(),derive_varvar_atsg()and a unifiedderive_atsg_borders()dispatcher cover all fouraspx_int_classvalues; the decoder's TNS and envelope-adjustment paths now route throughderive_atsg_bordersinstead of the FIXFIX-only path, enabling A-SPX bandwidth extension for FIXVAR / VARFIX / VARVAR substreams. §5.1.4 SNF injection:inject_snf_noise()fills zero-energy MDCT bins using a 16-bit LCG (multiplier 69069, addend 1) and gain formula2^((idx×1.5−84)/4); the long-mono ASF decode path now consumesparse_asf_snf_data()output instead of discarding it. 5_X ASPX_ACPL_3 wired inAc4Decoder: two new persistent state fields (acpl_5x_mch_state/acpl_5x_pair_state) are added; whenacpl_config_2ch+acpl_data_2ch+ stereo carrier spectra are present,run_acpl_5x_mch_pcm()(Pseudocode 118) fires and fillspcm_per_channel[0..5]with L/R/C/Ls/Rs surround PCM. Round 35 lands the §4.2.4.4 EMDF payloads substream parser (Table 18) plus the §4.2.14.14emdf_payload_config()(Table 79) in a newemdfmodule —parse_emdf_payloads_substream()walks the while-loop until theemdf_payload_id == 0terminator, handles theid == 31 → variable_bits(5)extension, decodes the fullEmdfPayloadConfig(sample-offset / duration / group-id / codecdata / discard / frame-aligned + create-/remove-duplicate / priority / proc_allowed gates per the Table 79 conditional tree), and captures each payload'semdf_payload_byte[]verbatim. Defensive caps (MAX_EMDF_PAYLOADS = 64,MAX_EMDF_PAYLOAD_BYTES = 65 536) bound malformed input. The outermetadata::parse_metadatawalker now consumes the substream whenb_emdf_payloads_substream == 1and surfaces it throughMetadata::emdf_payloads_substreaminstead of erroring out with "not yet implemented" — real-bitstream metadata can now fully round-trip through the walker. Round 35 also lands the §5.7.9.3.3 PCM gain application path:drc::drc_raw_to_linear()maps a 7-bitdrc_gain[ch][sf][band]value to its linear multiplier via2^((raw-64)/6),dialnorm_correction_linear()resolves the2^((Lout-Lin)/6)dialnorm correction, anddrc::apply_drc_gains_to_pcm()applies a parsedDrcGains(per channel-group, per subframe — multi-band averaged in the linear domain) to a planar&mut [Vec<f32>]PCM buffer with aDrcChannelMap(helpers for the[L, R, C, LFE?, Ls, Rs]5_X layout and the wideband single-group mono/stereo case). DE walker hardened with three new edge-case tests covering EOF on truncation, non-I-frame withoutprev_config, and thenr_channels == 0degenerate case. Round 51 lands stereo SIMPLE/ASF split-MDCT (Path A: 2× SCE) encoding per ETSI TS 103 190-1 §5.3 + §4.2.6.3 —Ac4ImsEncoder::encode_frame_pcm_stereoaccepts L+R PCM frames, runs the existing forward MDCT + scalefactor + DP-section + HCB1..11 codebook-selection + SNF emission pipeline independently per channel, and emits ab_enable_mdct_stereo_proc == 0stereo CPE body the decoder reconstructs at ≥24.8 dB spectral SNR for both 440 Hz L+R (matched) and 440 Hz L + 660 Hz R (independent) tone fixtures. Round 52 lands the matching joint M/S CPE (Path B,b_enable_mdct_stereo_proc == 1) encoder per §5.3 + §4.2.6.3
- §7.5:
encode_frame_pcm_stereonow dispatches between Path A and Path B based on an energy-weighted per-SFB correlation rising above the 0.7 threshold. Path B emits one sharedasf_section_data- two
asf_spectral_data(M/S or L/R per band based on bit-cost comparison) + sharedasf_scalefac_data+ per-active-sfbms_usedflags + sharedasf_snf_data. A frame-level "matched-channels" gate (S/M energy ratio < 0.15) bumps the M-channel q_target up to 16 to spend the bits saved on the silent / near-silent S residual on finer M quantisation. End-to-end SNR on the 440 Hz L=R matched fixture rises from round-51's 24.8 dB to 34.5 dB; the half- correlated 440 Hz amplitude-imbalance fixture clears ≥ 26 dB; independent 440 L + 660 R correctly routes via Path A and preserves the round-51 SNR floor. Round 74 lands the first multichannel forward-analysis encoder: a 5.0 SIMPLE/Cfg3Five path (5 SCE, no LFE, no joint coding) per §4.2.6.6 Table 25 rowcase SIMPLE: coding_config == 3+ §4.2.7.5 Table 29 (five_channel_data()). NewAc4ImsEncoder::with_5_0()flips the TOC channel_mode prefix to0b1101(4 b — Table 85 channel_mode 3), andencode_frame_pcm_5_0(&[L, R, C, Ls, Rs])runs the round-50 forward pipeline (KBD-MDCT + DP-optimal sectioning + HCB1..11- SNF) independently per channel into a shared
sf_info(ASF, 0, 0)header followed byfive_channel_info()(identity SAP:chel_matsel = 0+ 5xchparam_infowithsap_mode = 0) and 5xsf_data(ASF)bodies. Decoder's existingdispatch_5x_cfg3_simple_aspx(round 39) consumes the body and emits 5-channel interleaved S16 PCM. End-to-end per- channel spectral SNR ≥ 20 dB on the independent-tone fixture (220/440/660/880/1100 Hz on L/R/C/Ls/Rs — measured L=24.5 / R=24.8 / C=25.0 / Ls=23.4 / Rs=27.4 dB), matching the round-51 stereo Path A SNR floor. Round 80 extends the multichannel encoder to 5.1 (Cfg3Five + LFE) per §4.2.6.6 Table 25 (if (b_has_lfe) mono_data(1);) + §4.2.8 (sf_info_lfe()Table 35 / Table 106 column 4n_msfbl_bits):Ac4ImsEncoder::encode_frame_pcm_5_1(&[L, R, C, Ls, Rs, LFE])flips the TOC channel_mode prefix to0b1110(4 b — Table 85 channel_mode 4) andbuild_5_1_simple_asf_body_from_pcm_spectraprepends an LFEmono_data(1)element (b_long_frame = 1+sf_info_lfe()withmax_sfb_lfecapped ton_msfbl_bits = 3→ 7 sfb / ≈350 Hz at tl = 1920) before the Cfg3Fivefive_channel_data()body. The decoder side gains a matching LFE PCM render inAc4Decoder::receive_frame: whenchannels == 6(5.1) orchannels == 8(7.1) andtools.lfe_mono_data.scaled_specis present, the LFE spectrum is IMDCT'd into the trailing PCM slot (slot 5 for 5.1, slot 7 for 7.1). Non-LFE per-channel SNR matches the 5.0 numbers (L=24.5 / R=24.8 / C=25.0 / Ls=23.4 / Rs=27.4 dB ≥ 20 dB floor); a 60 Hz LFE tone round-trips to a non-silent reconstructed LFE channel. Round 91 extends the multichannel encoder to 7.1 (3/4/0.1) SIMPLE/Cfg3Five + LFE per §4.2.6.14 Table 33 + §4.2.7.4 Table 26 (additional-channeltwo_channel_data()) + Table 88 channel_mode 6 (0b1111001, 7 b):Ac4ImsEncoder::with_7_1()+encode_frame_pcm_7_1(&[L, R, C, Ls, Rs, Lb, Rb, LFE])emit a 7_X SIMPLE/Cfg3Five body whose innerfive_channel_data()reuses the round-80 5.1 forward pipeline, followed byb_use_sap_add_ch = 0identity-SAP +two_channel_data()for the immersive Lb/Rb pair. The decoder side gains the inner 5-channel core render for the 7_X SIMPLE/Cfg3Five path (it previously parsed but never IMDCT'd slots 0..4 — only the round-39 additional-pair slots 5/6 and the round-80 LFE slot 7 were touched); slots 0..4 now route throughdispatch_5x_cfg3_simple_aspx(the inner SCE shape is identical to the 5_X Cfg3Five case). Per-channel spectral SNR on the 220/440/660/880/1100/1320/1540 Hz independent-tone 7.1 fixture: L=24.5 / R=24.8 / C=25.0 / Ls=23.4 / Rs=27.4 / Lb=25.4 / Rb=26.0 dB — all above the ≥ 20 dB floor. Round 95 lands the 5_X SIMPLE/ASPX_ACPL_3 multichannel encoder path per §4.2.6.6 Table 25 rowcase ASPX_ACPL_3:— symmetric counterpart to the round-34 decoder ACPL_3 walker (5a58f6a).Ac4ImsEncoder::encode_frame_pcm_5_0_acpl3(&[L, R, C])andencode_frame_pcm_5_1_acpl3(&[L, R, C, LFE])emit IMS v2 frames with5_X_codec_mode = 4(ASPX_ACPL_3). The newencoder_acpl3module ships bit-exact emitters foraspx_config()(Table 50, 15 b),acpl_config_2ch()(Table 60, 4 b),companding_control(2)(Table 49, 2 b), plus minimum-bit-cost zero-delta Huffman writers covering all 18 ASPX HCBs (Annex A.2 Tables A.16-A.33) and all 24 ACPL HCBs (Annex A.3 Tables A.34-A.57) —pick_zero_delta_cwpicks the entry atindex == cb_off(zero delta for DF/DT) andpick_min_len_cwpicks the smallest-length entry (used for F0 seeds). The body layout is5_X_codec_mode = 4 (3 b)+ I-frameaspx_config() + acpl_config_2ch()+ optional LFEmono_data(b_lfe = 1)+companding_control(2)+stereo_data()(split-MDCT path, two carrier channels) +aspx_data_2ch()(FIXFIX num_env=1, balance=1, all-FREQ deltas) +acpl_data_2ch()(1 param set, 7 param bands, 11 EC streams withdiff_type = 0and zero-delta DF). Decoder round-trip: 5.0 ACPL_3 → 5-channel S16 interleaved PCM (1920 samples × 5 ch × 2 bytes); 5.1 ACPL_3 → 6-channel S16 (with LFE slot 5). The decoder walks the full Table 25 body and resolvesfive_x_mode == AspxAcpl3acpl_config_2ch.is_some() && acpl_data_2ch.is_some(). The 5-channel[L, R, C, Ls, Rs]synthesis runs viaacpl_synth::run_acpl_5x_mch_pcm(Pseudocode 118) — with all-zero ACPL parameter deltas Ls/Rs collapses to ducker-driven reconstruction from the L/R carriers (non-silent in the general case). Total tests 691 (was 680). Real per-band(alpha, beta, gamma)parameter extraction (replacing the zero-delta scaffold), real ASPX envelope coding, and matching encoder paths for5_X_codec_mode in {ASPX_ACPL_1, ASPX_ACPL_2}(Pseudocode 117) remain deferred. The 7_X paths inherit the sameaspx_data/acpl_datashape as 5_X so they're queued behind the 5_X work continuing to harden. Round 100 lands the 5_X SIMPLE/ASPX_ACPL_2 multichannel encoder path per §4.2.6.6 Table 25 rowcase ASPX_ACPL_2:— the symmetric counterpart to the round-25 decoderparse_aspx_acpl_1_2_inner_bodywalker (Pseudocode 117).Ac4ImsEncoder::encode_frame_pcm_5_0_acpl2(&[L, R, C])emits an IMS v2 frame with5_X_codec_mode = ASPX_ACPL_2 (3)whose body isaspx_config() + acpl_config_1ch(FULL) + companding_control(3) + coding_config = 0 + two_channel_data() (L/R carriers) + mono_data(0) (centre) + aspx_data_2ch() + aspx_data_1ch() + two acpl_data_1ch()parameter sets. The ASPX_ACPL_1-only joint-MDCT residual layer (max_sfb_master + 2× chparam_info + 2× sf_data) is skipped for ACPL_2 — that's the structural difference that makes the ACPL_2 path the cleanest encoder win. Newencoder_acpl3emitters:write_acpl_config_1ch_full(Table 59, 3 b),write_two_channel_data(Table 26 — sharedsf_info(ASF)+ identity-SAPchparam_info+ 2×sf_data),write_mono_data_centre(Table 21 non-LFE),write_aspx_data_1ch_minimal(Table 51 FIXFIX num_env=1) andwrite_acpl_data_1ch_minimal(Table 61). The 1ch ASPX SIGNAL band count usesnum_sbg_sig_highresto matchparse_aspx_ec_data's empty-freq_resfallback. Decoder round-trip: 5.0 ACPL_2 → 5-channel S16 interleaved PCM; the decoder resolvesfive_x_mode == AspxAcpl2, walksacpl_config_1ch_full,two_channel_data, the Cfg0 centremono_data(0), and bothacpl_data_1ch_pairentries, then synthesises[L, R, C, Ls, Rs]viaacpl_synth::run_acpl_5x_pair_pcm. Total tests 700 (was 691). The ASPX_ACPL_1 encoder path (joint-MDCT residual + PARTIAL-modeacpl_config_1chwithacpl_qmf_band), real(alpha, beta)parameter extraction, and the 7_X ASPX_ACPL_{1,2} encoder paths remain deferred. Round 103 lands the 5_X SIMPLE/ASPX_ACPL_1 multichannel encoder path per §4.2.6.6 Table 25 rowcase ASPX_ACPL_1:— the round-100 follow-up and the symmetric counterpart to the decoder's round-25parse_aspx_acpl_1_2_inner_bodyASPX_ACPL_1 branch (Pseudocode 117).Ac4ImsEncoder::encode_frame_pcm_5_0_acpl1(&[L, R, C, Ls, Rs])emits an IMS v2 frame with5_X_codec_mode = ASPX_ACPL_1 (2). The body differs from the ACPL_2 path in two structural places: (1)acpl_config_1chis PARTIAL —write_acpl_config_1ch_partial(Table 59, 6 b: id + quant_mode +acpl_qmf_band_minus1), so theacpl_data_1ch()start_band resolves fromqmf_bandviasb_to_pb; (2) the body carries an explicit joint-MDCT residual layer —write_acpl_1_residual_layeremitsmax_sfb_master(n_side bits) + 2× identity-SAPchparam_info+ 2×sf_data(ASF)for the Ls/Rs surround pair (sSMP,3 / sSMP,4 per Table 181), so the encoder takes a full 5-channel input instead of reconstructing Ls/Rs from the L/R carriers. Newbuild_5_x_acpl1_body_from_pcm_spectralays out5_X_codec_mode = 2 + aspx_config() + acpl_config_1ch(PARTIAL) + companding_control(3) + coding_config = 0 + two_channel_data() + residual-layer + mono_data(0) + aspx_data_2ch() + aspx_data_1ch() + 2× acpl_data_1ch(). Decoder round-trip: 5.0 ACPL_1 → 5-channel S16 interleaved PCM; the decoder resolvesfive_x_mode == AspxAcpl1, the PARTIAL config, the persisted residual pair, the Cfg0 centre, and bothacpl_data_1ch_pairentries, then synthesises[L, R, C, Ls, Rs]viaacpl_synth::run_acpl_5x_pair_pcm. Total tests 708 (was 700). Real per-band(alpha, beta)extraction, real ASPX envelope coding, real Table-181 SAP-derived residual content (the residual sf_data currently codes the raw Ls/Rs spectra), and the 7_X ASPX_ACPL_{1,2} encoder paths remain deferred. Round 107 lands the first of those deferred 7_X encoder paths: the 7.0 SIMPLE/ASPX_ACPL_2 multichannel encoder per §4.2.6.14 Table 33 rowcase ASPX_ACPL_2:— the 7_X (immersive) counterpart to the round-100 5_X ASPX_ACPL_2 path and the encoder side of the decoder's round-27parse_7x_audio_data_outerASPX_ACPL_2 branch.Ac4ImsEncoder::encode_frame_pcm_7_0_acpl2(&[L, R, C, Ls, Rs, Lb, Rb])emits an IMS v2 frame with7_X_codec_mode = ASPX_ACPL_2 (3)and channel_mode prefix0b1111000(7 b — Table 85 channel_mode 5, 7.0 (3/4/0)). The newencoder_acpl3::build_7_x_acpl2_body_from_pcm_spectrareuses the same 1ch ACPL / ASPX emitters as the 5_X ACPL_2 path but lays out the 7_X channel element's distinct framing: 2-bit7_X_codec_mode(vs the 5_X 3-bit field),companding_control(5)(sync-on 2-bit wire shape), 2-bitcoding_config = 0(Cfg0),b_2ch_mode + two_channel_data() (L/R) + two_channel_data() (Ls/Rs), a trailing centremono_data(0)moved out of the coding_config switch, and anaspx_data_2ch() + aspx_data_2ch() + aspx_data_1ch()envelope trailer before the twoacpl_data_1ch()parameter sets (Pseudocode 117 D0/D1). The ASPX_ACPL_1-only joint-MDCT residual layer and the SIMPLE/ASPX additional-channel block are skipped for ACPL_2. Decoder round-trip: 7.0 ACPL_2 → 7-channel S16 interleaved PCM (1920 samples × 7 ch × 2 bytes); the decoder resolvesseven_x_mode == AspxAcpl2, bothtwo_channel_datapairs, the Cfg0 centre, and bothacpl_data_1ch_pairentries, then synthesises[L, R, C, Ls, Rs](slots 0..4) viaacpl_synth::run_acpl_5x_pair_pcm(the back pair Lb/Rb stays silent per the Table 202 ACPL_2 mapping). Total tests 714 (was 708). The 7.1 (LFE) ASPX_ACPL_2 path, the 7_X ASPX_ACPL_1 path (PARTIAL config + joint-MDCT residual), real per-band(alpha, beta)extraction, real ASPX envelope coding, and back-pair Lb/Rb carriage remain deferred. Round 114 closes the first of those deferred items — the 7.1 (3/4/0.1) SIMPLE/ASPX_ACPL_2 multichannel encoder path per §4.2.6.14 Table 33 rowcase ASPX_ACPL_2:withb_has_lfe = 1+ §4.2.6.5 Table 21 (mono_data(b_lfe)) + §4.2.8 Table 35 (sf_info_lfe()).Ac4ImsEncoder::encode_frame_pcm_7_1_acpl2(&[L, R, C, Ls, Rs, Lb, Rb, LFE])emits the round-107 7.0 ASPX_ACPL_2 body plus a leadingmono_data(b_lfe = 1)element between the I-frame config block andcompanding_control(5)— exactly where the decoder'sparse_7x_audio_data_outer(b_has_lfe = true)readsif (b_has_lfe) mono_data(1);. The channel_mode prefix is forced to0b1111001(7 b — Table 88 channel_mode 6) so the decoder dispatcheschannels == 8.build_7_x_acpl2_body_from_pcm_spectragainedmax_sfb_lfe: Option<u32>+coeffs_lfe: Option<&[f32]>and reuses the shared round-80write_lfe_mono_dataemitter (max_sfb_lfecapped ton_msfbl_bits = 3→ 7 sfb attl = 1920). Decoder round-trip: 7.1 ACPL_2 → 8-channel S16 interleaved PCM (1920 samples × 8 ch × 2 bytes); the LFE spectrum IMDCT's into slot 7 via the round-80 LFE render, the[L, R, C, Ls, Rs]slots 0..4 synthesis is unchanged, and the back pair Lb/Rb (slots 5/6) stays silent per the Table 202 ACPL_2 mapping. A 60 Hz LFE tone round-trips to a non-silent reconstructed LFE channel. Total tests 721 (was 714). The 7_X ASPX_ACPL_1 path (PARTIAL config + joint-MDCT residual), real per-band(alpha, beta)extraction, real ASPX envelope coding, and back-pair Lb/Rb carriage remain deferred. Round 118 closes the first of those — the 7.0 / 7.1 (3/4/0(.1)) SIMPLE/ASPX_ACPL_1 multichannel encoder path per §4.2.6.14 Table 33 rowcase ASPX_ACPL_1:(the 7_X analogue of the round-103 5_X ACPL_1 path).Ac4ImsEncoder::encode_frame_pcm_7_0_acpl1(&[L, R, C, Ls, Rs, Lb, Rb])andencode_frame_pcm_7_1_acpl1(&[.., LFE])emit IMS v2 frames with7_X_codec_mode = ASPX_ACPL_1 (2). Newencoder_acpl3::build_7_x_acpl1_body_from_pcm_spectrais the round-107/114 7_X ACPL_2 body with the three ACPL_1 differences:7_X_codec_mode = 2(not 3),acpl_config_1chPARTIAL (write_acpl_config_1ch_partial, carriesacpl_qmf_band_minus1→acpl_data_1ch()start_band viasb_to_pb), and an explicit joint-MDCT residual layer (write_acpl_1_residual_layer:max_sfb_master + 2× chparam_info + 2× sf_data(ASF)for the Ls/Rs surround pair sSMP,3 / sSMP,4 per Table
- after the two
two_channel_data()pairs and before the trailing Cfg0 centremono_data(0). The 7.1 form prepends the round-80write_lfe_mono_dataLFE element. Decoder round-trip: 7.0 ACPL_1 → 7-channel S16 PCM; 7.1 ACPL_1 → 8-channel S16 (LFE IMDCT'd into slot 7);[L, R, C, Ls, Rs]synthesise viaacpl_synth::run_acpl_5x_pair_pcm, Lb/Rb (slots 5/6) silent per Table 202. Total tests 729 (was 721). Real per-band(alpha, beta)extraction, real ASPX envelope coding, real Table-181 SAP-derived residual content, and back-pair Lb/Rb carriage remain deferred. Round 125 lands the 7.0 (3/4/0) SIMPLE/Cfg3Five multichannel encoder path per ETSI TS 103 190-1 §4.2.6.14 Table 33 + §4.2.7.5 Table 29 (five_channel_data()) + §4.2.7.4 Table 26 (additional-channeltwo_channel_data()) — the non-LFE immersive counterpart of round-91's 7.1 encoder (the 7_X analogue of round 74's 5.0 vs round 80's 5.1).Ac4ImsEncoder::with_7_0()flips the TOC channel_mode prefix to0b1111000(7 b — Table 85 channel_mode 5, 7.0 (3/4/0) → 7 channels), andencode_frame_pcm_7_0(&[L, R, C, Ls, Rs, Lb, Rb])(+..._with_max_sfb(.., max_sfb, max_sfb_add)) emits a SIMPLE/Cfg3Five 7_X channel-element body whose innerfive_channel_data()reuses the round-80 5.1 forward pipeline for the L/R/C/Ls/Rs front/surround pair and whose trailing identity-SAPtwo_channel_data()(b_use_sap_add_ch = 0) carries the immersive Lb/Rb pair. The body is structurally the round-91 7.1 body with the leadingmono_data(b_lfe = 1)element omitted (the walker'sif (b_has_lfe) mono_data(1);branch is gated off for channel_mode 5). Newencoder_asf::build_7_0_simple_asf_body_from_pcm_spectraemits the body bytes; decoder round-trip: 7.0 → 7-channel S16 interleaved PCM (1920 samples × 7 ch × 2 bytes). The 7.0 walker resolvesseven_x_mode == Simple,seven_x_b_has_lfe == false,five_channel_datapopulated, identity-SAP additional-channel pair populated (slots 5/6 = Lb/Rb routed viadispatch_7x_additional_channel_pair). Per-channel spectral SNR on the 220/440/660/880/1100/1320/1540 Hz independent-tone 7.0 fixture: L=24.5 / R=24.8 / C=25.0 / Ls=23.4 / Rs=27.4 / Lb=25.4 / Rb=26.0 dB — all above the ≥ 20 dB floor. Total tests 737 (was 729). Round 128 lands the first real per-parameter-band α extraction in the ACPL_1 5.0 encoder per ETSI TS 103 190-1 §5.7.7.5 Pseudocode 116 + §5.7.7.6.1 Pseudocode 117 — replaces the round-103 zero-delta α scaffold (β / β3 / γ stay at the round-95 / 100 / 103 scaffold; β3 / γ only fire in ASPX_ACPL_3 anyway). With β = 0 the surround reconstruction isLs_recon = 0.5/√2 · L · (1 − α); solving for α per parameter band gives the closed formα = 1 − 2·√2 · ⟨L, Ls⟩ / ⟨L, L⟩. Newencoder_acpl3::build_5_x_acpl1_body_from_pcm_spectra_real_alpha
- helper chain (
compute_per_band_correlationsmapping MDCT bins → QMF subbands → A-CPL parameter bands via §5.7.7.2 Table 197,analytic_alpha_per_band+quantise_alphaagainst Tables 203 / 205, thenwrite_acpl_alpha_f0_value/write_acpl_alpha_df_valueemit the ALPHA F0 + DF codewords per Tables A.35 / A.34); newAc4ImsEncoder::encode_frame_pcm_5_0_acpl1_real_alphaentry point alongside the round-103 zero-delta variant. The on-wire body structure is unchanged — decoder resolvesFiveXCodecMode::AspxAcpl1, bothacpl_data_1ch_pair[0/1]populated, joint-MDCT residual layer walked,[L, R, C, Ls, Rs]synthesised viaacpl_synth::run_acpl_5x_pair_pcm. Total tests 743 (was 737). Round 132 adds the first real per-parameter-band β extraction in the ACPL_1 5.0 encoder per ETSI TS 103 190-1 §5.7.7.5 Pseudocode 116 + §5.7.7.6.1 Pseudocode 117 — replaces the round-95/100/103/128 zero-β scaffold for the ACPL_1 path. With the decorrelator outputy⊥x0andE[y²] ≈ E[x0²], the surround energy balance isE[Ls²] = 0.5·E[x0²]·((1−α)² + β²), so the per-band β magnitude isβ = √max(0, 2·E[Ls²]/E[x0²] − (1−α_dq)²). Newencoder_acpl3::build_5_x_acpl1_body_from_pcm_spectra_real_alpha_beta- helper chain (
compute_per_band_energies,analytic_beta_per_band,quantise_beta_magnitudeagainst Tables 204/206,write_acpl_beta_f0_value/write_acpl_beta_df_valueper Tables A.40/A.41) and the newAc4ImsEncoder::encode_frame_pcm_5_0_acpl1_real_alpha_betaentry point. The on-wire body structure is unchanged; the β coding contract round-trips byte-exact throughacpl::parse_acpl_data_1ch. Total tests 755 (was 743). Real β extraction for the 7_X / ACPL_2 / ACPL_3 paths, real γ extraction, and the round-128 ALPHA-writer negative-alpha_qdesync fix remain deferred. Round 135 extends the real per-band α + β extraction to the 7_X (7.0 immersive) ASPX_ACPL_1 path — the round-132 followup. Newencoder_acpl3::build_7_x_acpl1_body_from_pcm_spectra_real_alpha_beta(the real-α+β upgrade of the round-118 zero-delta 7_X builder, reusing theextract_alpha_q_per_band/extract_beta_q_per_bandprimitives) and theAc4ImsEncoder::encode_frame_pcm_7_0_acpl1_real_alpha_betaentry point; both trailingacpl_data_1ch()sets now carry real α + β. The on-wire body structure is unchanged — decoder resolvesSevenXCodecMode::AspxAcpl1(b_has_lfe = false), bothacpl_data_1ch_pair[0/1]populated, joint-MDCT residual layer walked. Total tests 760 (was 755). Round 139 extends the real per-band α + β extraction to the 7.1-with-LFE (3/4/0.1) ASPX_ACPL_1 path — the round-135 LFE follow-up. NewAc4ImsEncoder::encode_frame_pcm_7_1_acpl1_real_alpha_beta(and the_with_max_sfbform) reuses the round-135build_7_x_acpl1_body_from_pcm_spectra_real_alpha_betabuilder with the LFEcoeffs_lfe+max_sfb_lfeslots populated, emitting a leadingmono_data(b_lfe = 1)element (Table 21 +sf_info_lfe()Table 35) between the I-frame config block andcompanding_control(5)exactly where the decoder'sparse_7x_audio_data_outer(b_has_lfe = true)readsif (b_has_lfe) mono_data(1);. The on-wire body structure matches the existing round-118 7.1 ACPL_1 path — decoder resolvesSevenXCodecMode::AspxAcpl1withb_has_lfe = true, bothacpl_data_1ch_pair[0/1]populated (now carrying real α + β), joint-MDCT residual layer walked, LFE IMDCT'd into slot 7. A 60 Hz LFE tone round-trips to a non-silent reconstructed LFE channel. Total tests 766 (was 760). Real β extraction for the ACPL_2 / ACPL_3 paths and the round-128 ALPHA-writer negative-alpha_qdesync fix remain deferred. Round 144 closes the ACPL_2 5.0 half of the deferred list with the 5_X SIMPLE/ASPX_ACPL_2 encoder with real per-parameter-band α + β extraction per §4.2.6.6 Table 25 rowcase ASPX_ACPL_2:+ §5.7.7.5 Pseudocode 116 + §5.7.7.6.1 Pseudocode 117. NewAc4ImsEncoder::encode_frame_pcm_5_0_acpl2_real_alpha_beta(and the_with_max_sfbform) accepts a 5-channel[L, R, C, Ls, Rs]input and produces a 5_X ASPX_ACPL_2 frame whose two trailingacpl_data_1ch()elements carry real per-band α + β indices extracted from the (L, Ls) and (R, Rs) MDCT energy ratios via the round-128 / 132 shared analytic primitives. The on-wire body layout matches the round-100build_5_x_acpl2_body_from_pcm_spectraschedule (no joint-MDCT residual layer — ACPL_2 reconstructs the surround from L/R + the twoacpl_data_1ch()parameter sets at decode time); the Ls/Rs spectra are consumed only by the α + β extractors and are not transmitted.acpl_config_1ch(FULL)carries noqmf_band→start_band = 0so every parameter band participates in the α + β coding (in contrast to the ACPL_1 PARTIAL mode whoseacpl_qmf_bandmasks the low bands). Total tests 773 (was 766). Real β extraction for the ACPL_3 paths and the round-128 ALPHA-writer negative-alpha_qdesync fix (which currently obscures per-band on-wire α/β recovery through the full PCM→MDCT→writer→parser→synth chain when the analytic α quantises to a non-center lane) remain deferred. Round 174 closes the desync fix at the codebook contract level: ALPHA / BETA3 F0cb_offcorrected per §A.3 Tables A.34 / A.35 / A.46 / A.47. Pre-fixcb_off = 0conflicted with the §5.7.7.7 Pseudocode 121 differential-decoder / [acpl_synth::dequantize_alpha_index] signed-lane contract; the ALPHA F0 codebooks (17-entry Coarse / 33-entry Fine) are symmetric around the centre with a 1-bit peak at thealpha_q = 0lane, socb_off = N/2(8 Coarse / 16 Fine) is the right offset to read back signedalpha_q ∈ [-N/2, +N/2]directly fromdecode_delta. The fix lands in both [acpl::get_acpl_hcb] (decoder side) and the encoder's local [encoder_acpl3::acpl_hcb_arrays] mirror, plus the symmetric BETA3 F0 codebooks (cb_off = 4Coarse /8Fine — the §5.7.7.7dequantize_beta3multiplies the signed lane bybeta3_delta(qm)directly so they share ALPHA's signed convention). BETA F0 stays atcb_off = 0(unsigned magnitude — Table 204 / 206 stores positive entries only anddequantize_beta_indextakesunsigned_absthen re-applies the sign carried in by the differential accumulator). Three new unit tests ([alpha_f0_signed_lanes_round_trip_fine_and_coarse], [beta3_f0_signed_lanes_round_trip_fine_and_coarse], [alpha_f0_zero_alpha_picks_one_bit_peak]) sweep every signed lane through encode →decode_deltaand confirm the writer now picks the 1-bit symmetric peak foralpha_q = 0(down from 10 / 12 bits pre-fix). The round-128 family (encode_5_0_acpl1_real_alpha_emits_nonzero_alpha_when_surround_differs,..._symmetric_scaling_yields_matching_alpha) is re-shaped to assert on encoder byte-stream divergence rather than the decoder's recoveredalpha_q— bit-position drift through the full 5_X SIMPLE/ASPX_ACPL_1 walker on non-silence input is independent of the F0 cb_off bug and still pending separate investigation (it manifests as a misalignment upstream ofparse_acpl_data_1ch, not in the ACPL F0 codeword itself). Total tests 776 (was 773). Round 181 closes the deferred "alpha_q desync" follow-up at two distinct spec-alignment layers. Layer 1: [acpl::parse_acpl_huff_data] now returns a spec-indexed length-num_param_bandsvector matching §5.7.7.7 Pseudocode 121'sacpl_<SET>[ps][i]shape (positions[0..start_band)are zero, F0 lands atvalues[start_band], DF deltas occupy[start_band+1..num_param_bands)); pre-r181's packed(num_bands - start_band)-length layout silently shifted the DIFF_FREQ accumulation for the PARTIALacpl_config_1chpath. Layer 2: [encoder_acpl3::write_aspx_data_2ch_minimal] now keys the SIGNAL ec_data band count offcfg.signals_freq_res()per §4.3.10.4.9 (Table 124 NOTE 3) — when the encoder doesn't emit an in-bandaspx_freq_resbit, the parser's high-res fallback selectsnum_sbg_sig_highresand the writer must match (pre-r181 it hard-codednum_sbg_sig_lowres, causing a 20-vs-10 SIGNAL desync that buried every subsequentacpl_data_1ch()α/β codeword in trailing zero-padding). End-to-end 5.0 ASPX_ACPL_2 asymmetric L/Ls input now recovers a non-zero per-bandalpha_qrow onacpl_data_1ch_pair[0/1]through the full PCM → MDCT → encode → AC-4 walker →differential_decodechain. Total tests 780 (was 776). The ASPX_ACPL_1 path retains a separate joint-MDCT residual-layer alignment issue between [encoder_acpl3::write_acpl_1_residual_layer] and the decoder'sparse_aspx_acpl_1_2_inner_bodyresidual-pair walker — tracked as the remaining follow-up. Round 187 pins that follow-up with four end-to-end characterisation tests (silence / L-only / Ls-only / combined) that sweep [encoder_ims::Ac4ImsEncoder::encode_frame_pcm_5_0_acpl1_real_alpha_beta] and assert each pair slot's recoveredacpl_data_1ch_pair[0/1].framing.num_param_setsso the next round can iterate on the residual / α-β writers without regressing the aligned silence / L-only / Ls-only paths. The diagnostic narrative intests/round187_acpl1_residual_desync_characterization.rstriangulates the drift surface: writer→parser pairs for [encoder_acpl3::write_acpl_data_1ch_real_alpha_beta_bytes] ↔ [acpl::parse_acpl_data_1ch] are bit-exact in isolation (already pinned byround181_alpha_desync_fix::standalone_*), so the remaining drift sits upstream of pair0 — either inwrite_acpl_1_residual_layervs the inline residual walk insideparse_aspx_acpl_1_2_inner_body's ASPX_ACPL_1 branch, or inwrite_two_channel_datavsparse_two_channel_data— when L and Ls are simultaneously non-trivial. Total tests 784 (was 780). Round 190 closes the desync at the root cause: the two minimal A-SPX writers ([encoder_acpl3::write_aspx_data_2ch_minimal] and [encoder_acpl3::write_aspx_data_1ch_minimal]) emittedaspx_int_class = FIXFIXas the wrong prefix code:0b11(2 bits) instead of0b0(1 bit) per ETSI TS 103 190-1 Table 126. The decoder's [aspx::AspxIntClass::read] walks the prefix correctly (0→ FixFix,10→ FixVar,110/111→ VarFix / VarVar), so the writer's11start drove the parser into the VarFix branch withb_iframe = 1and Note-1 2-bit width (num_aspx_timeslots = 15 > 8):var_bord_left(2 b) +num_rel_left(2 b) +tsg_ptr(2 b) — parser consumed 9 bits in framing where the writer emitted only 3. The 6-bit drift was masked in the silence / L-only / Ls-only paths (α / β quantised to 0 ⇒ constant minimum-costacpl_data_1chbodies whosenum_param_sets_codbit positions sampled0on both sides), but with non-zero α / β the codewords shifted and the pair-1num_param_sets_codbit position landed on a1(the r187 pinned failure mode). Fix is one-line per writer: emitbw.write_bit(false)for the FIXFIX prefix. The r187 pinned-broken test (acpl1_combined_l_and_ls_pair1_currently_misaligns) is nowacpl1_full_round_trips_with_aligned_pair_lengthsand assertspair1.num_param_sets = 1. Total tests 784 (unchanged from r187 — r190 fixed the third pin in place rather than adding new ones). Round 193 lifts the round-95 5_X ASPX_ACPL_3 encoder's β1 / β2 parameter sets out of the zero-delta scaffold: a new [encoder_acpl3::extract_beta_q_per_band_carrier_energy] extracts per-parameter-band β_q from a single carrier's MDCT energy distribution (β proportional to√E[x²]keeps the wet/dry balance bounded), and a sibling [encoder_acpl3::build_5_x_acpl3_body_from_pcm_spectra_real_beta] drops it into the existingacpl_data_2ch()body in place of the two zero-deltaacpl_huff_data()codewords (α1 / α2 / β3 / γ1..γ6 stay at the round-95 minimum-bit-cost defaults). Caller-facing [encoder_ims::Ac4ImsEncoder::encode_frame_pcm_5_0_acpl3_real_beta] /encode_frame_pcm_5_1_acpl3_real_betawrap the new builder with the same channel-mode forcing and TOC framing as their round-95 counterparts. With α1 = α2 = 0 and β3 = 0 the §5.7.7.6.2 Pseudocode 119ACplModule2for the first parameter set reduces toz0 = 0.5·(x0·g1 + x1·g2 + y0·β1),z1 = 0.5·(x0·g1 + x1·g2 − y0·β1)(and analogously(z2, z3)with β2), so non-zero β1 / β2 injects the decorrelator output that gives the Ls / Rs outputs their decorrelated spaciousness. Seven integration tests intests/round193_5_x_acpl3_real_beta.rspin: round-trip to 5- / 6-channelAudioFramefor 5.0 / 5.1; silent input → all-zero β_q indices; tonal carrier + non-zerobeta_scale→ at least one non-zero β_q lane;beta_scale = 0.0is byte-for-byte identical to the round-95 scaffold (strict-superset invariant); silent inputs at anybeta_scaleare scaffold-identical; non-silent tonal inputs atbeta_scale > 0diverge from the scaffold (different β1 / β2 codeword bit-positions) while keeping the padded substream length identical. Total tests 791 (was 784).
Specs
- ETSI TS 103 190-1 — Channel-based coding + bitstream syntax.
- ETSI TS 103 190-2 — Multi-stream / Immersive / Object-based (IFM).
Installation
[]
= "0.1"
= "0.1"
= "0.0"
What's parsed (TS 103 190-1 clause 4)
- Sync frame (
ac4_syncframe(), Annex G) —0xAC40plain or0xAC41CRC-protected, plus the two-tierframe_size()(16-bit,0xFFFFescape to 24-bit). - Raw frame (
raw_ac4_frame()). - Table of contents (
ac4_toc()): bitstream_version (withvariable_bits(2)escape for version == 3), sequence_counter, wait_frames,fs_index-> 44.1 / 48 kHz,frame_rate_index-> 24…120 fps + 23.44 (Table 83 / 84),b_iframe_global, payload_base. - Presentations: per-presentation
ac4_presentation_info()walking both thepresentation_v1(default) andpresentation_v0forms. Handlespresentation_config0..=5 (M+E+D, Main+DE, Main+Assoc, M+E+D+Assoc, Main+DE+Assoc, Main+HSF) plus thepresentation_config_ext_infoescape,b_hsf_ext,b_pre_virtualizedand additional EMDF substreams. - Substream info:
ac4_substream_info()channel mode (1/2/4/7-bit withvariable_bits(2)escape), sample-frequency multiplier, bitrate_indicator, content_type + language tag, per-frame-rate-factorb_iframeflags. - Substream index table: per-substream
substream_sizewith theb_more_bits/variable_bits(2)extension. - Bit-rate indicator / content classifier / frame_rate_factor /
sf_multiplier all surfaced on the parsed
Ac4FrameInfostruct.
What's not parsed yet
- ASF / ASF-A2 / A-SPX audio coefficient coding (the heart of the
codec). The A-SPX
aspx_config()header andcompanding_control()element are parsed (ETSI §4.2.11 / §4.2.12.1); the Huffman-coded envelope / noise payload (aspx_framing,aspx_ec_data, etc.) is not. - Metadata payloads inside substreams (DRC, dialog normalization,
downmix params) — the spec's
metadata()tree is skipped by size, not parsed. - TS 103 190-2 IFM (immersive / object) extensions.
- EMDF payload bodies — the outer
emdf_payloads_substream()walker (Table 18) andemdf_payload_config()(Table 79) are parsed but the per-payloademdf_payload_byte[]opaque sequence is captured as raw bytes; per-emdf_payload_idsemantic interpretation lives in the AC-4 EMDF datatype registry [i.14] and is out of scope for the present document.
Decode path
make_decoder builds an Ac4Decoder that:
- Scans the packet for a sync word.
- Parses the full TOC + presentation + substream descriptors, and
therefore knows the channel count, sample rate (44.1 / 48 kHz
scaled by
sf_multiplier), and frame length in samples. - Emits a silence
AudioFrame(S16 zeros) with the correctchannels,sample_rate,samplesandpts.
This is enough to keep a container/demuxer pipeline running against an AC-4 track without crashing, and to exercise the TOC parser against real fixtures.
Codec id
"ac4". Also registers the ISO BMFF fourcc ac-4 so MP4 tracks tagged
with the AC-4 sample entry resolve cleanly.
License
MIT — see LICENSE.