g722_enc_dec.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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: g722.h,v 1.10 2006/06/16 12:45:53 steveu Exp $
  22. *
  23. * Modifications for WebRtc, 2011/04/28, by tlegrand:
  24. * -Changed to use WebRtc types
  25. * -Added new defines for minimum and maximum values of short int
  26. */
  27. /*! \file */
  28. #ifndef MODULES_THIRD_PARTY_G722_G722_H_
  29. #define MODULES_THIRD_PARTY_G722_G722_H_
  30. #include <stdint.h>
  31. /*! \page g722_page G.722 encoding and decoding
  32. \section g722_page_sec_1 What does it do?
  33. The G.722 module is a bit exact implementation of the ITU G.722 specification
  34. for all three specified bit rates - 64000bps, 56000bps and 48000bps. It passes
  35. the ITU tests.
  36. To allow fast and flexible interworking with narrow band telephony, the encoder
  37. and decoder support an option for the linear audio to be an 8k samples/second
  38. stream. In this mode the codec is considerably faster, and still fully
  39. compatible with wideband terminals using G.722.
  40. \section g722_page_sec_2 How does it work?
  41. ???.
  42. */
  43. #define WEBRTC_INT16_MAX 32767
  44. #define WEBRTC_INT16_MIN -32768
  45. enum { G722_SAMPLE_RATE_8000 = 0x0001, G722_PACKED = 0x0002 };
  46. typedef struct {
  47. /*! TRUE if the operating in the special ITU test mode, with the band split
  48. filters disabled. */
  49. int itu_test_mode;
  50. /*! TRUE if the G.722 data is packed */
  51. int packed;
  52. /*! TRUE if encode from 8k samples/second */
  53. int eight_k;
  54. /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
  55. int bits_per_sample;
  56. /*! Signal history for the QMF */
  57. int x[24];
  58. struct {
  59. int s;
  60. int sp;
  61. int sz;
  62. int r[3];
  63. int a[3];
  64. int ap[3];
  65. int p[3];
  66. int d[7];
  67. int b[7];
  68. int bp[7];
  69. int sg[7];
  70. int nb;
  71. int det;
  72. } band[2];
  73. unsigned int in_buffer;
  74. int in_bits;
  75. unsigned int out_buffer;
  76. int out_bits;
  77. } G722EncoderState;
  78. typedef struct {
  79. /*! TRUE if the operating in the special ITU test mode, with the band split
  80. filters disabled. */
  81. int itu_test_mode;
  82. /*! TRUE if the G.722 data is packed */
  83. int packed;
  84. /*! TRUE if decode to 8k samples/second */
  85. int eight_k;
  86. /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
  87. int bits_per_sample;
  88. /*! Signal history for the QMF */
  89. int x[24];
  90. struct {
  91. int s;
  92. int sp;
  93. int sz;
  94. int r[3];
  95. int a[3];
  96. int ap[3];
  97. int p[3];
  98. int d[7];
  99. int b[7];
  100. int bp[7];
  101. int sg[7];
  102. int nb;
  103. int det;
  104. } band[2];
  105. unsigned int in_buffer;
  106. int in_bits;
  107. unsigned int out_buffer;
  108. int out_bits;
  109. } G722DecoderState;
  110. #ifdef __cplusplus
  111. extern "C" {
  112. #endif
  113. G722EncoderState* WebRtc_g722_encode_init(G722EncoderState* s,
  114. int rate,
  115. int options);
  116. int WebRtc_g722_encode_release(G722EncoderState* s);
  117. size_t WebRtc_g722_encode(G722EncoderState* s,
  118. uint8_t g722_data[],
  119. const int16_t amp[],
  120. size_t len);
  121. G722DecoderState* WebRtc_g722_decode_init(G722DecoderState* s,
  122. int rate,
  123. int options);
  124. int WebRtc_g722_decode_release(G722DecoderState* s);
  125. size_t WebRtc_g722_decode(G722DecoderState* s,
  126. int16_t amp[],
  127. const uint8_t g722_data[],
  128. size_t len);
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. #endif /* MODULES_THIRD_PARTY_G722_G722_H_ */