Wed Oct 28 15:49:23 2009

Asterisk developer's documentation


ulaw.c File Reference

u-Law to Signed linear conversion More...

#include "asterisk.h"
#include "asterisk/ulaw.h"

Include dependency graph for ulaw.c:

Go to the source code of this file.

Defines

#define BIAS   0x84
#define CLIP   32635
#define ZEROTRAP

Functions

void ast_ulaw_init (void)
 Set up mu-law conversion table.
static unsigned char linear2ulaw (short sample)

Variables

unsigned char __ast_lin2mu [16384]
short __ast_mulaw [256]


Detailed Description

u-Law to Signed linear conversion

Definition in file ulaw.c.


Define Documentation

#define BIAS   0x84

define the add-in bias for 16 bit samples

Definition at line 32 of file ulaw.c.

Referenced by linear2ulaw().

#define CLIP   32635

Definition at line 33 of file ulaw.c.

Referenced by linear2ulaw().

#define ZEROTRAP

turn on the trap as per the MIL-STD

Definition at line 31 of file ulaw.c.


Function Documentation

void ast_ulaw_init ( void   ) 

Set up mu-law conversion table.

Init the ulaw conversion stuff

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

Definition at line 84 of file ulaw.c.

References linear2ulaw().

Referenced by main().

00085 {
00086    int i;
00087    for(i = 0;i < 256;i++) {
00088       short mu,e,f,y;
00089       static short etab[]={0,132,396,924,1980,4092,8316,16764};
00090 
00091       mu = 255-i;
00092       e = (mu & 0x70)/16;
00093       f = mu & 0x0f;
00094       y = f * (1 << (e + 3));
00095       y += etab[e];
00096       if (mu & 0x80) y = -y;
00097            __ast_mulaw[i] = y;
00098    }
00099    /* set up the reverse (mu-law) conversion table */
00100    for(i = -32768; i < 32768; i++) {
00101       __ast_lin2mu[((unsigned short)i) >> 2] = linear2ulaw(i);
00102    }
00103 
00104 }

static unsigned char linear2ulaw ( short  sample  )  [static]

Definition at line 39 of file ulaw.c.

References BIAS, and CLIP.

Referenced by ast_ulaw_init(), and main().

00040 {
00041    static int exp_lut[256] = {
00042       0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
00043       4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
00044       5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
00045       5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
00046       6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
00047       6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
00048       6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
00049       6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
00050       7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
00051       7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
00052       7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
00053       7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
00054       7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
00055       7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
00056       7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
00057       7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 };
00058    int sign, exponent, mantissa;
00059    unsigned char ulawbyte;
00060 
00061    /* Get the sample into sign-magnitude. */
00062    sign = (sample >> 8) & 0x80;          /* set aside the sign */
00063    if (sign != 0) 
00064       sample = -sample;              /* get magnitude */
00065    if (sample > CLIP)
00066       sample = CLIP;             /* clip the magnitude */
00067 
00068    /* Convert from 16 bit linear to ulaw. */
00069    sample = sample + BIAS;
00070    exponent = exp_lut[(sample >> 7) & 0xFF];
00071    mantissa = (sample >> (exponent + 3)) & 0x0F;
00072    ulawbyte = ~(sign | (exponent << 4) | mantissa);
00073 #ifdef ZEROTRAP
00074    if (ulawbyte == 0)
00075       ulawbyte = 0x02;   /* optional CCITT trap */
00076 #endif
00077 
00078    return ulawbyte;
00079 }


Variable Documentation

unsigned char __ast_lin2mu[16384]

converts signed linear to mulaw

Definition at line 35 of file ulaw.c.

short __ast_mulaw[256]

help

Definition at line 36 of file ulaw.c.


Generated on Wed Oct 28 15:49:23 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6