ATRAC3

From MultimediaWiki
Jump to navigation Jump to search

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 two major implementations for the PC: RealAudio8 atrc and the Sony ATRAC3 for Audio Compression Manager (ACM).

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

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 the same as the MPEG AAC SSR profile with the exception of a special window.

MLT Window table

atrac_window[256] = {
   9.41253620112548e-06,8.47234623506665e-05,0.000235401996178553,0.000461561692645773,
   0.000763372576329857,0.00114106200635433,0.00159491400700063,0.00212526903487742,
   0.00273252697661519,0.00341714196838439,0.00417962903156877,0.00502056023105979,
   0.00594056397676468,0.00694032711908221,0.00802059844136238,0.00918218307197094,
   0.0104259504005313,0.0117528103291988,0.013163760304451,0.0146598499268293,
   0.0162421800196171,0.017911909148097,0.019670270383358,0.0215185508131981,
   0.023458119481802,0.0254903696477413,0.0276167895644903,0.0298389103263617,
   0.0321583412587643,0.0345767587423325,0.0370958782732487,0.0397174991667271,
   0.0424434691667557,0.04527572914958,0.048216238617897,0.0512670800089836,
   0.0544303394854069,0.0577081888914108,0.0611028708517551,0.0646167024970055,
   0.0682519972324371,0.0720112174749374,0.0758968368172646,0.0799113884568214,
   0.084057442843914,0.0883376598358154,0.0927547365427017,0.0973114371299744,
   0.102010503411293,0.106854900717735,0.111847400665283,0.116990998387337,
   0.122288599610329,0.127743199467659,0.133357793092728,0.139135494828224,
   0.145079404115677,0.151192396879196,0.157477602362633,0.163938298821449,
   0.170577302575111,0.177397698163986,0.184402495622635,0.191594794392586,
   0.198977395892143,0.20655320584774,0.214325100183487,0.222295597195625,
   0.230467602610588,0.238843500614166,0.247425600886345,0.256216287612915,
   0.265217810869217,0.274431705474854,0.283860206604004,0.293504595756531,
   0.303366303443909,0.313446491956711,0.323745906352997,0.334265112876892,
   0.345004290342331,0.355963587760925,0.367142498493195,0.378540098667145,
   0.390155404806137,0.401986807584763,0.414032310247421,0.426289200782776,
   0.438754886388779,0.451425611972809,0.464297711849213,0.477366387844086,
   0.490626811981201,0.504073321819305,0.517699420452118,0.531498670578003,
   0.545463383197784,0.559585571289062,0.573856592178345,0.588267087936401,
   0.602807104587555,0.617465972900391,0.632232785224915,0.647095382213593,
   0.662041485309601,0.677057981491089,0.692131519317627,0.707247793674469,
   0.722392320632935,0.737549722194672,0.752704918384552,0.767841517925262,
   0.782943487167358,0.797994315624237,0.812976777553558,0.827874422073364,
   0.842669785022736,0.857345581054688,0.871884822845459,0.886269986629486,
   0.900484383106232,0.91451108455658,0.928333282470703,0.941935122013092,
   0.955300509929657,0.968414008617401,0.981260776519775,0.993826687335968,
   1.00609803199768,1.01806199550629,1.02970600128174,1.04101896286011,
   1.05199003219604,1.06261003017426,1.07287001609802,1.08276200294495,
   1.09228003025055,1.10141599178314,1.11016702651978,1.118528008461,
   1.12649703025818,1.13407099246979,1.14124798774719,1.14803004264832,
   1.15441703796387,1.16040897369385,1.16601002216339,1.17122399806976,
   1.17605304718018,1.18050396442413,1.18457996845245,1.18828999996185,
   1.19163799285889,1.19463300704956,1.19728195667267,1.1995929479599,
   1.20157599449158,1.20323896408081,1.20459198951721,1.2056440114975,
   1.20640504360199,1.20688498020172,1.20709502696991,1.2070449590683,
   1.20674395561218,1.20620501041412,1.20543599128723,1.20444905757904,
   1.20325398445129,1.20186197757721,1.20028102397919,1.19852304458618,
   1.19659698009491,1.19451296329498,1.19228100776672,1.18991005420685,
   1.18740999698639,1.18478798866272,1.18205404281616,1.17921698093414,
   1.17628395557404,1.17326295375824,1.17016303539276,1.1669909954071,
   1.16375398635864,1.16045904159546,1.15711295604706,1.15372204780579,
   1.15029203891754,1.14683103561401,1.14334201812744,1.13983201980591,
   1.13630700111389,1.13276994228363,1.1292279958725,1.12568402290344,
   1.12214398384094,1.11861002445221,1.11508798599243,1.11158096790314,
   1.10809302330017,1.10462701320648,1.1011860370636,1.09777402877808,
   1.09439396858215,1.09104800224304,1.08773899078369,1.08446896076202,
   1.08124196529388,1.07805800437927,1.07492101192474,1.07183194160461,
   1.06879305839539,1.06580603122711,1.062873005867,1.05999398231506,
   1.05717301368713,1.05440902709961,1.05170500278473,1.04906094074249,
   1.04647898674011,1.0439590215683,1.04150295257568,1.03911197185516,
   1.03678703308105,1.03452801704407,1.03233599662781,1.03021097183228,
   1.028156042099,1.02616894245148,1.0242520570755,1.02240598201752,
   1.02063000202179,1.01892495155334,1.01729202270508,1.01573097705841,
   1.01424205303192,1.01282596588135,1.01148295402527,1.01021301746368,
   1.00901699066162,1.00789403915405,1.00684499740601,1.00587105751038,
   1.00497102737427,1.00414502620697,1.0033940076828,1.00271797180176,
   1.00211596488953,1.00159001350403,1.00113797187805,1.00076198577881,
   1.00046098232269,1.0002349615097,1.00008499622345,1.00000894069672,
};

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,
};