G.711 Audio Encoding

Source: Internet
Author: User

A law and U law is defined as follows: a law code is a compression/decompression algorithm for pulse coding defined by ITU-T (International Telecommunications Institute of Standards. Most countries in the world adopt the law compression algorithm (including China ). The United States uses the U law Algorithm for pulse encoding. The English definition is roughly as follows:

A-Law and U-law are companding schemes used in telephone network
Get more dynamics to the 8 bit samples that is available with linear
Coding. typically 12 .. 14 bit samples (linear scale) sampled at 8 kHz
Sample are companded to 8 bit (logarithmic scale) for transmission
Over 64 kbit/s data channel. In the processing ing end the data is then
Converter back to linear scale (12 .. 14 bit) and played back.
Converted back
U-law definition
U-Law (pronounced Mu-Law) is
SGN (m) (| M |) | M |
Y = ------- ln (1 + u | -- |) | -- | = <1
Ln (1 + u) (| MP |) | MP |
Another definition for Mu-law I have seen
Ln (1 + 255 | x |)
Output = SGN (x )---------------------
Ln (1 + 255)

X = normalized input (between-1 and 1)
255 = compression Parameter
SGN (x) = sign (+/-) of X

A-law definition
A-LAW is
| A (m) | M | 1
| ------- (--) | -- | = <-
| 1 + ln a (MP) | MP |
Y = |
| SGN (m) (| M |) 1 | M |
| ------ (1 + ln a | -- |)-= <| -- | = <1
| 1 + ln a (| MP |) A | MP |
Values of U = 100 and 255, A = 87.6, MP is the peak message value, M is
The current quantised message value. (The formulae get simpler if you
Substitute X for M/MP and SGN (x) for SGN (m); then-1 <= x <= 1 .)
Converting from U-law to A-LAW is in a sense "lossy" since there are
Quantizing errors introduced in the conversion.
". The U-law used in North America and Japan, and the A-LAW used in
Europe and the rest of the world and international routes .."
References:
? Modern digital and analog communication systems, B. P. lathi .,
2nd ed. ISBN 0-03-0933-x
? Transmission Systems for communications, century th edition,
Members of the technical staff at Bell Telephone Laboratories,
Bell Telephone Laboratories, inreceivated, copyright 1959,196 4,
1970,198 2

The following describes the core of g.711 C code.

# Ifndef _ g711_h _
# DEFINE _ g711_h _


# Ifdef _ cplusplus
Extern "C "...{
# Endif/* _ cplusplus */


Unsigned char linear2ulaw (short pcm_val );
Short ulaw2linear (unsigned char u_val );

Unsigned char linear2alaw (short pcm_val );
Short alaw2linear (unsigned char a_val );

Unsigned char alaw2ulaw (unsigned char a_val );
Unsigned char ulaw2alaw (unsigned char u_val );


# Ifdef _ cplusplus
}
# Endif/* _ cplusplus */


# Endif/* _ g711_h _*/

Generally, law A is used in many projects, so

Unsigned char linear2alaw (short pcm_val );
Short alaw2linear (unsigned char a_val );

Note that the data types used in audio processing are unsigned char and short, where the official code for the ITU-T is fine, in openh323, the Data Types of g.711 codecs all use int and unsigned, which results in data overflow and cannot work properly. I encountered this problem when I did it for the first time, replace the int with short and unsigned char.

 

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.