g72x.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * This source code is a product of Sun Microsystems, Inc. and is provided
  3. * for unrestricted use. Users may copy or modify this source code without
  4. * charge.
  5. *
  6. * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
  7. * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  8. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  9. *
  10. * Sun source code is provided with no support and without any obligation on
  11. * the part of Sun Microsystems, Inc. to assist in its use, correction,
  12. * modification or enhancement.
  13. *
  14. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  15. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
  16. * OR ANY PART THEREOF.
  17. *
  18. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  19. * or profits or other special, indirect and consequential damages, even if
  20. * Sun has been advised of the possibility of such damages.
  21. *
  22. * Sun Microsystems, Inc.
  23. * 2550 Garcia Avenue
  24. * Mountain View, California 94043
  25. */
  26. /*
  27. * g72x.h
  28. *
  29. * Header file for CCITT conversion routines.
  30. *
  31. */
  32. #ifndef _G72X_H
  33. #define _G72X_H
  34. #define AUDIO_ENCODING_ULAW (1) /* ISDN u-law */
  35. #define AUDIO_ENCODING_ALAW (2) /* ISDN A-law */
  36. #define AUDIO_ENCODING_LINEAR (3) /* PCM 2's-complement (0-center) */
  37. /*
  38. * The following is the definition of the state structure
  39. * used by the G.721/G.723 encoder and decoder to preserve their internal
  40. * state between successive calls. The meanings of the majority
  41. * of the state structure fields are explained in detail in the
  42. * CCITT Recommendation G.721. The field names are essentially identical
  43. * to variable names in the bit level description of the coding algorithm
  44. * included in this Recommendation.
  45. */
  46. struct g72x_state {
  47. long yl; /* Locked or steady state step size multiplier. */
  48. short yu; /* Unlocked or non-steady state step size multiplier. */
  49. short dms; /* Short term energy estimate. */
  50. short dml; /* Long term energy estimate. */
  51. short ap; /* Linear weighting coefficient of 'yl' and 'yu'. */
  52. short a[2]; /* Coefficients of pole portion of prediction filter. */
  53. short b[6]; /* Coefficients of zero portion of prediction filter. */
  54. short pk[2]; /*
  55. * Signs of previous two samples of a partially
  56. * reconstructed signal.
  57. */
  58. short dq[6]; /*
  59. * Previous 6 samples of the quantized difference
  60. * signal represented in an internal floating point
  61. * format.
  62. */
  63. short sr[2]; /*
  64. * Previous 2 samples of the quantized difference
  65. * signal represented in an internal floating point
  66. * format.
  67. */
  68. char td; /* delayed tone detect, new in 1988 version */
  69. };
  70. /* External function definitions. */
  71. void g72x_init_state(struct g72x_state*);
  72. int g721_encoder(int sample, int in_coding, struct g72x_state* state_ptr);
  73. int g721_decoder(int code, int out_coding, struct g72x_state* state_ptr);
  74. int g723_24_encoder(int sample, int in_coding, struct g72x_state* state_ptr);
  75. int g723_24_decoder(int code, int out_coding, struct g72x_state* state_ptr);
  76. int g723_40_encoder(int sample, int in_coding, struct g72x_state* state_ptr);
  77. int g723_40_decoder(int code, int out_coding, struct g72x_state* state_ptr);
  78. int quantize(int d, int y, short* table, int size);
  79. int reconstruct(int, int, int);
  80. void
  81. update(int code_size,
  82. int y,
  83. int wi,
  84. int fi,
  85. int dq,
  86. int sr,
  87. int dqsez,
  88. struct g72x_state* state_ptr);
  89. int tandem_adjust_alaw(int sr, int se, int y, int i, int sign, short* qtab);
  90. int tandem_adjust_ulaw(int sr, int se, int y, int i, int sign, short* qtab);
  91. unsigned char linear2alaw(int pcm_val);
  92. int alaw2linear(unsigned char a_val);
  93. unsigned char linear2ulaw(int pcm_val);
  94. int ulaw2linear(unsigned char u_val);
  95. int predictor_zero(struct g72x_state* state_ptr);
  96. int predictor_pole(struct g72x_state* state_ptr);
  97. int step_size(struct g72x_state* state_ptr);
  98. #endif /* !_G72X_H */