Wed Oct 28 11:50:51 2009

Asterisk developer's documentation


alaw.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 A-Law to Signed linear conversion
00021  */
00022 
00023 #ifndef _ASTERISK_ALAW_H
00024 #define _ASTERISK_ALAW_H
00025 
00026 
00027 /*! \brief
00028  * To init the alaw to slinear conversion stuff, this needs to be run.
00029  */
00030 void ast_alaw_init(void);
00031 
00032 #define AST_ALAW_BIT_LOSS  4
00033 #define AST_ALAW_STEP      (1 << AST_ALAW_BIT_LOSS)
00034 #define AST_ALAW_TAB_SIZE  (32768 / AST_ALAW_STEP + 1)
00035 #define AST_ALAW_SIGN_BIT  0x80
00036 #define AST_ALAW_AMI_MASK  0x55
00037 
00038 
00039 /*! \brief converts signed linear to alaw */
00040 #ifndef G711_NEW_ALGORITHM
00041 extern unsigned char __ast_lin2a[8192];
00042 #else
00043 extern unsigned char __ast_lin2a[AST_ALAW_TAB_SIZE];
00044 #endif
00045 
00046 /*! help */
00047 extern short __ast_alaw[256];
00048 
00049 #ifndef G711_NEW_ALGORITHM
00050 #define AST_LIN2A(a) (__ast_lin2a[((unsigned short)(a)) >> 3])
00051 #else
00052 #define AST_LIN2A_LOOKUP(mag)                   \
00053    __ast_lin2a[(mag) >> AST_ALAW_BIT_LOSS]
00054 
00055 /*! \brief Convert signed linear sample to sign-magnitude pair for a-Law */
00056 static inline void ast_alaw_get_sign_mag(short sample, unsigned *sign, unsigned *mag)
00057 {
00058    /* It may look illogical to retrive the sign this way in both cases,
00059     * but this helps gcc eliminate the branch below and produces
00060     * faster code */
00061    *sign = ((unsigned short)sample >> 8) & AST_ALAW_SIGN_BIT;
00062 #if defined(G711_REDUCED_BRANCHING)
00063    {
00064       unsigned dual_mag = (-sample << 16) | (unsigned short)sample;
00065       *mag = (dual_mag >> (*sign >> 3)) & 0xffffU;
00066    }
00067 #else
00068    if (sample < 0)
00069       *mag = -sample;
00070    else
00071       *mag = sample;
00072 #endif /* G711_REDUCED_BRANCHING */
00073    *sign ^= AST_ALAW_SIGN_BIT;
00074 }
00075 
00076 static inline unsigned char AST_LIN2A(short sample)
00077 {
00078    unsigned mag, sign;
00079    ast_alaw_get_sign_mag(sample, &sign, &mag);
00080    return (sign | AST_LIN2A_LOOKUP(mag)) ^ AST_ALAW_AMI_MASK;
00081 }
00082 #endif
00083 
00084 #define AST_ALAW(a) (__ast_alaw[(int)(a)])
00085 
00086 #endif /* _ASTERISK_ALAW_H */

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