1 /* This source code is a product of Sun Microsystems, Inc. and is provided
2  * for unrestricted use.  Users may copy or modify this source code without
3  * charge.
4  *
5  * SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
6  * THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
7  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
8  *
9  * Sun source code is provided with no support and without any obligation on
10  * the part of Sun Microsystems, Inc. to assist in its use, correction,
11  * modification or enhancement.
12  *
13  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
14  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
15  * OR ANY PART THEREOF.
16  *
17  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
18  * or profits or other special, indirect and consequential damages, even if
19  * Sun has been advised of the possibility of such damages.
20  *
21  * Sun Microsystems, Inc.
22  * 2550 Garcia Avenue
23  * Mountain View, California  94043
24  */
25 
26 /*
27  * g72x.h
28  *
29  * Header file for CCITT conversion routines.
30  *
31  */
32 #ifndef _G72X_H
33 #define	_G72X_H
34 
35 /* aliases */
36 #define g721_decoder lsx_g721_decoder
37 #define g721_encoder lsx_g721_encoder
38 #define g723_24_decoder lsx_g723_24_decoder
39 #define g723_24_encoder lsx_g723_24_encoder
40 #define g723_40_decoder lsx_g723_40_decoder
41 #define g723_40_encoder lsx_g723_40_encoder
42 #define g72x_init_state lsx_g72x_init_state
43 #define predictor_pole lsx_g72x_predictor_pole
44 #define predictor_zero lsx_g72x_predictor_zero
45 #define quantize lsx_g72x_quantize
46 #define reconstruct lsx_g72x_reconstruct
47 #define step_size lsx_g72x_step_size
48 #define tandem_adjust_alaw lsx_g72x_tandem_adjust_alaw
49 #define tandem_adjust_ulaw lsx_g72x_tandem_adjust_ulaw
50 #define update lsx_g72x_update
51 
52 #define	AUDIO_ENCODING_ULAW	(1)	/* ISDN u-law */
53 #define	AUDIO_ENCODING_ALAW	(2)	/* ISDN A-law */
54 #define	AUDIO_ENCODING_LINEAR	(3)	/* PCM 2's-complement (0-center) */
55 
56 /*
57  * The following is the definition of the state structure
58  * used by the G.721/G.723 encoder and decoder to preserve their internal
59  * state between successive calls.  The meanings of the majority
60  * of the state structure fields are explained in detail in the
61  * CCITT Recommendation G.721.  The field names are essentially indentical
62  * to variable names in the bit level description of the coding algorithm
63  * included in this Recommendation.
64  */
65 struct g72x_state {
66 	long yl;	/* Locked or steady state step size multiplier. */
67 	short yu;	/* Unlocked or non-steady state step size multiplier. */
68 	short dms;	/* Short term energy estimate. */
69 	short dml;	/* Long term energy estimate. */
70 	short ap;	/* Linear weighting coefficient of 'yl' and 'yu'. */
71 
72 	short a[2];	/* Coefficients of pole portion of prediction filter. */
73 	short b[6];	/* Coefficients of zero portion of prediction filter. */
74 	short pk[2];	/*
75 			 * Signs of previous two samples of a partially
76 			 * reconstructed signal.
77 			 */
78 	short dq[6];	/*
79 			 * Previous 6 samples of the quantized difference
80 			 * signal represented in an internal floating point
81 			 * format.
82 			 */
83 	short sr[2];	/*
84 			 * Previous 2 samples of the quantized difference
85 			 * signal represented in an internal floating point
86 			 * format.
87 			 */
88 	char td;	/* delayed tone detect, new in 1988 version */
89 };
90 
91 /* External function definitions. */
92 
93 extern void g72x_init_state(struct g72x_state *);
94 extern int g721_encoder(
95 	int sample,
96 	int in_coding,
97 	struct g72x_state *state_ptr);
98 extern int g721_decoder(
99 	int code,
100 	int out_coding,
101 	struct g72x_state *state_ptr);
102 extern int g723_16_encoder(
103         int sample,
104         int in_coding,
105         struct g72x_state *state_ptr);
106 extern int g723_16_decoder(
107         int code,
108         int out_coding,
109         struct g72x_state *state_ptr);
110 extern int g723_24_encoder(
111 	int sample,
112 	int in_coding,
113 	struct g72x_state *state_ptr);
114 extern int g723_24_decoder(
115 	int code,
116 	int out_coding,
117 	struct g72x_state *state_ptr);
118 extern int g723_40_encoder(
119 	int sample,
120 	int in_coding,
121 	struct g72x_state *state_ptr);
122 extern int g723_40_decoder(
123 	int code,
124 	int out_coding,
125 	struct g72x_state *state_ptr);
126 
127 int predictor_zero(struct g72x_state *state_ptr);
128 int predictor_pole(struct g72x_state *state_ptr);
129 int step_size(struct g72x_state *state_ptr);
130 int quantize(int d,
131 	     int y,
132 	     short const *table,
133 	     int size);
134 int reconstruct(int sign,
135 		int dqln,
136 		int y);
137 void update(int code_size,
138 	    int y,
139 	    int wi,
140 	    int fi,
141 	    int dq,
142 	    int sr,
143 	    int dqsez,
144 	    struct g72x_state *state_ptr);
145 int tandem_adjust_alaw(int sr,
146 		       int se,
147 		       int y,
148 		       int i,
149 		       int sign,
150 		       short const *qtab);
151 int tandem_adjust_ulaw(int sr,
152 		       int se,
153 		       int y,
154 		       int i,
155 		       int sign,
156 		       short const *qtab);
157 #endif /* !_G72X_H */
158