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
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.
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]
23 * Copyright (c) 1992-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #ifndef _MULTIMEDIA_AUDIO_ENCODE_H
28 #define _MULTIMEDIA_AUDIO_ENCODE_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <audio_types.h>
37 #include <audio_hdr.h>
42 * u-law, A-law and linear PCM conversion tables and macros.
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 */
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 */
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 */
57 /* PCM linear <-> a-law conversion macros */
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)
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])
69 /* PCM linear <-> u-law conversion macros */
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)
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])
81 /* A-law <-> u-law conversion macros */
83 #define audio_a2u(X) (_alaw2ulaw[(unsigned char)(X)])
84 #define audio_u2a(X) (_ulaw2alaw[(unsigned char)(X)])
87 * external declarations, type definitions and
88 * macro definitions for use with the G.721 routines.
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.
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'. */
107 short a
[2]; /* Coefficients of pole portion of prediction filter. */
108 short b
[6]; /* Coefficients of zero portion of prediction filter. */
111 * Signs of previous two samples of a partially
112 * reconstructed signal.
116 * Previous 6 samples of the quantized difference
117 * signal represented in an internal floating point
122 * Previous 2 samples of the quantized difference
123 * signal represented in an internal floating point
126 char td
; /* delayed tone detect, new in 1988 version */
127 unsigned char leftover
[8];
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.
136 * Flag indicating the number of bits stored in
137 * 'leftover'. Reset to 0 upon packing of 'leftover'.
141 /* External tables. */
143 /* Look-up table for performing fast log based 2. */
144 extern unsigned char _fmultanexp
[];
146 /* Look-up table for perfoming fast 6bit by 6bit multiplication. */
147 extern unsigned char _fmultwanmant
[];
150 * Look-up table for performing fast quantization of the step size
151 * scale factor normalized log magnitude of the difference signal.
153 extern unsigned char _quani
[];
155 /* External function definitions. */
157 EXTERN_FUNCTION(void g721_init_state
, (struct audio_g72x_state
*state_ptr
));
158 EXTERN_FUNCTION(int g721_encode
, (
161 Audio_hdr
*in_header
,
162 unsigned char *out_buf
,
164 struct audio_g72x_state
*state_ptr
));
165 EXTERN_FUNCTION(int g721_decode
, (
166 unsigned char *in_buf
,
168 Audio_hdr
*out_header
,
171 struct audio_g72x_state
*state_ptr
));
174 * Look-up table for performing fast quantization of the step size
175 * scale factor normalized log magnitude of the difference signal.
177 extern unsigned char _g723quani
[];
179 /* External function definitions. */
181 EXTERN_FUNCTION(void g723_init_state
, (struct audio_g72x_state
*state_ptr
));
182 EXTERN_FUNCTION(int g723_encode
, (
185 Audio_hdr
*out_header
,
186 unsigned char *out_buf
,
188 struct audio_g72x_state
*state_ptr
));
189 EXTERN_FUNCTION(int g723_decode
, (
190 unsigned char *in_buf
,
192 Audio_hdr
*out_header
,
195 struct audio_g72x_state
*state_ptr
));
201 #endif /* !_MULTIMEDIA_AUDIO_ENCODE_H */