TAK

From MultimediaWiki
Jump to: navigation, search

TAK (Tom's lossless Audio Kompressor), formerly known as YALAC (Yet Another Lossless Audio Codec) is a lossless audio codec developed by Thomas Becker. Last version is 2.2.0. Source code is not available.



Stream format

Integers are little-endian. 24-bit CRC is employed for checking data integrity.

TAK file consists of signature ("tBaK"), obligatory metadata and compressed audio data. APE tags may be present at the end of file.

Metadata

Metadata consists of series of objects, each object has 32-bit header.

Header meaning:

  7 bits - object type
  1 bit  - reserved
 24 bits - object size

Metadata object types:

 0x00 - end of metadata
 0x01 - stream info
 0x02 - seektable (obsoleted in TAK 1.1.1)
 0x03 - original file data
 0x04 - encoder info
 0x05 - padding (since 1.0.3)
 0x06 - MD5 checksum (since 1.1.1)
 0x07 - last frame information (since 1.1.1)

Non-empty metadata object ends with 3 bytes of object data CRC.

Stream information

Stream information consist of:

  Encoder info
  Frame size information
  Audio format
  
Encoder info
  6 bits    codec type
  4 bits    encoder profile (= encoder preset at least for versions <= 1.1.2)

Known codec types:

  0    Integer 24 bit (TAK 1.0)
  1    Experimental!
  2    Integer 24 bit (TAK 2.0)
  3    LossyWav (TAK 2.1 Beta)
  4    Integer 24 bit MC (TAK 2.2)
Frame size information
  4 bits    frame size type
 35 bits    number of samples in whole stream

Possible frame types:

  0    94 ms of audio
  1    125 ms
  2    188 ms
  3    250 ms
  4    4096 samples
  5    8192 samples
  6    16384 samples
  7    512 samples
  8    1024 samples
  9    2048 samples
 10    obsoleted in 1.1.0, invalid, never used
 11    obsoleted in 1.1.0, invalid, never used
 12-14    reserved
 15    frame contains number of samples stored in next 35 bits (not supported yet)
Audio format
  3 bits    data type (should be 0 = PCM)
 18 bits    sample rate - 6000
  5 bits    sample bits - 8
  4 bits    audio channels - 1 (5 bits in 1.1.1 version, last bit is never
                                used anyway because older encoders did not
                                supported multi-channel input)
  1 bit     is extension present

(>= 2.2.0 only)

            if extension is present:
  5 bits    valid bits per sample
  1 bit     is speaker assignment present
            if speaker assignment present:

6xCh bits speaker assignment for each channel

supported assignments:

   0    none
   1    FRONT_LEFT
   2    FRONT_RIGHT
   3    FRONT_CENTER
   4    LOW_FREQUENCY
   5    BACK_LEFT
   6    BACK_RIGHT
   7    FRONT_LEFT_OF_CENTER
   8    FRONT_RIGHT_OF_CENTER
   9    BACK_CENTER
  10    SIDE_LEFT
  11    SIDE_RIGHT
  12    TOP_CENTER
  13    TOP_FRONT_LEFT
  14    FRONT_CENTER
  15    FRONT_RIGHT
  16    BACK_LEFT
  17    BACK_CENTER
  18    BACK_RIGHT

Original file data

Called "simple wave data", this contains trailer and footer from original file to allow perfect reconstruction:

  0-2   trailer size
  3-6   footer size
  trailer data
  footer data

Encoder info

  24 bits    encoder version (8 bits per each version component)
   4 bits    preset
   2 bits    evaluation
   2 bits    reserved

Last frame information

 40 bits    frame position relative to the beginning of audio data
 24 bits    frame size

Audio data

Frame header

 16 bits    syncword (0xA0FF little-endian)
  1 bit     last frame
  1 bit     frame contains stream information + extra info (see "stream information" above and "extra info" bellow)
  1 bit     frame contains metadata (unsupported)
 21 bits    frame number
 14 bits    sample count - 1 (only for the last frame)
  2 bits    padding (only for the last frame)
            if stream information is present:
  stream information
  extra info
0-7 bits    padding
 24 bits    CRC

Extra info

  1 bit     previous frame position is present (currently always set to 0)
  5 bits    reserved (should be 0)
            if previous frame position is present:
 25 bits    offset to the previous frame header from the end of this header

Frame data

 X  bits    bitstream
0-7 bits    padding
24  bits    CRC