DSPRelated.com
Forums

A law c code

Started by Benoy Antony April 10, 2003
Hi all,
I was looking for a c implementation on C5409 for A-law compression
(both encoder and decoder).

It would be really helpful if anybody could provide me the same or links
from where i could get the c code...

Thanks and Regards
kp




Hi,

If your DSP has got a bootloader in the on-chip ROM, then there a
built-in 256-word A-law expansion table that you can use. This table
is located at address 0xFD00. Make sure that you map the on-chip ROM
into data space (DROM=1).

Remember that A-law can only handle 12-bit linear. You need to
right/left shift the linear sample in order to work with 16-bit or
other width linear.

The C code for A-law expansion (decoding) would look like this: // built-in expansion table in on-chip ROM
int *alaw_exp_table = (int*)0xFD00;
int *ulaw_exp_table = (int*)0xFC00;

// decode a-law into 12-bit linear
int alaw_expand(int sample)
{
// make sure sample is between 0 and 255
return alaw_exp_table[sample & 0xFF];
}
For A-law compression (encoding), using lookup table would be
inefficient. You can use the following C code to compress 12-bit
linear into 8-bit A-law. #define MASK 0x0080
#define BIAS 0x01F0
#define INVT 0x00D5;
#define ABS(x) (((x) > 0) ? (x) : -(x))

// encode 12-bit linear into a-law
int alaw_compress(int sample)
{
int result;
int exp;

result = sample >> 6;
exp = (result) ? _lnorm(result) : 0x1F;
result &= MASK;
result += BIAS;
result -= (exp * 16);
result += (ABS(sample) >> (32 - exp));
return result^INVT;
} The function _lnorm() is an intrinsic function equivalent to EXP
assembly instruction.

Hope it helps.
--- In , Benoy Antony <rec_kp@y...> wrote:
> Hi all,
> I was looking for a c implementation on C5409 for A-law
compression
> (both encoder and decoder).
>
> It would be really helpful if anybody could provide me the same or
links
> from where i could get the c code...
>
> Thanks and Regards
> kp