Lossless codec-Ape code interpretation series (1)

Source: Internet
Author: User

Monkey's audio --- ape encoding Principle

Ape code interpretation series (2)

Ape code interpretation series (III)

Three major theories of ape compression:
(1) Mid/side Coding
Mid/side coding is a common method in 2 channel audio encoding. By performing R and l data transformations, the related values are reduced, thus reducing the number of Quantizing digits.

The mid (x) is the midpoint between the L and R channels and the side (Y) is the difference in the channels

X = (L + r)/2;

Y = (l-R );

Decompress code for 2 channels:

If (nchannels = 2)

{

If (nbitssample = 16)

{

Int Nr = x-(y/2 );

Int NL = nR + Y;

// Error check for Overflow

If (NR <-32768) | (NR> 32767) | (NL <-32768) | (NL> 32767 ))

Return error_id;

* (Int16 *) poutput = (int16) NR;
Calculate_crc_byte // ape frame have CRC check.
Calculate_crc_byte
* (Int16 *) poutput = (int16) nL;
Calculate_crc_byte
Calculate_crc_byte

}

Else if

{

.......

}

}

(2) predictor
The correlation between audio signals in the time domain is very large.
Use adapting's predictor (adapting Gini filter) to extract the predictable part of the signal.

Ape uses adaptive prediction. The principle is to use the past several samples values to predict the current value. The more the past values are used, the closer the predicted value to the actual value.

Encode the difference value between the real value and the predicted value, which further reduces the number of quantified bits.

There are three models for predicting the current time series value: Ma model-Moving Average Model, AR model-Self-regression model, ARMA model-auto-regression moving average model.

For more information about the three models, see <random process>.

In the next articleArticleI will discuss in detail how ape codec applies this theory to implement lossless encoding.

(3) rice Coding
Number of digits required for prediction Encoding
These bitwise codes are used for signals without Overflow.
The overflow signal is represented by a special identifier.

Rice coding is a type of entropy encoding, which is equivalent to the Huffman subclass. It is not very common, so we are not very familiar with it.

The lossless compression effect of Rice coding on small-value data is obvious. The last step (1) (2) is to make the samples value as small as possible and be prepared for rice coding.

Rice coding consists of the basic sequence FS --- foundamental sequence and sample splitting. FS is a funny number. Value m

A code consisting of M 0 and 1. The code book is unique and does not need to be used. The split technique assumes that K minimum valid bits of each input in a block are random. Therefore, it cannot be compressed.

Parameter k, for a n-bit data, encoding, first of all, the most effective bit of the N-K using FS encoding, and then directly using binary encoding Random k-bit, then the results are encoded using FS.

Connect to the K-bit LSB to form the rice code.

Rice encoding requires estimation of the parameter K. Effective estimation methods are provided for different encoding methods (in the next series, we will analyze the methods used by ape codec)

 

All rice codes are extended to non-negative value n

Each code word is divided into two parts: High-Order (unary) and low-order (Binary). The specific encoding is as follows: if the encoding parameter is K and the non-negative integer to be encoded is n

Unary = n/2 ^ K;

Binary = n % 2 ^ K;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.