RK Audio

From MultimediaWiki
Jump to navigation Jump to search

RK Audio is a lossless audio coding algorithm.

Container format

All values are little-endian.

3 bytes - "RKA"
1 byte  - version ('5'-'7')
4 bytes - raw audio size
4 bytes - sampling rate
1 byte  - number of channels
1 byte  - bits per sample
1 byte  - method * 16 + cmode (known methods: fast/normal/max, cmode 0 - lossless, 0-3 - simple lossy, 4-7 - VRQ lossy)
1 byte  - flags (bit 0 - true stereo, bit 1 - seek table present)

Without seek table audio data coded as single block follows immediately, otherwise there is 4-byte work with an offset to frame sizes. Frame sizes are stored as 24-bit integers. Frame codes 131072 bytes of audio data

Compression details

Compression algorithm works by applying LPC filter with order up to 257 to the residues, all data is coded with adaptive models and arithmetic coder.

Frame data consists of interleaved channel data blocks each coding 2560 samples. Depending on coded mode it can be coded in up to three segments. Each segment contains filter order, filter coefficients, and residues. Filter coefficients and residues are decoded using context-dependent adaptive models, the rest is coded using adaptive models.

Stereo reconstruction:

 new_l = (l * 2 + r + 1) >> 1;
 new_r = (l * 2 - r + 1) >> 1;