/*---------------------------------------------------------------------------*/
/*
  File: g726.h

  G.726 codec.
*/
/*---------------------------------------------------------------------------*/

#ifndef G726_H_
#define G726_H_

#ifdef __cplusplus
extern "C" {
#endif
/*---------------------------------------------------------------------------*/

#define G726_BIT_RATE_INDEX_16K         0
#define G726_BIT_RATE_INDEX_24K         1
#define G726_BIT_RATE_INDEX_32K         2
#define G726_BIT_RATE_INDEX_40K	        3

#define G726_COMPAND_MODE_ALAW          0
#define G726_COMPAND_MODE_ULAW          1
#define G726_COMPAND_MODE_LINEAR        2


typedef struct tag_g726_coder
{
  word yl_l;      /* Locked or steady state step size multiplier. */
  short yl_h;
  short yu;       /* Unlocked or non-steady state step size multiplier. */
  short dms;      /* Short term energy estimate. */
  short dml;      /* Long term energy estimate. */
  short ap;       /* Linear weighting coefficient of 'yl' and 'yu'. */

  short a[2];     /* Coefficients of pole portion of prediction filter. */
  short b[6];     /* Coefficients of zero portion of prediction filter. */
  short pk[2];    /* Signs of previous two samples of a partially */
                  /* reconstructed signal. */
  short dq[6*3];  /* Previous 6 samples of the quantized difference */
                  /* signal represented in an internal floating point */
                  /* format. (sign,exp,mant) */
  short sr[2*3];  /* Previous 2 samples of the quantized difference */
                  /* signal represented in an internal floating point */
                  /* format. (sign,exp,mant) */
  char tdp;       /* delayed tone detect, new in 1988 version */
  short dq_pos;
  short sr_pos;
  const short *quantizer_coeffs;
  const short *dequantizer_coeffs;
  word bit_rate_index;
  word compand_mode;
} t_g726_coder;


typedef t_g726_coder t_g726_encoder;
typedef t_g726_coder t_g726_decoder;


void g726_encoder_init (t_g726_encoder *p_g726, word bit_rate_index, word compand_mode);
byte g726_encoder_exec (t_g726_encoder *p_g726, short sample);
void g726_decoder_init (t_g726_decoder *p_g726, word bit_rate_index, word compand_mode);
short g726_decoder_exec (t_g726_decoder *p_g726, byte b);


/*---------------------------------------------------------------------------*/
#ifdef __cplusplus
}
#endif

#endif

/*---------------------------------------------------------------------------*/
