# [music-dsp] A-Law Mu-Law Compression on adsp2186m

ayyams ayyams japintokio at yahoo.com
Fri Jan 16 22:23:01 EST 2004

```hi
thank u for ur response.....

i here with sending my code for compression and expension...i am not trying look up table method.its normal linear method.
but i couldn't fine where i am doing fault....Looking forward for your favorable reply

ALaw_Compression:
/*
This routine determines the 8-bit (right-justified)
a-Law value from the 16-bit (right-justified) linear
input.
Calling Parameters
AR = 16-bit (right-justified) linear input
Return Values
AR = 8-bit log (a-Law) output
Altered Registers
AR, AF, AX0, AY0,
SR, SE
Computation Time
21 Cycles
*/

AR=ABS AR;   // {Take absolute value}
AY0=1;
IF NEG AR=AR+AY0;
SR=ASHIFT AR BY -1 (HI);
AR=PASS SR1;
AY0=4095;   // {Maximum PCM value}
AF=AR-AY0;   // {Cap input}
IF GT AR=PASS AY0; // {If in excess}
AY0=31;    //  {Check ofor zero segment}
AF=AR-AY0;
IF GT JUMP upper_seg;
SR=LSHIFT AR BY -1 (LO);
AR=0x4000;
IF NEG AR=PASS 0;
SR=SR OR LSHIFT AR BY -7 (LO);
AY0=0x55;
AR=SR0 XOR AY0;
RTS;
upper_seg:  SE=EXP AR (HI);        //{Find exponent adjustmet}
AX0=SE, SR=NORM AR (HI);  //{Normalize input}
AY0=0x4000;
AR=SR1 XOR AY0;     //{Remove first significant bit}
SR=LSHIFT AR BY -10 (LO);  //{Shift position bits}
AR=PASS AY0;
IF NEG AR=PASS 0;    //{Create sign bit}
SR=SR OR LSHIFT AR BY -7 (LO);  // {Position sign bit}
AY0=10;
AR=AX0+AY0;      //{Compute segment}
IF LT AR=PASS 0;
SR=SR OR LSHIFT AR BY 4 (LO); //{Position segment bits}
AY0=0x55;
AR=SR0 XOR AY0;     //{Invert bits}
RTS;

ALaw_Expansion:
/*
This routine determines the 16-bit (right-justified) linear
value from an 8-bit log (a-law) input

Calling Parameters
AR = 8-bit log (a-law) value
Return Values
AR = 16-bit linear output
Altered Registers
AR, AF, AX0, AY0,
SR, SE
Cycle Count
16 Cycles
*/

AY0=0x0055;
AR=AR XOR AY0;
SR1=0x0008;      //{Always set sign bit}
SR0=0x0800;      //{Set LSB of interval}
SR=SR OR LSHIFT AR BY 12 (LO); //{Isolate segment, interval}
AY0=32;
AX0=AR, AF=PASS AY0;
AY0=9;       //{Segment bias}
AR=SR1-AY0;      //{Determine shift value}
IF LT AF=PASS 0;    //{No extra MSB bit}
IF EQ AR=PASS 0;    //{No less then zero bits}
SR=LSHIFT SR0 BY -11 (LO);  //{Isolate Interval}
SE=AR, AR=SR0 OR AF;   //{Add bit if necessary}
SR=LSHIFT AR (LO);    //{Position output}
AY0=0xFF80;
SR=ASHIFT SR0 BY 1 (HI);
AR=SR1, AF=AX0+AY0;    //{Is sign bit set?}
IF LT AR=-SR1;     //{Yes, so invert word}
RTS;

Erik de Castro Lopo <erikd-music-dsp at mega-nerd.com> wrote:
On Fri, 16 Jan 2004 00:35:09 -0800 (PST)
ayyams ayyams wrote:

>
> hi all,
>
> i have to change 16-bit data to 8-bit data.For that i am
> trying to apply either A-Law or Mu-Law compression algorithm.i got
> a sample code from ADI but it not working fine.

A-law and u-law encoding are relatively trivial and can be implemented
using lookup tables.

Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo nospam at mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
Linux: the only OS that makes you feel guilty when you reboot
-- Kenneth Crudup in comp.os.linux.misc
dupswapdrop -- the music-dsp mailing list and website:
subscription info, FAQ, source code archive, list archive, book reviews, dsp links
http://shoko.calarts.edu/musicdsp
http://ceait.calarts.edu/mailman/listinfo/music-dsp

---------------------------------
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://music.columbia.edu/pipermail/music-dsp/attachments/20040116/3dca2c7f/attachment-0001.html
```