2.6. Implementation of G.711 codec

The ITU-T Rec. G.711 presents two PCM audio codecs called A-law and U-law. They both transform linear PCM signal into logarithmic PCM. They both operate on single samples.

A-law uses 13-bit linear PCM vector and transforms it into 8-bit logarithmic PCM vector while encoding process. U-law uses 14-bit linear PCM, transforming it into 8-bit. Non-professional sound devices cannot generate nether 13 nor 14-bit samples. In this implementation 16-bit samples are passed and the input of coder. Every sample is converted into 13 or 14-bit sample by cutting off the less significant bits.

Coding process does not require logarithmic calculations. ITU-T Rec. G.711 [3] defines tables, that are used while coding 7and decoding process. Although A-law and U-law operate on the same algorithms, they use slightly different tables. A-law is used as an example in this implementation of G.711 codec.

14-bit input signal for A-law coder can take value from between -4096 and 4096. This range is divided into several segments having various length. And each segment is divided into equal length intervals with interval size characteristic for each interval. The sum of all intervals in all segments is equal 255 (to fit it into one byte). For greater values of the input signal, the intervals are bigger, e.g. 128 for intervals from between 2048 and 4096, so bigger values are encoded with bigger coding error. While encoding a sample, first the segment is determined. Next, appropriate interval is this segment must be determined (it is called offset). Next, sum of all intervals in less segments is added to this offset and this is the 8-bit encoded value. While decoding, appropriate segment and appropriate interval are determined. The output value is always treated as if it was the value from the middle of the interval (the average value) and in this way original value is restored.

This codec is compatible with codec management module. After selection of this codec functions snd_encode, snd_decode are used to transform the audio signal. But first the length of the input buffer must be set, using auxiliary snd_ functions.