Difference between revisions of "ATRAC3"

From MultimediaWiki
Jump to navigation Jump to search
m (grammar)
(Factor out general ATRAC description.)
Line 6: Line 6:
= ATRAC3 Introduction =
= ATRAC3 Introduction =
ATRAC (Adaptive TRansform Acoustic Coding) is the collective name for audio compression technologies
developed by [[Sony]]. This codec family includes the following codecs today: ATRAC, ATRAC3,
ATRAC3plus and ATRAC Advanced lossless.
You can read about it at http://www.sony.net/Products/ATRAC3/overview/index.html#family
The ATRAC codec was introduced in 1992 with the MiniDisc. There is a good description at
http://www.minidisc.org/aes_atrac.html. It is used in MiniDisc portable players
by many companies.
ATRAC3 is the next generation of the ATRAC codec. There are three major implementations for the PC:
ATRAC3 is the next generation of the ATRAC codec. There are three major implementations for the PC:

Revision as of 06:15, 29 November 2018

Found in some old RealMedia files. The same as the Sony ATRAC.

ATRAC3 Introduction

ATRAC3 is the next generation of the ATRAC codec. There are three major implementations for the PC: RealAudio8 atrc, the Sony ATRAC3 for Audio Compression Manager (ACM) and the Sonic Stage implementation.

ATRAC3 supports several different constant bitrates ("flavors"). The following table shows the bitrate, the size of a frame and the coding mode for each flavor respectively:

No             bitrate   frame size (stereo)     coding mode   samples per frame
--   -----------------   -------------------   -------------   -----------------
0     66 kbps  (66150)             192 bytes    joint stereo    1024 per channel
1     94 kpbs  (93713)             272 bytes    joint stereo    1024 per channel
2    105 kbps (104738)             304 bytes   normal stereo    1024 per channel
3    132 kpbs (132300)             384 bytes   normal stereo    1024 per channel
4    146 kbps (146081)             424 bytes   normal stereo    1024 per channel
5    176 kbps (176400)             512 bytes   normal stereo    1024 per channel
6    264 kbps (264600)             768 bytes   normal stereo    1024 per channel
7    352 kbps (352800)            1024 bytes   normal stereo    1024 per channel

Encoding algorithm

  • Split the input signal into 4 bands using a Quadrature mirror filter (QMF).
  • Perform gain control analysis to obtain gain control data.
  • Convert all four bands into frequency domain using Modified Cosine Transform (MDCT or MLT).
  • Find tonal components.
  • Quantization
  • Encode the bitstream.

Even though this is for ATRAC2 (http://www.minidisc.org/atrac2.html) most of it applies to ATRAC3.

Decoding algorithm

  • Parse the bitstream and extract the following:
    • gain control data
    • tonal components
    • quantized spectral coefficients
  • inverse quantization of the tonal components and spectral coefficients
  • Merge tonal components and other spectral coefficients together.
  • Reconstruct the timedomain signal using inverse MDCT.
  • gain compensation
  • Apply the QMF synthesis filter to reconstruct the sound.

Tonal components

ATRAC3 extracts the psychoacoustically important tonal components from the input signal spectra and encodes them separate from the less important spectral data. A tone component is a group of consecutive spectral coefficients, described with parameters such as location and with. This allows finer quantization of such coefficients than a quantization within fixed subbands.

Joint-stereo mode

ATRAC3 uses joint-stereo coding at low bitrates (66 and 94 kbps) to achieve better compression.

Bitstream overview

The ATRAC3 bitstream consists of so-called "Channel Sound Units". In stereo mode there are two such units. The structure of an unit is shown below:

| Header                             |
| Gain compensation data             |
| Tonal components                   |
| Other spectral coefficients        |

Decoding Specification

Bitstream parsing

Parts is bold mean that a certain amount of bits are to be consumed from the bitstream.


If not in the joint-stereo mode, this header should be interpreted as follows:

  • id (6 bits) - should contain the value 0x28
  • nBandsCoded (2 bits) - number of QMF bands were coded. The value of 0 indicates one coded band.

Gain compensation data

For each coded QMF band (see nBandsCoded above) the following data will be transmitted:

  • numGainData (3 bits) - number of gain change points coded as level/location pairs. Value of 0 indicates no coded pairs. Each coded pair consists of the following fields:
  • levcode (4 bits) - level code
  • loccode (5 bits) - location code

This data is identical with the gain control tool from the MPEG AAC SSR profile that were also developed by Sony. Please refer to section "Gain compensation" below for a description how to interpret this data.

Tonal components

The presence of tonal components is indicated by the following field:

  • numToneComp (5 bits) - Number of coded tonal components. The value of 0 indicates no coded tonal components.
  • coding_mode_selector(2 bits) -- If this is equal to 2, return error. If this is equal to 3 then every component has it's own bit to select the coefficients coding mode. (VLC/CLC). If this is equal to 1 then all the components are CLC coded. If this is 0 all components are VLC coded. (coding_mode)
  • For each tonal component
    • For each number of bands, get band flags
      • band_flags (1 bit) -- Flag per band in the Tonal Component to be processed
    • coded_values (3 bits) -- amount of coded coefficients
    • quant_step_index (3 bits) -- index into the quant step table, if it is less then/equal to 1 then return error
    • if coding_mode_selector is 3
      • coding_mode (1 bit) -- get the bands coding mode (CLC/VLC)

Other spectral coefficients

The coefficients coded in this block are assumed not to be "tonal" (noise etc.) They are quantized and coded within fixed subbands. The ATRAC3 divides the whole MDCT spectrum (1024 points) into 32 subbands of unequal width (higher frequencies - wider bands). For each subband ATRAC3 will transmit a scalefactor index and VLC codes for each quantized spectral coefficients. The format of this this block is shown below:

  • numSubbands (5 bits) - number of coded subbands. The value of 0 indicates no coded subbands.
  • codingMode (1 bit) - value indicates the coding mode for ALL subbands:
0 - coefficients are coded using variable length codes (VLC)
1 - coefficients are coded using constant length codes (CLC)

Then follow the array of coding table indexes for each coded band:

  • tblIndex (3 bits) - indicates the coding table used (VLC) or number of bits used (CLC). The value of "0" indicates "skipped" (not coded) subband.

Then follows the array of scalefactor indexes for each coded subband:

  • sfIndex (6 bits) - indicates the index into scalefactor decoding table (see below).

Then follows the codes for each spectral coefficient in this subband. The VLC codes are shown below.


In RealMedia files the bitstream is scrambled. To unscramble the stream, perform a XOR on every 32 bits in the frame. The hex value to XOR with is 0x537F6103.

Extra data format

In RealMedia files the extra data is as follows (big-endian order):

INT32	id, always 4
INT16	samples per frame, always 1024 * 2
INT16	delay, not used but always 0x88E
INT16	stereo coding mode, 2 - normal stereo, 0x12 - joint stereo

The length of this data is always 10 bytes.



Three stacked Quadrature Mirror Filters are used to split the signal into 4 different frequency bands.

  • 0 to 2.75625 kHz (DC to f/16)
  • 2.75625 to 5.5125 kHz (f/16 to f/8)
  • 5.5125 to 11.025 kHz (f/8 to f/4)
  • 11.025 to 22.05 kHz (f/4 to f/2)

QMF window

The coeffs used in the QMF filter.

float qmf_48tap_half[24] = {
  -0.00001461907, -0.00009205479, -0.000056157569, 0.00030117269,
  0.0002422519,-0.00085293897, -0.0005205574, 0.0020340169,
  0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944,
  -0.000061169922, -0.01344162, 0.0024626821, 0.021736089,
  -0.007801671, -0.034090221, 0.01880949, 0.054326009,
  -0.043596379, -0.099384367, 0.13207909, 0.46424159

These coeffs need to be mirrored and scaled by 2.

for (i=0 ; i<24; i++) {
  s = qmf_48tap_half[i] * 2.0;
  qmf_window[i] = s;
  qmf_window[47 - i] = s;


The transform is a regular MDCT.


The overlapping window is not the same for encoding and decoding. Perfect reconstruction is ensured by the encoding and decoding windows having a inverse relation. Technical details can be found in H. Malvar's paper Fast algorithms for orthogonal modulated lapped transforms [1]

for (i = 0; i < 256; i++) {
  we[i] = (sin(((i + 0.5) / 256 - 0.5) * PI) + 1.0) * 0.5;
for (i = 0; i < 256; i++) {
  wd[i] = we[i]/(we[i]^2 + we[255-i]^2)

Huffman coding

VLC coding is used to compress the tonal and spectral coefficients.

Huffman tables

huffcode1[9] = {

huffbits1[9] = {

huffcode2[5] = {

huffbits2[5] = {

huffcode3[7] = {

huffbits3[7] = {

huffcode4[9] = {

huffbits4[9] = {

huffcode5[15] = {

huffbits5[15] = {

huffcode6[31] = {

huffbits6[31] = {

huffcode7[63] = {

huffbits7[63] = {