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