g722_enc_dec.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #if !defined(_G722_ENC_DEC_H_)
  29. #define _G722_ENC_DEC_H_
  30. #include "tinydav_config.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 for all three
  34. specified bit rates - 64000bps, 56000bps and 48000bps. It passes the ITU tests.
  35. To allow fast and flexible interworking with narrow band telephony, the encoder and decoder
  36. support an option for the linear audio to be an 8k samples/second stream. In this mode the
  37. codec is considerably faster, and still fully compatible with wideband terminals using G.722.
  38. \section g722_page_sec_2 How does it work?
  39. ???.
  40. */
  41. #define TDAV_INT16_MAX 32767
  42. #define TDAV_INT16_MIN -32768
  43. enum {
  44. G722_SAMPLE_RATE_8000 = 0x0001,
  45. G722_PACKED = 0x0002
  46. };
  47. typedef struct {
  48. /*! TRUE if the operating in the special ITU test mode, with the band split filters
  49. disabled. */
  50. int itu_test_mode;
  51. /*! TRUE if the G.722 data is packed */
  52. int packed;
  53. /*! TRUE if encode from 8k samples/second */
  54. int eight_k;
  55. /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
  56. int bits_per_sample;
  57. /*! Signal history for the QMF */
  58. int x[24];
  59. struct {
  60. int s;
  61. int sp;
  62. int sz;
  63. int r[3];
  64. int a[3];
  65. int ap[3];
  66. int p[3];
  67. int d[7];
  68. int b[7];
  69. int bp[7];
  70. int sg[7];
  71. int nb;
  72. int det;
  73. } band[2];
  74. unsigned int in_buffer;
  75. int in_bits;
  76. unsigned int out_buffer;
  77. int out_bits;
  78. } g722_encode_state_t;
  79. typedef struct {
  80. /*! TRUE if the operating in the special ITU test mode, with the band split filters
  81. disabled. */
  82. int itu_test_mode;
  83. /*! TRUE if the G.722 data is packed */
  84. int packed;
  85. /*! TRUE if decode to 8k samples/second */
  86. int eight_k;
  87. /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
  88. int bits_per_sample;
  89. /*! Signal history for the QMF */
  90. int x[24];
  91. struct {
  92. int s;
  93. int sp;
  94. int sz;
  95. int r[3];
  96. int a[3];
  97. int ap[3];
  98. int p[3];
  99. int d[7];
  100. int b[7];
  101. int bp[7];
  102. int sg[7];
  103. int nb;
  104. int det;
  105. } band[2];
  106. unsigned int in_buffer;
  107. int in_bits;
  108. unsigned int out_buffer;
  109. int out_bits;
  110. } g722_decode_state_t;
  111. #ifdef __cplusplus
  112. extern "C" {
  113. #endif
  114. g722_encode_state_t *g722_encode_init(g722_encode_state_t *s, int rate, int options);
  115. int g722_encode_release(g722_encode_state_t *s);
  116. int g722_encode(g722_encode_state_t *s,
  117. uint8_t g722_data[],
  118. const int16_t amp[],
  119. int len);
  120. g722_decode_state_t *g722_decode_init(g722_decode_state_t *s, int rate, int options);
  121. int g722_decode_release(g722_decode_state_t *s);
  122. int g722_decode(g722_decode_state_t *s,
  123. int16_t amp[],
  124. const uint8_t g722_data[],
  125. int len);
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif