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