Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:00:59 2007

Asterisk developer's documentation :: Codename Pineapple


alaw.c File Reference


Detailed Description

u-Law to Signed linear conversion

Author:
Mark Spencer <markster@digium.com>

Definition in file alaw.c.

#include "asterisk.h"
#include "asterisk/alaw.h"

Include dependency graph for alaw.c:

Go to the source code of this file.

Defines

#define AMI_MASK   0x55

Functions

static short int alaw2linear (unsigned char alaw)
void ast_alaw_init (void)
static unsigned char linear2alaw (short int linear)

Variables

short __ast_alaw [256]
unsigned char __ast_lin2a [8192]


Define Documentation

#define AMI_MASK   0x55
 

Definition at line 32 of file alaw.c.

Referenced by alaw2linear(), and linear2alaw().


Function Documentation

static short int alaw2linear unsigned char  alaw  )  [inline, static]
 

Definition at line 64 of file alaw.c.

References AMI_MASK.

Referenced by ast_alaw_init().

00065 {
00066     int i;
00067     int seg;
00068 
00069     alaw ^= AMI_MASK;
00070     i = ((alaw & 0x0F) << 4);
00071     seg = (((int) alaw & 0x70) >> 4);
00072     if (seg)
00073        i = (i + 0x100) << (seg - 1);
00074     return (short int) ((alaw & 0x80)  ?  i  :  -i);
00075 }

void ast_alaw_init void   ) 
 

To init the ulaw to slinear conversion stuff, this needs to be run.

Definition at line 80 of file alaw.c.

References alaw2linear().

00081 {
00082    int i;
00083    /* 
00084     *  Set up mu-law conversion table
00085     */
00086    for (i = 0; i < 256; i++) {
00087            __ast_alaw[i] = alaw2linear(i);
00088    }
00089    /* set up the reverse (mu-law) conversion table */
00090    for (i = -32768; i < 32768; i++) {
00091       __ast_lin2a[((unsigned short)i) >> 3] = linear2alaw(i);
00092    }
00093 
00094 }

static unsigned char linear2alaw short int  linear  )  [inline, static]
 

Definition at line 34 of file alaw.c.

References AMI_MASK.

00035 {
00036     int mask;
00037     int seg;
00038     int pcm_val;
00039     static int seg_end[8] =
00040     {
00041          0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
00042     };
00043     
00044     pcm_val = linear;
00045     if (pcm_val >= 0) {
00046        /* Sign (7th) bit = 1 */
00047        mask = AMI_MASK | 0x80;
00048     } else {
00049        /* Sign bit = 0 */
00050        mask = AMI_MASK;
00051        pcm_val = -pcm_val;
00052     }
00053 
00054     /* Convert the scaled magnitude to segment number. */
00055     for (seg = 0;  seg < 8;  seg++) {
00056        if (pcm_val <= seg_end[seg])
00057           break;
00058     }
00059     /* Combine the sign, segment, and quantization bits. */
00060     return  ((seg << 4) | ((pcm_val >> ((seg)  ?  (seg + 3)  :  4)) & 0x0F)) ^ mask;
00061 }


Variable Documentation

short __ast_alaw[256]
 

help

Definition at line 78 of file alaw.c.

unsigned char __ast_lin2a[8192]
 

Definition at line 77 of file alaw.c.


Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen