ATRAC3
- FOURCC: atrc
- Company: Real
- Samples: http://samples.mplayerhq.hu/real/AC-atrc/
Found in some old RealMedia files. Suspected to be similar to, or the same as, Sony ATRAC.
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: 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 four bands using Quadrature mirror filter (QMF).
- Gain control analyze and 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.
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 IMDCT.
- 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 qantization 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 format of a unit is as follows:
-------------------------------------- | Identification info | -------------------------------------- | Gain compensation data | -------------------------------------- | Tonal components | -------------------------------------- | Other spectral coefficients | --------------------------------------
Decoding Specification
Scrambling
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
It is always 10 bytes of data.
Transforms
QMF
MLT
The transform is a regular MDCT.
Windows
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]
Encoding
for (i = 0; i < 256; i++) { we[i] = (sin(((i + 0.5) / 256 - 0.5) * PI) + 1.0) * 0.5; }
Decoding
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 spectral coefficients.
Huffman tables
huffcode1[9] = { 0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F, }; huffbits1[9] = { 1,3,3,4,4,5,5,5,5, }; huffcode2[5] = { 0x0,0x4,0x5,0x6,0x7, }; huffbits2[5] = { 1,3,3,3,3, }; huffcode3[7] = { 0x0,0x4,0x5,0xC,0xD,0xE,0xF, }; huffbits3[7] = { 1,3,3,4,4,4,4, }; huffcode4[9] = { 0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F, }; huffbits4[9] = { 1,3,3,4,4,5,5,5,5, }; huffcode5[15] = { 0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0x1C,0x1D,0x3C,0x3D,0x3E,0x3F, }; huffbits5[15] = { 2,3,3,4,4,4,4,4,4,5,5,6,6,6,6, }; huffcode6[31] = { 0x0,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x14,0x15,0x16,0x17,0x18,0x19,0x34,0x35, 0x36,0x37,0x38,0x39,0x3A,0x3B,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F, }; huffbits6[31] = { 3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7, }; huffcode7[63] = { 0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11,0x24,0x25,0x26,0x27,0x28, 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x68,0x69,0x6A,0x6B,0x6C, 0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2, 0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF, }; huffbits7[63] = { 3,4,4,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, };