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