G726 Class Reference
[Audio Codec - ITU-T Recomendation G726]

A class which implements ITU-T (formerly CCITT) Recomendation G726 "40, 32, 24, 16 kbit/s Adaptive Differential Pulse Code Modulation (ADPCM)". More...

#include <G726.h>

List of all members.

Public Types

enum  Law {
  uLaw = 0,
  ALaw = 1,
  PCM16 = 2
}
enum  Rate {
  Rate16kBits = 2,
  Rate24kBits = 3,
  Rate32kBits = 4,
  Rate40kBits = 5
}

Public Member Functions

 G726 ()
void Reset ()
void SetLaw (Law law)
void SetRate (Rate rate)
unsigned Encode (unsigned pcm)
unsigned Decode (unsigned adpcm)
unsigned Encode (void *dst, int dstOffset, const void *src, size_t srcSize)
unsigned Decode (void *dst, const void *src, int srcOffset, unsigned srcSize)

Private Member Functions

void InputPCMFormatConversionAndDifferenceSignalComputation (unsigned S, int SE, int &D)
 FIGURE 4/G.726 from Section 4.2.1 - Input PCM format conversion and difference signal computation.
void AdaptiveQuantizer (int D, unsigned Y, unsigned &I)
 FIGURE 5/G.726 from Section 4.2.2 - Adaptive quantizer.
void InverseAdaptiveQuantizer (unsigned I, unsigned Y, unsigned &DQ)
 FIGURE 6/G.726 from Section 4.2.3 - Inverse adaptive quantizer.
void QuantizerScaleFactorAdaptation1 (unsigned AL, unsigned &Y)
 FIGURE 7/G.726 (Part 1) from Section 4.2.4 - Quantizer scale factor adaptation.
void QuantizerScaleFactorAdaptation2 (unsigned I, unsigned Y)
 FIGURE 7/G.726 (Part 2) from Section 4.2.4 - Quantizer scale factor adaptation.
void AdaptationSpeedControl1 (unsigned &AL)
 FIGURE 8/G.726 (Part 1) from Section 4.2.5 - Adaptation speed control.
void AdaptationSpeedControl2 (unsigned I, unsigned y, unsigned TDP, unsigned TR)
 FIGURE 8/G.726 (Part 2) from Section 4.2.5 - Adaptation speed control.
void AdaptativePredictorAndReconstructedSignalCalculator1 (int &SE, int &SEZ)
 FIGURE 9/G.726 (Part1) from Section 4.2.6 - Adaptative predictor and reconstructed signal calculator.
void AdaptativePredictorAndReconstructedSignalCalculator2 (unsigned DQ, unsigned TR, int SE, int SEZ, int &SR, int &A2P)
 FIGURE 9/G.726 (Part2) from Section 4.2.6 - Adaptative predictor and reconstructed signal calculator.
void ToneAndTransitionDetector1 (unsigned DQ, unsigned &TR)
 FIGURE 10/G.726 (Part 1) from Section 4.2.7 - Tone and transition detector.
void ToneAndTransitionDetector2 (int A2P, unsigned TR, unsigned &TDP)
 FIGURE 10/G.726 (Part 2) from Section 4.2.7 - Tone and transition detector.
void OutputPCMFormatConversionAndSynchronousCodingAdjustment (int SR, int SE, unsigned Y, unsigned I, unsigned &SD)
 FIGURE 11/G.726 from Section 4.2.8 - Output PCM format conversion and synchronous coding adjustment.
void DifferenceSignalComputation (int SL, int SE, int &D)
 FIGURE A.4/G.726 from Section A.3.3 - Difference signal computation.
void OutputLimiting (int SR, int &S0)
 FIGURE A.5/G.726 from Section A.3.5 - Output limiting (decoder only).
unsigned EncodeDecode (unsigned input, bool encode)
 The top level method which implements the complete algorithm for both encoding and decoding.

Detailed Description

A class which implements ITU-T (formerly CCITT) Recomendation G726 "40, 32, 24, 16 kbit/s Adaptive Differential Pulse Code Modulation (ADPCM)".

G726 replaces recomendations G721 and G723.

Note, this implemetation reproduces bugs found in the G191 reference implementation of G726. These bugs can be controlled by the IMPLEMENT_G191_BUGS macro.

See also:
IMPLEMENT_G191_BUGS
Version:
2005-02-13
2006-05-20
  • Changed code to use standard typedefs, e.g. replaced uint8 with uint8_t, and made use of size_t.
2007-01-13
  • Fixed GCC compilation warnings.

Definition at line 62 of file G726.h.


Member Enumeration Documentation

enum G726::Law

Enumeration used to specify the coding law used for encoder input and decoder output.

Enumerator:
uLaw 

u law

ALaw 

A law

PCM16 

16 bit uniform PCM values. These are 'left justified' values corresponding to the 14 bit values in G726 Annex A.

Definition at line 68 of file G726.h.

enum G726::Rate

Enumeration used to specify the ADPCM bit-rate.

Enumerator:
Rate16kBits 

16k bits per second (2 bits per ADPCM sample)

Rate24kBits 

24k bits per second (3 bits per ADPCM sample)

Rate32kBits 

32k bits per second (4 bits per ADPCM sample)

Rate40kBits 

40k bits per second (5 bits per ADPCM sample)

Definition at line 78 of file G726.h.


Constructor & Destructor Documentation

G726::G726 (  ) 

Contructor which initialises the object to the reset state.

See also:
Reset()
Since:
2005-02-13

Definition at line 90 of file G726.h.


Member Function Documentation

void G726::Reset (  ) 

Clears the internal state variables to their 'reset' values. Call this function before starting to decode/encode a new audio stream.

Definition at line 1192 of file G726.cpp.

void G726::SetLaw ( Law  law  ) 

Set the encoding law used for encoder input and decoder output.

Parameters:
law The encoding law.

Definition at line 1215 of file G726.cpp.

void G726::SetRate ( Rate  rate  ) 

Set the ADPCM bit-rate used for encoder output and decoder intput.

Parameters:
rate The ADPCM bit-rate.

Definition at line 1222 of file G726.cpp.

unsigned G726::Encode ( unsigned  pcm  ) 

Encodes a single PCM value as an ADPCM value.

Precondition:
The coding law and ADPCM bit-rate should have been previous initialised with SetLaw() and SetRate().
Parameters:
pcm The PCM value to encode. The bits in this value which lie outside the range of values for the currently set encoding law, are ignored.
Returns:
The encoded ADPCM value. The number of significant bits in this value are dependant on the bit-rate set by SetRate(). Unused bits are set to zero.

Definition at line 1229 of file G726.cpp.

unsigned G726::Decode ( unsigned  adpcm  ) 

Decodes a single ADPCM value into a PCM value.

Precondition:
The coding law and ADPCM bit-rate should have been previous initialised with SetLaw() and SetRate().
Parameters:
adpcm The ADPCM value to decode. The bits in this value which lie outside the range of values for the currently set bit-rate, are ignored.
Returns:
The decoded PCM value. This is in the format specified by SetLaw().
See also:
IMPLEMENT_G191_BUGS

Definition at line 1235 of file G726.cpp.

unsigned G726::Encode ( void *  dst,
int  dstOffset,
const void *  src,
size_t  srcSize 
)

Encode a buffer of uniform PCM values into ADPCM values.

Each ADPCM value only occupies the minimum number of bits required and successive values occupy adjacent bit positions. E.g. Four 3 bit ADPCM values (A,B,C,D) are stored in two successive bytes like this: 1st byte: ccbbbaaa 2nd byte: ----dddc. Note that any unused bits in the last byte are set to zero.

Precondition:
The coding law and ADPCM bit-rate should have been previous initialised with SetLaw() and SetRate().
Parameters:
dst Pointer to location to store ADPCM values.
dstOffset Offset from dst, in number-of-bits, at which the decoded values will be stored. I.e. the least significant bit of the first ADPCM value will be stored in byte

 dst[dstOffset>>3]   

at bit position

 dstOffset&7         

Where the bit 0 is the least significant bit in a byte and bit 7 is the most significant bit.

src Pointer to the buffer of PCM values to be converted.
srcSize The size in bytes of the buffer at src. Must be a multiple of the size of a single PCM sample.
Returns:
The number of bits were stored in the dst buffer.
Since:
2005-02-13

Definition at line 1242 of file G726.cpp.

unsigned G726::Decode ( void *  dst,
const void *  src,
int  srcOffset,
unsigned  srcSize 
)

Decode a buffer of ADPCM values into uniform PCM values.

Each ADPCM value only occupies the minimum number of bits required and successive values occupy adjacent bit positions. E.g. Four 3 bit ADPCM values (A,B,C,D) are stored in two successive bytes like this: 1st byte: ccbbbaaa 2nd byte: ----dddc.

Precondition:
The coding law and ADPCM bit-rate should have been previous initialised with SetLaw() and SetRate().
Parameters:
dst Pointer to location to store PCM values.
src Pointer to the buffer of ADPCM values to be converted.
srcOffset Offset from src, in number-of-bits, from which the ADPCM values will be read. I.e. the least significant bit of the first ADPCM value will be read from byte

 src[srcOffset>>3]   

at bit position

 srcOffset&7         

Where the bit 0 is the least significant bit in a byte and bit 7 is the most significant bit.

srcSize The number of bits to be read from the buffer at src. Must be a multiple of the size of a single ADPCM value.
Returns:
The number of bytes which were stored in the dst buffer.
See also:
IMPLEMENT_G191_BUGS
Since:
2005-02-13

Definition at line 1315 of file G726.cpp.

unsigned G726::EncodeDecode ( unsigned  input,
bool  encode 
) [private]

The top level method which implements the complete algorithm for both encoding and decoding.

Parameters:
input Either the PCM input to the encoder or the ADPCM input to the decoder.
encode A flag which if true makes this method perform the encode function. If the flag is false then the decode function is performed.
Returns:
Either the ADPCM output to the encoder or the PCM output to the decoder.

Definition at line 1130 of file G726.cpp.


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.1