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