Technical discussions related to Speech Coding (all itu and other vocoders, ACELP, CELP, AMR, etc)
|
Hello, Can anyone provide me code for converting A-law to linear & vice-versa. Kindly send the same at the foll. address: Thanking in advance Yours faithfully, Sachin Athalye |
|
|
|
Please obtain ITU G.191 and you will have an official version of codes. Binshi Cao. > ---------- > From: [SMTP:] > Reply To: > Sent: Wednesday, May 10, 2000 6:40 AM > To: > Subject: [speechcoding] A-law to linear coding & vice-versa > > Hello, > Can anyone provide me code for converting A-law to linear & > vice-versa. Kindly send the same at the foll. address: > > Thanking in advance > Yours faithfully, > > Sachin Athalye > > ------------------------------------------------------------------------ > Remember four years of good friends, bad clothes, explosive chemistry > experiments. > http://click.egroups.com/1/4051/0/_/8885/_/957960092/ > ------------------------------------------------------------------------ > > To Join: > > To Post: > > To Leave: > > Archives: http://www.egroups.com/group/speechcoding > > Other DSP-Related Groups: http://www.dsprelated.com |
|
Hi Pls refer to Texas Instrument's Application Note SPRA163 for algorithm and code for A & mu law companding. The App note is downloadable from www.ti.com Regards, satheesh.s -----Original Message----- From: [mailto:] Sent: Wednesday, May 10, 2000 4:10 PM To: Subject: [speechcoding] A-law to linear coding & vice-versa Hello, Can anyone provide me code for converting A-law to linear & vice-versa. Kindly send the same at the foll. address: Thanking in advance Yours faithfully, Sachin Athalye ------------------------------------------------------------------------ Remember four years of good friends, bad clothes, explosive chemistry experiments. http://click.egroups.com/1/4051/0/_/8885/_/957960092/ ------------------------------------------------------------------------ To Join: To Post: To Leave: Archives: http://www.egroups.com/group/speechcoding Other DSP-Related Groups: http://www.dsprelated.com |
|
Hi,
In which language u need the code? because most of the
processors have this conversion program as a part of their library. it's just a
lookup table conversion.
bye
|
|
Dear Friends, Thank you for your prompt response. In the meantime, I have come across a free source code from Sun Microsystems. But I have trouble understanding it. I'm providing the same below : #define SIGN_BIT (0x80) /* Sign bit for a A-law byte.*/ #define QUANT_MASK (0xf) /* Quantization field mask. */ #define NSEGS (8) /* Number of A-law segments. */ #define SEG_SHIFT (4) /* Left shift for segment number. */ #define SEG_MASK (0x70) /* Segment field mask. */ static short seg_end[8] = {0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF}; static int search( int val,short *table,int size) { int i; for (i = 0; i < size; i++) { if (val <= *table++) return (i); } return (size); } /* * linear2alaw() - Convert a 16-bit linear PCM value to 8-bit A-law * * linear2alaw() accepts an 16-bit integer and encodes it as A-law data. * * Linear Input Code Compressed Code * ------------------------ --------------- * 0000000wxyza 000wxyz * 0000001wxyza 001wxyz * 000001wxyzab 010wxyz * 00001wxyzabc 011wxyz * 0001wxyzabcd 100wxyz * 001wxyzabcde 101wxyz * 01wxyzabcdef 110wxyz * 1wxyzabcdefg 111wxyz * */ unsigned char linear2alaw(int pcm_val)/* 2's complement 16-bit range) */ { int mask; int seg; unsigned char aval; if (pcm_val >= 0) { mask = 0xD5; /* sign (7th) bit = 1 */ } else { mask = 0x55; /* sign bit = 0 */ pcm_val = -pcm_val - 8; } /* Convert the scaled magnitude to segment number. */ seg = search(pcm_val, seg_end, 8); /* Combine the sign, segment, and quantization bits. */ if (seg >= 8) /* out of range, return maximum value. */ return (0x7F ^ mask); else { aval = seg << SEG_SHIFT; if (seg < 2) aval |= (pcm_val >> 4) & QUANT_MASK; else aval |= (pcm_val >> (seg + 3)) & QUANT_MASK; return (aval ^ mask); } } I have the foll. doubts: 1> In the func linear2alaw(), when pcm_val is found to be -ve, why is the operation , pcm_val=-pcm_val-8, performed ? 2> In the func search(), an int is compared with a short. Will this make it a machine [16-bit , 32-bit]dependent or compiler dependent operation ? Kindly solve my doubts. Thanking you Yours faithfully, Sachin Athalye email: |
|
|
|
Hi, factor '8' is actually '1'. Actual i/p to linear-A law is 13 bit..but the code is for 16 bit linear ( obtained by shifting left the 13 bit value by 3...similarly '1' becomes 8. regards Suresh shetty --- In , sachin.athalye@p... wrote: > Dear Friends, > Thank you for your prompt response. In the meantime, I > have come across a free source code from Sun Microsystems. But I have > trouble understanding it. I'm providing the same below : > > #define SIGN_BIT (0x80) /* Sign bit for a A-law > byte.*/ > #define QUANT_MASK (0xf) /* Quantization field mask. */ > #define NSEGS (8) /* Number of A-law segments. > */ > #define SEG_SHIFT (4) /* Left shift for segment > number. */ > #define SEG_MASK (0x70) /* Segment field mask. */ > > static short seg_end[8] = {0xFF, 0x1FF, 0x3FF, 0x7FF, > 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF}; > > static int search( int val,short *table,int size) > { > int i; > for (i = 0; i < size; i++) { > if (val <= *table++) > return (i); > } > return (size); > } > > /* > * linear2alaw() - Convert a 16-bit linear PCM value to 8-bit A-law > * > * linear2alaw() accepts an 16-bit integer and encodes it as A-law > data. > * > * Linear Input Code Compressed Code > * ------------------------ --------------- > * 0000000wxyza 000wxyz > * 0000001wxyza 001wxyz > * 000001wxyzab 010wxyz > * 00001wxyzabc 011wxyz > * 0001wxyzabcd 100wxyz > * 001wxyzabcde 101wxyz > * 01wxyzabcdef 110wxyz > * 1wxyzabcdefg 111wxyz > * > */ > unsigned char linear2alaw(int pcm_val)/* 2's complement 16-bit > range) */ > { > int mask; > int seg; > unsigned char aval; > > if (pcm_val >= 0) { > mask = 0xD5; /* sign (7th) bit = 1 */ > } else { > mask = 0x55; /* sign bit = 0 */ > pcm_val = -pcm_val - 8; > } > > /* Convert the scaled magnitude to segment number. */ > seg = search(pcm_val, seg_end, 8); > > /* Combine the sign, segment, and quantization bits. */ > > if (seg >= 8) /* out of range, return maximum value. > */ > return (0x7F ^ mask); > else { > aval = seg << SEG_SHIFT; > if (seg < 2) > aval |= (pcm_val >> 4) & QUANT_MASK; > else > aval |= (pcm_val >> (seg + 3)) & QUANT_MASK; > return (aval ^ mask); > } > } > > I have the foll. doubts: > > 1> In the func linear2alaw(), when pcm_val is found to be -ve, why is > the operation , pcm_val=-pcm_val-8, performed ? > > 2> In the func search(), an int is compared with a short. Will this > make it a machine [16-bit , 32-bit]dependent or compiler dependent > operation ? > Kindly solve my doubts. > Thanking you > > Yours faithfully, > Sachin Athalye > email:sachin.athalye@p... |