g722.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * SpanDSP - a series of DSP components for telephony
  3. *
  4. * g722.h - The ITU G.722 codec.
  5. *
  6. * Written by Steve Underwood <steveu@coppice.org>
  7. *
  8. * Copyright (C) 2005 Steve Underwood
  9. *
  10. * Despite my general liking of the GPL, I place my own contributions
  11. * to this code in the public domain for the benefit of all mankind -
  12. * even the slimy ones who might try to proprietize my work and use it
  13. * to my detriment.
  14. *
  15. * Based on a single channel G.722 codec which is:
  16. *
  17. ***** Copyright (c) CMU 1993 *****
  18. * Computer Science, Speech Group
  19. * Chengxiang Lu and Alex Hauptmann
  20. *
  21. * $Id$
  22. */
  23. /*! \file */
  24. #if !defined(_G722_H_)
  25. #define _G722_H_
  26. /*! \page g722_page G.722 encoding and decoding
  27. \section g722_page_sec_1 What does it do?
  28. The G.722 module is a bit exact implementation of the ITU G.722 specification for all three
  29. specified bit rates - 64000bps, 56000bps and 48000bps. It passes the ITU tests.
  30. To allow fast and flexible interworking with narrow band telephony, the encoder and decoder
  31. support an option for the linear audio to be an 8k samples/second stream. In this mode the
  32. codec is considerably faster, and still fully compatible with wideband terminals using G.722.
  33. \section g722_page_sec_2 How does it work?
  34. ???.
  35. */
  36. enum
  37. {
  38. G722_SAMPLE_RATE_8000 = 0x0001,
  39. G722_PACKED = 0x0002
  40. };
  41. #ifndef INT16_MAX
  42. #define INT16_MAX 32767
  43. #endif
  44. #ifndef INT16_MIN
  45. #define INT16_MIN (-32768)
  46. #endif
  47. typedef struct
  48. {
  49. /*! TRUE if the operating in the special ITU test mode, with the band split filters
  50. disabled. */
  51. int itu_test_mode;
  52. /*! TRUE if the G.722 data is packed */
  53. int packed;
  54. /*! TRUE if encode from 8k samples/second */
  55. int eight_k;
  56. /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
  57. int bits_per_sample;
  58. /*! Signal history for the QMF */
  59. int x[24];
  60. struct
  61. {
  62. int s;
  63. int sp;
  64. int sz;
  65. int r[3];
  66. int a[3];
  67. int ap[3];
  68. int p[3];
  69. int d[7];
  70. int b[7];
  71. int bp[7];
  72. int sg[7];
  73. int nb;
  74. int det;
  75. } band[2];
  76. unsigned int in_buffer;
  77. int in_bits;
  78. unsigned int out_buffer;
  79. int out_bits;
  80. } g722_encode_state_t;
  81. typedef struct
  82. {
  83. /*! TRUE if the operating in the special ITU test mode, with the band split filters
  84. disabled. */
  85. int itu_test_mode;
  86. /*! TRUE if the G.722 data is packed */
  87. int packed;
  88. /*! TRUE if decode to 8k samples/second */
  89. int eight_k;
  90. /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
  91. int bits_per_sample;
  92. /*! Signal history for the QMF */
  93. int x[24];
  94. struct
  95. {
  96. int s;
  97. int sp;
  98. int sz;
  99. int r[3];
  100. int a[3];
  101. int ap[3];
  102. int p[3];
  103. int d[7];
  104. int b[7];
  105. int bp[7];
  106. int sg[7];
  107. int nb;
  108. int det;
  109. } band[2];
  110. unsigned int in_buffer;
  111. int in_bits;
  112. unsigned int out_buffer;
  113. int out_bits;
  114. } g722_decode_state_t;
  115. #ifdef __cplusplus
  116. extern "C" {
  117. #endif
  118. g722_encode_state_t *g722_encode_init(g722_encode_state_t *s, int rate, int options);
  119. int g722_encode_release(g722_encode_state_t *s);
  120. int g722_encode(g722_encode_state_t *s, uint8_t g722_data[], const int16_t amp[], int len);
  121. g722_decode_state_t *g722_decode_init(g722_decode_state_t *s, int rate, int options);
  122. int g722_decode_release(g722_decode_state_t *s);
  123. int g722_decode(g722_decode_state_t *s, int16_t amp[], const uint8_t g722_data[], int len);
  124. #ifdef __cplusplus
  125. }
  126. #endif
  127. #endif