xref: /titanic_52/usr/src/cmd/audio/include/audio_encode.h (revision 269e59f9a28bf47e0f463e64fc5af4a408b73b21)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1992-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef _MULTIMEDIA_AUDIO_ENCODE_H
28 #define	_MULTIMEDIA_AUDIO_ENCODE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <audio_types.h>
37 #include <audio_hdr.h>
38 
39 /*
40  * audio_encode.h
41  *
42  * u-law, A-law and linear PCM conversion tables and macros.
43  */
44 
45 /* PCM linear <-> a-law conversion tables */
46 extern short		_alaw2linear[];		/* 8-bit a-law to 16-bit PCM */
47 extern unsigned char	*_linear2alaw;		/* 13-bit PCM to 8-bit a-law */
48 
49 /* PCM linear <-> u-law conversion tables */
50 extern short		_ulaw2linear[];		/* 8-bit u-law to 16-bit PCM */
51 extern unsigned char	*_linear2ulaw;		/* 14-bit PCM to 8-bit u-law */
52 
53 /* A-law <-> u-law conversion tables */
54 extern unsigned char	_alaw2ulaw[];		/* 8-bit A-law to 8-bit u-law */
55 extern unsigned char	_ulaw2alaw[];		/* 8-bit u-law to 8-bit A-law */
56 
57 /* PCM linear <-> a-law conversion macros */
58 
59 /* a-law to 8,16,32-bit linear */
60 #define	audio_a2c(X)	((char)(_alaw2linear[(unsigned char) (X)] >> 8))
61 #define	audio_a2s(X)	(_alaw2linear[(unsigned char) (X)])
62 #define	audio_a2l(X)	(((long)_alaw2linear[(unsigned char) (X)]) << 16)
63 
64 /* 8,16,32-bit linear to a-law */
65 #define	audio_c2a(X)	(_linear2alaw[((short)(X)) << 5])
66 #define	audio_s2a(X)	(_linear2alaw[((short)(X)) >> 3])
67 #define	audio_l2a(X)	(_linear2alaw[((long)(X)) >> 19])
68 
69 /* PCM linear <-> u-law conversion macros */
70 
71 /* u-law to 8,16,32-bit linear */
72 #define	audio_u2c(X)	((char)(_ulaw2linear[(unsigned char) (X)] >> 8))
73 #define	audio_u2s(X)	(_ulaw2linear[(unsigned char) (X)])
74 #define	audio_u2l(X)	(((long)_ulaw2linear[(unsigned char) (X)]) << 16)
75 
76 /* 8,16,32-bit linear to u-law */
77 #define	audio_c2u(X)	(_linear2ulaw[((short)(X)) << 6])
78 #define	audio_s2u(X)	(_linear2ulaw[((short)(X)) >> 2])
79 #define	audio_l2u(X)	(_linear2ulaw[((long)(X)) >> 18])
80 
81 /* A-law <-> u-law conversion macros */
82 
83 #define	audio_a2u(X)	(_alaw2ulaw[(unsigned char)(X)])
84 #define	audio_u2a(X)	(_ulaw2alaw[(unsigned char)(X)])
85 
86 /*
87  * external declarations, type definitions and
88  * macro definitions for use with the G.721 routines.
89  */
90 
91 /*
92  * The following is the definition of the state structure
93  * used by the G.721/G.723 encoder and decoder to preserve their internal
94  * state between successive calls.  The meanings of the majority
95  * of the state structure fields are explained in detail in the
96  * CCITT Recommendation G.721.  The field names are essentially indentical
97  * to variable names in the bit level description of the coding algorithm
98  * included in this Recommendation.
99  */
100 struct audio_g72x_state {
101 	long yl;	/* Locked or steady state step size multiplier. */
102 	short yu;	/* Unlocked or non-steady state step size multiplier. */
103 	short dms;	/* Short term energy estimate. */
104 	short dml;	/* Long term energy estimate. */
105 	short ap;	/* Linear weighting coefficient of 'yl' and 'yu'. */
106 
107 	short a[2];	/* Coefficients of pole portion of prediction filter. */
108 	short b[6];	/* Coefficients of zero portion of prediction filter. */
109 	short pk[2];
110 			/*
111 			 * Signs of previous two samples of a partially
112 			 * reconstructed signal.
113 			 */
114 	short dq[6];
115 			/*
116 			 * Previous 6 samples of the quantized difference
117 			 * signal represented in an internal floating point
118 			 * format.
119 			 */
120 	short sr[2];
121 			/*
122 			 * Previous 2 samples of the quantized difference
123 			 * signal represented in an internal floating point
124 			 * format.
125 			 */
126 	char td;	/* delayed tone detect, new in 1988 version */
127 	unsigned char leftover[8];
128 			/*
129 			 * This array is used to store the last unpackable
130 			 * code bits in the event that the number of code bits
131 			 * which must be packed into a byte stream is not a
132 			 * multiple of the sample unit size.
133 			 */
134 	char leftover_cnt;
135 			/*
136 			 * Flag indicating the number of bits stored in
137 			 * 'leftover'.  Reset to 0 upon packing of 'leftover'.
138 			 */
139 };
140 
141 /* External tables. */
142 
143 /* Look-up table for performing fast log based 2. */
144 extern unsigned char _fmultanexp[];
145 
146 /* Look-up table for perfoming fast 6bit by 6bit multiplication. */
147 extern unsigned char _fmultwanmant[];
148 
149 /*
150  * Look-up table for performing fast quantization of the step size
151  * scale factor normalized log magnitude of the difference signal.
152  */
153 extern unsigned char _quani[];
154 
155 /* External function definitions. */
156 
157 EXTERN_FUNCTION(void g721_init_state, (struct audio_g72x_state *state_ptr));
158 EXTERN_FUNCTION(int g721_encode, (
159 			void *in_buf,
160 			int data_size,
161 			Audio_hdr *in_header,
162 			unsigned char *out_buf,
163 			int *out_size,
164 			struct audio_g72x_state *state_ptr));
165 EXTERN_FUNCTION(int g721_decode, (
166 			unsigned char *in_buf,
167 			int data_size,
168 			Audio_hdr *out_header,
169 			void *out_buf,
170 			int *out_size,
171 			struct audio_g72x_state *state_ptr));
172 
173 /*
174  * Look-up table for performing fast quantization of the step size
175  * scale factor normalized log magnitude of the difference signal.
176  */
177 extern unsigned char _g723quani[];
178 
179 /* External function definitions. */
180 
181 EXTERN_FUNCTION(void g723_init_state, (struct audio_g72x_state *state_ptr));
182 EXTERN_FUNCTION(int g723_encode, (
183 			void *in_buf,
184 			int data_size,
185 			Audio_hdr *out_header,
186 			unsigned char *out_buf,
187 			int *out_size,
188 			struct audio_g72x_state *state_ptr));
189 EXTERN_FUNCTION(int g723_decode, (
190 			unsigned char *in_buf,
191 			int data_size,
192 			Audio_hdr *out_header,
193 			void *out_buf,
194 			int *out_size,
195 			struct audio_g72x_state *state_ptr));
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 
201 #endif /* !_MULTIMEDIA_AUDIO_ENCODE_H */
202