Wed Oct 28 11:45:43 2009

Asterisk developer's documentation


ulaw.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief u-Law to Signed linear conversion
00021  */
00022 
00023 #ifndef _ASTERISK_ULAW_H
00024 #define _ASTERISK_ULAW_H
00025 
00026 
00027 /*!
00028  * To init the ulaw to slinear conversion stuff, this needs to be run.
00029  */
00030 void ast_ulaw_init(void);
00031 
00032 #define AST_ULAW_BIT_LOSS  3
00033 #define AST_ULAW_STEP      (1 << AST_ULAW_BIT_LOSS)
00034 #define AST_ULAW_TAB_SIZE  (32768 / AST_ULAW_STEP + 1)
00035 #define AST_ULAW_SIGN_BIT  0x80
00036 
00037 /*! \brief converts signed linear to mulaw */
00038 #ifndef G711_NEW_ALGORITHM
00039 extern unsigned char __ast_lin2mu[16384];
00040 #else
00041 extern unsigned char __ast_lin2mu[AST_ULAW_TAB_SIZE];
00042 #endif
00043 
00044 /*! help */
00045 extern short __ast_mulaw[256];
00046 
00047 #ifndef G711_NEW_ALGORITHM
00048 
00049 #define AST_LIN2MU(a) (__ast_lin2mu[((unsigned short)(a)) >> 2])
00050 
00051 #else
00052 
00053 #define AST_LIN2MU_LOOKUP(mag)                                 \
00054    __ast_lin2mu[((mag) + AST_ULAW_STEP / 2) >> AST_ULAW_BIT_LOSS]
00055 
00056 
00057 /*! \brief convert signed linear sample to sign-magnitude pair for u-Law */
00058 static inline void ast_ulaw_get_sign_mag(short sample, unsigned *sign, unsigned *mag)
00059 {
00060        /* It may look illogical to retrive the sign this way in both cases,
00061         * but this helps gcc eliminate the branch below and produces
00062         * faster code */
00063        *sign = ((unsigned short)sample >> 8) & AST_ULAW_SIGN_BIT;
00064 #if defined(G711_REDUCED_BRANCHING)
00065        {
00066                unsigned dual_mag = (-sample << 16) | (unsigned short)sample;
00067                *mag = (dual_mag >> (*sign >> 3)) & 0xffffU;
00068        }
00069 #else
00070        if (sample < 0)
00071                *mag = -sample;
00072        else
00073                *mag = sample;
00074 #endif /* G711_REDUCED_BRANCHING */
00075 }
00076 
00077 static inline unsigned char AST_LIN2MU(short sample)
00078 {
00079        unsigned mag, sign;
00080        ast_ulaw_get_sign_mag(sample, &sign, &mag);
00081        return ~(sign | AST_LIN2MU_LOOKUP(mag));
00082 }
00083 #endif
00084 
00085 #define AST_MULAW(a) (__ast_mulaw[(a)])
00086 
00087 #endif /* _ASTERISK_ULAW_H */

Generated on Wed Oct 28 11:45:43 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6