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