Audio Encoding G711 Checksum

Source: Internet
Author: User
G711 Encoding G711It is an international Telecommunication Union ITU-T Custom-made set of speech compression standards, which represent the logarithmic PCM (logarithmic pulse-code modulation) sampling standard, mainly used for telephones. It mainly uses the Pulse code modulation to the audio sampling, the sampling rate is 8k per second. It uses a 64Kbps uncompressed channel to transmit voice signals. The compression rate is 1:2, which is to compress 16 bits of data into 8 bits.     G.711 is the mainstream waveform sound codec. There are two main compression algorithms under the G.711 standard. One is &micro-law algorithm (also known as often u-law, Ulaw, Mu-law), mainly used in North America and Japan, the other is A-law algorithm, mainly used in Europe and other parts of the world. Among them, the latter is specially designed to facilitate computer processing. Checksum

The CRC32 is used, the full name is cyclic redundancy check

Take CRC16 as an example:

Idea: Take a character (8bit), check the character bit by digit, if it is 1,crc^crc_mul, and if the original CRC highest bit is 1, then crc^crc_mul the left 1 bits, otherwise it just moves left one bit. After calculating one character, load the next character.

#include <stdio.h>

#define CRC_MUL 0x1021//generating polynomial

unsigned int cal_crc (unsigned char *ptr, unsigned char len)
{
unsigned char i;
unsigned int crc=0;
while (len--! = 0)
{
for (i=0x80; i!=0; i>>=1)
{
if ((crc&0x8000)!=0)
{
crc<<=1;
Crc^= (Crc_mul);
}else{
crc<<=1;
}
if ((*ptr&i)!=0)
{
CRC ^= (Crc_mul);
}
}
PTR + +;
}
return (CRC);
}

int main ()
{
unsigned char i[8] = {0X00,0X00,0X00,0X00,0X06,0X0D,0XD2,0XE3};
unsigned int CRC;
CRC=CAL_CRC (i,8);
return 0;
}
/* Results: manual Calculation example of 7123dbc0*/CRC check code

Generate Polynomial: G (X) =x4+x3+1, requires the CRC checksum of the binary sequence 10110011.

(1) G (x) =x4+x3+1, binary bit string is 11001, (there are several sides of X, corresponding 2 of the bits of a few square is 1)

(2) Because the check code 4 bits, so 10110011 and then add 4 0, get 101100110000, with "Modulo 2 Division" (In fact, or ^) can be obtained results;

Figure CRC Check code calculation example

(3) crc^101100110000 get 101100110100. Sent to the receiving end;

(4) The receiving end receives 101100110100 divided by 11001 ("Modulo 2 Division" method to remove), the remainder of 0 is error-free; CRC calibration Principle

After the K-bit information code and then splicing the R-bit check code, the message encoding length is n bits, therefore, this code is called (n,k) code.

Theorem: for a given (n,k) code, it can be proved that there is a polynomial g (x) with a maximum power of n=k+r, which exists and exists only one R-th polynomial g (x), which makes .

which

M (x): k-th information polynomial,

R (x): R-1-times Check polynomial,

g (x): Generate polynomial:.

The sender generates a CRC check code for R bit by the specified g (x), and the receiver verifies that the CRC check code of the received message code is 0 by this g (X).

Assuming that the message is sent with information polynomial C (x), the C (x) is shifted to the left R bit, it can be represented as C (x) *2R, so that the right side of C (x) will be vacated the position of R-bit check code, Division (modulo 2), the remainder R is the checksum code. The CRC code sent is to verify that the received message encoding is correct, still doing modulo 2 except:. generation polynomial of CRC

The selection of the resulting polynomial should meet the following criteria:

A, the highest and lowest bits of the generated polynomial must be 1.

b, when the transmitted information (CRC code) any one error, is generated polynomial modulo 2 after the addition, should make the remainder is not 0.

C, different bits when errors, should make the remainder different.

D, the remainder to continue to do modulo 2 in addition, should make the remainder cycle.

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.