Introduction
AC-4 is a lossy audio codec from Dolby, standardised by ETSI as TS 103 190 (part 1 and part 2).
It was designed for broadcast and streaming: it carries stereo, 5.1 and immersive channel layouts up to 22.2, object-based audio
(the basis of Dolby Atmos in broadcast), several presentations of the same programme (for example a main mix, a
commentary version and an audio description) and dialogue enhancement, and its frame rate can match the video frame rate. It is used
in ATSC 3.0 and DVB broadcasts, in streaming services and in MP4 and Matroska files. A .ac4 file is a run of AC-4 sync
frames, the form the ETSI standard defines for storing a stream as a file; most AC-4 audio is inside other containers.
Structure
A bare file has no header: sync frames, one after another. Each starts with a 16-bit sync word, then the size of the frame and the frame itself, called a raw AC-4 frame. The raw frame holds a table of contents (what presentations exist and which substreams make them up), a table of substream sizes, and then the substreams. Every frame carries its own table of contents, so a decoder can start at any frame whose substreams do not depend on earlier ones (an I-frame).
0Sync wordAC 40, orAC 41when a CRC follows the frame2 bytes2frame_size the length of the raw frame (orFF FFand a 24-bit length)2 or 5 bytes4Table of contents version, frame rate, presentations, substream groups, the substream sizesbit-packed, byte aligned…Substreams coded audio and its metadata, EMDF metadata, presentation data, object metadatasizes from the table…crc_word only forAC 412 bytes
The reference pages cover the parts of the stream:
- Sync frame – the sync word, the frame size, the CRC and how frames are found
- Table of contents – every field of ac4_toc(), presentations, substream groups, channel modes, objects
- Substreams – the audio substream, the high-frequency extension, EMDF payloads, the presentation substream and object audio metadata
- Metadata – loudness, downmix, dialogue and channel metadata that follows the audio
- In other files – the
dac4box of MP4, Matroska, WAVE and the sync-frame media type
What the explorer shows
A .ac4 file is opened by its own viewer. It finds the frames by their sync words and sizes, checks the CRC of every
0xAC41 frame, and shows each frame as a tree: the sync word, the frame size, the table of contents field by field (version, sequence
counter, frame rate, presentations, substream groups, channel modes, content types and languages, the substream index table), and then
each substream. A presentation substream, an EMDF substream and an object audio metadata substream are read to their last field. An audio
substream shows its audio size, its coded audio as one block of bytes, and its metadata (loudness, downmix, dialogue and channel
information, the EMDF payloads). The summary lists the presentations, the channel layout, the language, the frame rate, the duration and
the CRC result, and a table lists every frame.
In an MP4 file the ac-4 sample entry and its dac4 box are read field
by field, and in a Matroska file the A_AC4 track and its CodecPrivate are summarised.
A WAVE file with the format tag 0xAC40 holds sync frames in its data chunk. In all four places the audio of mono and stereo
streams is decoded and drawn as a waveform that can be played; the next section says exactly what is decoded.
A stream that needs a tool the decoder does not have says which one in the Sound row, and has no waveform.
How the structure is read
The table of contents is read bit by bit with the syntax of the two parts of the standard. The first part (TS 103 190-1) defines bitstream versions 0 and 1 with presentation information and substream information in the presentation. The second part (TS 103 190-2) defines bitstream version 2: presentations refer to substream groups, which describe channel-coded, object-coded and A-JOC substreams. The substream index table then gives the size of every substream, and each substream is read from its position with the syntax of its kind. Fields that depend on earlier fields (the channel mode decides which metadata fields exist; the presentation decides which loudness corrections are present) are read in the order the standard gives.
The audio decoder
The decoder turns the audio of a channel-coded mono, stereo or 5.0/5.1 surround substream into PCM. It works on one raw frame at a time and keeps what carries from one frame to the next (the overlap of the transform and the A-SPX state), so a stream can be decoded frame after frame, and the viewer saves that state at checkpoints to start again in the middle of a long file.
What it does
| Part of the standard | State |
|---|---|
Channel elements: single_channel_element and channel_pair_element in the SIMPLE and ASPX modes | decoded |
Audio spectral frontend (ASF): asf_transform_info, asf_psy_info, section data, the eleven spectral codebooks and the escape code, scale factors, spectral noise fill | decoded |
Stereo processing: chparam_info with M/S per band and SAP (sap_data) | decoded |
| Inverse MDCT, KBD windows, block switching (long blocks, 2, 4, 8 and 16 partial blocks, mixed sizes), 44.1 and 48 kHz and every frame length of the standard (384 to 2,048) | decoded |
A-SPX: aspx_config, framing, delta directions, harmonic, interleaved and noise flags, signal and noise envelope Huffman data, the subband group tables | read to the last bit and applied: the scale factors are delta-decoded and dequantized, the HF generator patches the low band up (pre-flattening, a second order predictor per subband, chirp-factor tonal to noise adjustment), the envelope adjuster sets the levels (limiter, boost), noise and tone generators and interleaved waveform coding are added, so the sound goes up to the A-SPX stop frequency (48 kHz streams; mono and stereo) |
| QMF analysis and synthesis (64 subbands), companding | decoded: the complex QMF banks of clauses 5.7.3 and 5.7.4 (a stream that uses A-SPX passes every frame through them, which delays the sound by 577 samples plus the A-SPX delay of 192 or 384), and the companding of the encoder undone on the low band |
| 96 and 192 kHz (the transform and band tables are in place), the HSF extension substream above 24 kHz | the core transform is coded for them but they have not been tried on a stream; the extension is not decoded |
3.0, 5.0 and 5.1 channel elements: three_channel_data, four_channel_data, five_channel_data with their chel_matsel matrices (tables 178 and 179), the two channel and mono parts, the LFE channel, the coding configurations and 2ch_mode of every codec mode | decoded: the output is L, R, C, LFE, Ls, Rs; A-SPX runs per element (L and R, Ls and Rs, C) with the companding of all the channels together |
Advanced coupling (A-CPL): acpl_config, acpl_data_1ch and _2ch, differential decoding and dequantization (tables 203 to 208), the two interpolations, the three decorrelators, the transient ducker, the coupling modules of the 5.X element | decoded for ASPX_ACPL_2 in the 5.X element and ASPX_ACPL_3 (the matrices of pseudocodes 117 to 119, read from the specification; ASPX_ACPL_3 has no stream to be checked against). ASPX_ACPL_1 (two extra side tracks with max_sfb_master), the channel pair element in the A-CPL modes and the 7.X element are not decoded yet |
| Speech spectral frontend (SSF), the 7.X channel element, immersive (7.1.4 and so on) and 22.2 layouts | not decoded: the frame is reported as needing them |
| Objects: A-JOC and Atmos substreams | parsed (see substreams), not rendered |
Dialnorm (the level of the dialogue, dialnorm_bits in quarter decibels) | always reported; the option Apply dialnorm scales the sound by 2(output level − dialnorm) / 6 (-31 dBFS by default) |
| Dynamic range control, dialogue enhancement, downmix coefficients | read as metadata, not applied: the PCM is not scaled by them |
| Frame alignment delay (clause 5.6) | not applied: the sound starts with the first transform block |
Options of the Sound tab
A surround stream has more channels than a stereo player has, so the options bar has a Channels choice: all channels (the default), a stereo downmix in the style of ITU-R BS.775 (left = L + 0.707 C + 0.707 Ls, right = R + 0.707 C + 0.707 Rs; the LFE is left out unless Include the LFE is on, and Scale the downmix divides by the sum of the gains so that nothing exceeds full scale), or any one channel alone. Apply dialnorm and Output level set the loudness as described in the table above.
The PCM is given as floating point with 1.0 as full scale. The decoding process of the standard works in 16-bit integer units (the A-SPX
levels are anchored in them), so the decoder divides by 32,768 at the end. One frame is frame_length samples per channel
(2,048 at 25 frames a second, 1,920 at 24, 1,536 at 30).
How it works
- Find the audio. The table of contents gives the substream; its first 15 bits are
audio_size, and the channel element follows the byte alignment. The channel mode comes from the table of contents; a stream that declares a multi-channel mode but codes a pair (the ExoPlayer test stream) is read as a pair when that is the reading that fits, so that the audio ends in the last byte ofaudio_size. - Read the layout.
asf_transform_infosays whether the frame is one long block or several short ones;asf_psy_infogivesmax_sfband the grouping bits, which group the short blocks that share scale factors. The scale factor band offsets come from annex B for the block length. - Read the spectrum. Per group, the sections say which of the eleven Huffman codebooks codes each run of bands. A
codeword stands for two or four quantised lines; unsigned codebooks are followed by sign bits and codebook 11 by escape codes
(
2^(n+4)plusn+4bits). The codebooks are the ETSI tables, and every one is a complete prefix code. - Scale. A line is
sign(q) · |q|^(4/3)times the band gain2^((sf − 100)/4). The first scale factor in the frame is the 8-bit reference; each other is a Huffman-coded difference (index − 60) from the one before. - Fill noise. If
b_snf_data_existsis set, bands that came out all zero get random noise at a coded level relative to the previous band. The generator is a table walk seeded fromsequence_counter, so a decoder that starts at the same frame makes the same noise. - Stereo. With
b_enable_mdct_stereo_procboth channels share the layout and onechparam_info: per band the pair is left alone, turned from mid/side (L = M + S, R = M − S), or rotated by a coded gain (L = (1 + g)M + S, R = (1 − g)M − S with g = 0.1 · alpha_q). - Undo the grouping and transform. The lines are put in window order and each block goes through an inverse MDCT (N/2-point complex FFT with pre and post rotation, divided by N), windowed with the left half of a Kaiser-Bessel-derived window for this block and the right half for the block before; where block sizes differ the window is stretched with flat and zero parts. Overlap-adding the halves gives the PCM.
- Into the QMF domain (A-SPX streams). The PCM goes through the analysis bank: per 64 samples, a 640-tap window
(
QWIN, table D.3) is applied to the last 640, five segments of 128 are summed, and a 64 by 128 complex modulation gives 64 complex subband samples. (Sample amplitude 1 gives subband amplitude about 8, so energies are 64 times larger: this is the factornum_qmf_subbandsin the scale factors.) If the stream switches companding on, the low band is expanded: per slot the levelL = 0.9105 · mean(max(|re|,|im|) + min(|re|,|im|)/2)(full scale 1) gives the gain2^(1/α) · L^((1−α)/α)withα = 0.65. - Regenerate the high band. Scale factors:
aspx_ec_datavalues are summed along frequency or added to the last envelope (time), and become energies64 · 2^(q/2)(3 dB steps:2^q) for signal and2^(6−q)for noise; a balance pair is split into two channels with a pan offset of 12. The low band is delayed by 6 slots (3 for short frames). For each subband below the first patch source a covariance of the signal at lags 0, 2 and 4 slots gives two complex predictor coefficients; the patches (subband groups copied from below the crossover up to the stop frequency) copy the signal plus the predicted terms scaled by a chirp factor that follows the transmitted tonal to noise mode (0, 0.6, 0.9, 0.98, smoothed in time). The energy of the patched signal is measured per envelope, the gain that brings it to the transmitted scale factor is limited to 1.41 times the ratio over each limiter group and the lost energy is boosted back (at most 4 dB); noise (a 512-entry complex table) and tones (every fourth slot a quarter turn, in the middle subband of the group) are added at their levels. With interleaved waveform coding the coded spectrum is added (frequency) or replaces the generated slots (time). - Back to PCM. The synthesis bank is the transpose: 64 complex samples become 128 values, 1,280 values of history are windowed and summed to 64 samples.
Not described
These pages describe the stream as far as the explorer reads it. What is not covered:
- Audio: see the audio decoder for what is decoded. The parts that are not: A-SPX at 96 and 192 kHz
(the A-SPX of mono and stereo at 44.1 and 48 kHz is decoded; the delay between the control data and the signal is applied as the
pseudocode of clause 5.7.6 states it, with no further control data delay), A-CPL in its modes
ASPX_ACPL_1and in the channel pair element, the speech spectral frontend, the 7.X channel element, the immersive channel element (7.1.4 and the like), the 96 and 192 kHz extension, about one frame in a thousand of some surround streams (frames with a transient in which the A-SPX data and two A-CPL parameter sets together do not fit the frame: they play as silence), A-JOC and object rendering, and the application of dynamic range control, dialogue enhancement and loudness metadata. Streams that use them have no waveform, or a waveform of the low band only, and the Sound row says which. - Metadata: the dynamic range control data and the dialogue enhancement data inside metadata() (the
tools_metadata_sizebits) and the DRC data of the presentation substream are shown as raw bits with their size; their fields depend on configuration sent in earlier frames. The object audio metadata of an alternative presentation (oamd_dyndata_single) is shown as raw bits. - High sampling frequency: the extension substream for 96 and 192 kHz (ac4_hsf_ext_substream) is read as far as its first field; its scale factor data is raw bytes.
- EMDF payloads: each payload is shown with its identifier, its configuration and its bytes. What an identifier means is registered outside the standard, so the payloads are not interpreted.
- Presentation version 2: some streams (the ExoPlayer test stream, for one) declare presentation version 2 and a multi-channel layout in the table of contents but carry stereo metadata. The explorer reads those substreams as stereo when that is the only reading that fits, and says so in the frame’s note. The published standard defines only presentation versions 0 and 1.
- Transport: AC-4 in MPEG transport streams and in the ATSC 3.0 transport is read by the viewers of those formats, not here.
Links
Software
- Dolby – the codec’s owner; its encoders and decoders are part of broadcast and streaming equipment, televisions and AV receivers
- ExoPlayer – Android media player library with an AC-4 extractor for sync frames and MP4 (Android)
- GPAC – MP4 toolkit that reads and writes the AC-4 sample entry (Windows, macOS, Linux)
Developers
- oxideav-ac4 – open-source AC-4 decoder and encoder (Rust, MIT licence)
- AndroidX Media – ExoPlayer’s source, with Ac4Util for the table of contents and the
dac4box (Java)
Reference
- ETSI TS 103 190-1 – Digital Audio Compression (AC-4) Standard, part 1: channel based coding
- ETSI TS 103 190-2 – Digital Audio Compression (AC-4) Standard, part 2: immersive and personalized audio