对视频会议系统比较了解的高手看过来(500分)(300分)

  • 主题发起人 主题发起人 liukeen
  • 开始时间 开始时间
L

liukeen

Unregistered / Unconfirmed
GUEST, unregistred user!
能否提供H261,H263,G711,G723,g729详细规范,
最好能提供较底层的一些编码、解码模块,
本人除了感激外,令奉上500大洋
 
只能300呀,令外200,随后奉上
 
请看: <a href=http://avsuper.126.com><font size=3 color=red>http://avsuper.126.com</font></a>
图像压缩算法.
 
caowei,谢谢你,不知道
你有没有H261.dll中的函数声明
 
H.261
系列的程序大多都是C的吧
 
h263.dll,可以使用DELPHI,VC调用.
没有到主页上面看吗?
http://avsuper.126.com
 
去了
谢谢
caowei
你的QQ号码是多少!!??
 
OICQ: 58085501不过很少用.
EMAIL联系!
 
那个主页是谁做的
你的吗!?
caowei?
 
有规范么?
 
基本上都要靠硬件来实现,而且目前大多数的视频会议系统都是老外的,好像
美国和以色列的比较出名些吧。国产的华为有,但据说很滥。
软件实现起来有很多问题,一是带宽的限制,二是很多同步的处理,会议的点数越多
越要及其完善的压缩,传输,解压,同步算法。
难啊。
 
声音标准压缩、解压缩G711_G721_G723代码:

/*
* decode.c 文件内容:
*
* CCITT ADPCM decoder
*
* Usage : decode [-3|4|5] [-a|u|l] < infile > outfile
*/
#include <stdio.h>
#include "g72x.h"


/*
* Unpack input codes and pass them back as bytes.
* Returns 1 if there is residual input, returns -1 if eof, else
returns 0.
*/
int
unpack_input(
unsigned char *code,
int bits)
{
static unsigned int in_buffer = 0;
static int in_bits = 0;
unsigned char in_byte;

if (in_bits < bits) {
if (fread(&amp;in_byte, sizeof (char), 1, stdin) != 1) {
*code = 0;
return (-1);
}
in_buffer |= (in_byte << in_bits);
in_bits += 8;
}
*code = in_buffer &amp;
((1 << bits) - 1);
in_buffer >>= bits;
in_bits -= bits;
return (in_bits > 0);
}


main(
int argc,
char **argv)
{
short sample;
unsigned char code;
int n;
struct g72x_state state;
int out_coding;
int out_size;
int (*dec_routine)();
int dec_bits;

g72x_init_state(&amp;state);
out_coding = AUDIO_ENCODING_ULAW;
out_size = sizeof (char);
dec_routine = g721_decoder;
dec_bits = 4;

/* Process encoding argument, if any */
while ((argc > 1) &amp;&amp;
(argv[1][0] == '-')) {
switch (argv[1][1]) {
case '3':
dec_routine = g723_24_decoder;
dec_bits = 3;
break;
case '4':
dec_routine = g721_decoder;
dec_bits = 4;
break;
case '5':
dec_routine = g723_40_decoder;
dec_bits = 5;
break;
case 'u':
out_coding = AUDIO_ENCODING_ULAW;
out_size = sizeof (char);
break;
case 'a':
out_coding = AUDIO_ENCODING_ALAW;
out_size = sizeof (char);
break;
case 'l':
out_coding = AUDIO_ENCODING_LINEAR;
out_size = sizeof (short);
break;
default:
fprintf(stderr, "CCITT ADPCM Decoder -- usage:/n");
fprintf(stderr, "/tdecode [-3|4|5] [-a|u|l] < infile > outfile/n");
fprintf(stderr, "where:/n");
fprintf(stderr, "/t-3/tProcess G.723 24kbps (3-bit) input data/n");
fprintf(stderr, "/t-4/tProcess G.721 32kbps (4-bit) input data [default]/n");
fprintf(stderr, "/t-5/tProcess G.723 40kbps (5-bit) input data/n");
fprintf(stderr, "/t-a/tGenerate 8-bit A-law data/n");
fprintf(stderr, "/t-u/tGenerate 8-bit u-law data [default]/n");
fprintf(stderr, "/t-l/tGenerate 16-bit linear PCM data/n");
exit(1);
}
argc--;
argv++;
}

/* Read and unpack input codes and process them */
while (unpack_input(&amp;code, dec_bits) >= 0) {
sample = (*dec_routine)(code, out_coding, &amp;state);
if (out_size == 2) {
fwrite(&amp;sample, out_size, 1, stdout);
} else
{
code = (unsigned char)sample;
fwrite(&amp;code, out_size, 1, stdout);
}
}
fclose(stdout);
}
--------------------------------------------------------------------------------

/*
* encode.c文件内容
*
* CCITT ADPCM encoder
*
* Usage : encode [-3|4|5] [-a|u|l] < infile > outfile
*/
#include <stdio.h>
#include "g72x.h"


/*
* Pack output codes into bytes and write them to stdout.
* Returns 1 if there is residual output, else
returns 0.
*/
int
pack_output(
unsigned code,
int bits)
{
static unsigned int out_buffer = 0;
static int out_bits = 0;
unsigned char out_byte;

out_buffer |= (code << out_bits);
out_bits += bits;
if (out_bits >= 8) {
out_byte = out_buffer &amp;
0xff;
out_bits -= 8;
out_buffer >>= 8;
fwrite(&amp;out_byte, sizeof (char), 1, stdout);
}
return (out_bits > 0);
}


main(
int argc,
char **argv)
{
struct g72x_state state;
unsigned char sample_char;
short sample_short;
unsigned char code;
int resid;
int in_coding;
int in_size;
unsigned *in_buf;
int (*enc_routine)();
int enc_bits;

g72x_init_state(&amp;state);

/* Set defaults to u-law input, G.721 output */
in_coding = AUDIO_ENCODING_ULAW;
in_size = sizeof (char);
in_buf = (unsigned *)&amp;sample_char;
enc_routine = g721_encoder;
enc_bits = 4;

/* Process encoding argument, if any */
while ((argc > 1) &amp;&amp;
(argv[1][0] == '-')) {
switch (argv[1][1]) {
case '3':
enc_routine = g723_24_encoder;
enc_bits = 3;
break;
case '4':
enc_routine = g721_encoder;
enc_bits = 4;
break;
case '5':
enc_routine = g723_40_encoder;
enc_bits = 5;
break;
case 'u':
in_coding = AUDIO_ENCODING_ULAW;
in_size = sizeof (char);
in_buf = (unsigned *)&amp;sample_char;
break;
case 'a':
in_coding = AUDIO_ENCODING_ALAW;
in_size = sizeof (char);
in_buf = (unsigned *)&amp;sample_char;
break;
case 'l':
in_coding = AUDIO_ENCODING_LINEAR;
in_size = sizeof (short);
in_buf = (unsigned *)&amp;sample_short;
break;
default:
fprintf(stderr, "CCITT ADPCM Encoder -- usage:/n");
fprintf(stderr, "/tencode [-3|4|5] [-a|u|l] < infile > outfile/n");
fprintf(stderr, "where:/n");
fprintf(stderr, "/t-3/tGenerate G.723 24kbps (3-bit) data/n");
fprintf(stderr, "/t-4/tGenerate G.721 32kbps (4-bit) data [default]/n");
fprintf(stderr, "/t-5/tGenerate G.723 40kbps (5-bit) data/n");
fprintf(stderr, "/t-a/tProcess 8-bit A-law input data/n");
fprintf(stderr, "/t-u/tProcess 8-bit u-law input data [default]/n");
fprintf(stderr, "/t-l/tProcess 16-bit linear PCM input data/n");
exit(1);
}
argc--;
argv++;
}

/* Read input file and process */
while (fread(in_buf, in_size, 1, stdin) == 1) {
code = (*enc_routine)(in_size == 2 ? sample_short : sample_char,
in_coding, &amp;state);
resid = pack_output(code, enc_bits);
}

/* Write zero codes until all residual codes are written out */
while (resid) {
resid = pack_output(0, enc_bits);
}
fclose(stdout);
}
---------------------------------------------------------------------------------------
/*g711.c文件内容:
/*
* This source code is a product of Sun Microsystems, Inc. and is provided
* for unrestricted use. Users may copy or modify this source code without
* charge.
*
* SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
* THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun source code is provided with no support and without any obligation on
* the part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/

/*
* g711.c
*
* u-law, A-law and linear PCM conversions.
*/
#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};

/* copy from CCITT G.711 specifications */
unsigned char _u2a[128] = { /* u- to A-law conversions */
1, 1, 2, 2, 3, 3, 4, 4,
5, 5, 6, 6, 7, 7, 8, 8,
9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24,
25, 27, 29, 31, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44,
46, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62,
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120,
121, 122, 123, 124, 125, 126, 127, 128};

unsigned char _a2u[128] = { /* A- to u-law conversions */
1, 3, 5, 7, 9, 11, 13, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
32, 32, 33, 33, 34, 34, 35, 35,
36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 48, 49, 49,
50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 64,
65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127};

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
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
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) &amp;
QUANT_MASK;
else

aval |= (pcm_val >> (seg + 3)) &amp;
QUANT_MASK;
return (aval ^ mask);
}
}

/*
* alaw2linear() - Convert an A-law value to 16-bit linear PCM
*
*/
int
alaw2linear(
unsigned char a_val)
{
int t;
int seg;

a_val ^= 0x55;

t = (a_val &amp;
QUANT_MASK) << 4;
seg = ((unsigned)a_val &amp;
SEG_MASK) >> SEG_SHIFT;
switch (seg) {
case 0:
t += 8;
break;
case 1:
t += 0x108;
break;
default:
t += 0x108;
t <<= seg - 1;
}
return ((a_val &amp;
SIGN_BIT) ? t : -t);
}

#define BIAS (0x84) /* Bias for linear code. */

/*
* linear2ulaw() - Convert a linear PCM value to u-law
*
* In order to simplify the encoding process, the original linear magnitude
* is biased by adding 33 which shifts the encoding range from (0 - 8158) to
* (33 - 8191). The result can be seen in the following encoding table:
*
* Biased Linear Input Code Compressed Code
* ------------------------ ---------------
* 00000001wxyza 000wxyz
* 0000001wxyzab 001wxyz
* 000001wxyzabc 010wxyz
* 00001wxyzabcd 011wxyz
* 0001wxyzabcde 100wxyz
* 001wxyzabcdef 101wxyz
* 01wxyzabcdefg 110wxyz
* 1wxyzabcdefgh 111wxyz
*
* Each biased linear code has a leading 1 which identifies the segment
* number. The value of the segment number is equal to 7 minus the number
* of leading 0's. The quantization interval is directly available as the
* four bits wxyz. * The trailing bits (a - h) are ignored.
*
* Ordinarily the complement of the resulting code word is used for
* transmission, and so the code word is complemented before it is returned.
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
unsigned char
linear2ulaw(
int pcm_val) /* 2's complement (16-bit range) */
{
int mask;
int seg;
unsigned char uval;

/* Get the sign and the magnitude of the value. */
if (pcm_val < 0) {
pcm_val = BIAS - pcm_val;
mask = 0x7F;
} else
{
pcm_val += BIAS;
mask = 0xFF;
}

/* Convert the scaled magnitude to segment number. */
seg = search(pcm_val, seg_end, 8);

/*
* Combine the sign, segment, quantization bits;
* and complement the code word.
*/
if (seg >= 8) /* out of range, return maximum value. */
return (0x7F ^ mask);
else
{
uval = (seg << 4) | ((pcm_val >> (seg + 3)) &amp;
0xF);
return (uval ^ mask);
}

}

/*
* ulaw2linear() - Convert a u-law value to 16-bit linear PCM
*
* First, a biased linear code is derived from the code word. An unbiased
* output can then
be obtained by subtracting 33 from the biased code.
*
* Note that this function expects to be passed the complement of the
* original code word. This is in keeping with ISDN conventions.
*/
int
ulaw2linear(
unsigned char u_val)
{
int t;

/* Complement to obtain normal u-law value. */
u_val = ~u_val;

/*
* Extract and bias the quantization bits. then

* shift up by the segment number and subtract out the bias.
*/
t = ((u_val &amp;
QUANT_MASK) << 3) + BIAS;
t <<= ((unsigned)u_val &amp;
SEG_MASK) >> SEG_SHIFT;

return ((u_val &amp;
SIGN_BIT) ? (BIAS - t) : (t - BIAS));
}

/* A-law to u-law conversion */
unsigned char
alaw2ulaw(
unsigned char aval)
{
aval &amp;= 0xff;
return ((aval &amp;
0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) :
(0x7F ^ _a2u[aval ^ 0x55]));
}

/* u-law to A-law conversion */
unsigned char
ulaw2alaw(
unsigned char uval)
{
uval &amp;= 0xff;
return ((uval &amp;
0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) :
(0x55 ^ (_u2a[0x7F ^ uval] - 1)));
}
--------------------------------------------------------------------------------

/* g721.c文件内容:

/*
* This source code is a product of Sun Microsystems, Inc. and is provided
* for unrestricted use. Users may copy or modify this source code without
* charge.
*
* SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
* THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun source code is provided with no support and without any obligation on
* the part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/

/*
* g711.c
*
* u-law, A-law and linear PCM conversions.
*/
#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};

/* copy from CCITT G.711 specifications */
unsigned char _u2a[128] = { /* u- to A-law conversions */
1, 1, 2, 2, 3, 3, 4, 4,
5, 5, 6, 6, 7, 7, 8, 8,
9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24,
25, 27, 29, 31, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44,
46, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62,
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120,
121, 122, 123, 124, 125, 126, 127, 128};

unsigned char _a2u[128] = { /* A- to u-law conversions */
1, 3, 5, 7, 9, 11, 13, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
32, 32, 33, 33, 34, 34, 35, 35,
36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 48, 49, 49,
50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 64,
65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127};

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
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
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) &amp;
QUANT_MASK;
else

aval |= (pcm_val >> (seg + 3)) &amp;
QUANT_MASK;
return (aval ^ mask);
}
}

/*
* alaw2linear() - Convert an A-law value to 16-bit linear PCM
*
*/
int
alaw2linear(
unsigned char a_val)
{
int t;
int seg;

a_val ^= 0x55;

t = (a_val &amp;
QUANT_MASK) << 4;
seg = ((unsigned)a_val &amp;
SEG_MASK) >> SEG_SHIFT;
switch (seg) {
case 0:
t += 8;
break;
case 1:
t += 0x108;
break;
default:
t += 0x108;
t <<= seg - 1;
}
return ((a_val &amp;
SIGN_BIT) ? t : -t);
}

#define BIAS (0x84) /* Bias for linear code. */

/*
* linear2ulaw() - Convert a linear PCM value to u-law
*
* In order to simplify the encoding process, the original linear magnitude
* is biased by adding 33 which shifts the encoding range from (0 - 8158) to
* (33 - 8191). The result can be seen in the following encoding table:
*
* Biased Linear Input Code Compressed Code
* ------------------------ ---------------
* 00000001wxyza 000wxyz
* 0000001wxyzab 001wxyz
* 000001wxyzabc 010wxyz
* 00001wxyzabcd 011wxyz
* 0001wxyzabcde 100wxyz
* 001wxyzabcdef 101wxyz
* 01wxyzabcdefg 110wxyz
* 1wxyzabcdefgh 111wxyz
*
* Each biased linear code has a leading 1 which identifies the segment
* number. The value of the segment number is equal to 7 minus the number
* of leading 0's. The quantization interval is directly available as the
* four bits wxyz. * The trailing bits (a - h) are ignored.
*
* Ordinarily the complement of the resulting code word is used for
* transmission, and so the code word is complemented before it is returned.
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
unsigned char
linear2ulaw(
int pcm_val) /* 2's complement (16-bit range) */
{
int mask;
int seg;
unsigned char uval;

/* Get the sign and the magnitude of the value. */
if (pcm_val < 0) {
pcm_val = BIAS - pcm_val;
mask = 0x7F;
} else
{
pcm_val += BIAS;
mask = 0xFF;
}

/* Convert the scaled magnitude to segment number. */
seg = search(pcm_val, seg_end, 8);

/*
* Combine the sign, segment, quantization bits;
* and complement the code word.
*/
if (seg >= 8) /* out of range, return maximum value. */
return (0x7F ^ mask);
else
{
uval = (seg << 4) | ((pcm_val >> (seg + 3)) &amp;
0xF);
return (uval ^ mask);
}

}

/*
* ulaw2linear() - Convert a u-law value to 16-bit linear PCM
*
* First, a biased linear code is derived from the code word. An unbiased
* output can then
be obtained by subtracting 33 from the biased code.
*
* Note that this function expects to be passed the complement of the
* original code word. This is in keeping with ISDN conventions.
*/
int
ulaw2linear(
unsigned char u_val)
{
int t;

/* Complement to obtain normal u-law value. */
u_val = ~u_val;

/*
* Extract and bias the quantization bits. then

* shift up by the segment number and subtract out the bias.
*/
t = ((u_val &amp;
QUANT_MASK) << 3) + BIAS;
t <<= ((unsigned)u_val &amp;
SEG_MASK) >> SEG_SHIFT;

return ((u_val &amp;
SIGN_BIT) ? (BIAS - t) : (t - BIAS));
}

/* A-law to u-law conversion */
unsigned char
alaw2ulaw(
unsigned char aval)
{
aval &amp;= 0xff;
return ((aval &amp;
0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) :
(0x7F ^ _a2u[aval ^ 0x55]));
}

/* u-law to A-law conversion */
unsigned char
ulaw2alaw(
unsigned char uval)
{
uval &amp;= 0xff;
return ((uval &amp;
0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) :
(0x55 ^ (_u2a[0x7F ^ uval] - 1)));
}
-------------------------------------------------------------------------------------

/* g723_24.c文件内容:

/*
* This source code is a product of Sun Microsystems, Inc. and is provided
* for unrestricted use. Users may copy or modify this source code without
* charge.
*
* SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
* THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun source code is provided with no support and without any obligation on
* the part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/

/*
* g711.c
*
* u-law, A-law and linear PCM conversions.
*/
#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};

/* copy from CCITT G.711 specifications */
unsigned char _u2a[128] = { /* u- to A-law conversions */
1, 1, 2, 2, 3, 3, 4, 4,
5, 5, 6, 6, 7, 7, 8, 8,
9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24,
25, 27, 29, 31, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44,
46, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62,
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120,
121, 122, 123, 124, 125, 126, 127, 128};

unsigned char _a2u[128] = { /* A- to u-law conversions */
1, 3, 5, 7, 9, 11, 13, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
32, 32, 33, 33, 34, 34, 35, 35,
36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 48, 49, 49,
50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 64,
65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127};

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
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
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) &amp;
QUANT_MASK;
else

aval |= (pcm_val >> (seg + 3)) &amp;
QUANT_MASK;
return (aval ^ mask);
}
}

/*
* alaw2linear() - Convert an A-law value to 16-bit linear PCM
*
*/
int
alaw2linear(
unsigned char a_val)
{
int t;
int seg;

a_val ^= 0x55;

t = (a_val &amp;
QUANT_MASK) << 4;
seg = ((unsigned)a_val &amp;
SEG_MASK) >> SEG_SHIFT;
switch (seg) {
case 0:
t += 8;
break;
case 1:
t += 0x108;
break;
default:
t += 0x108;
t <<= seg - 1;
}
return ((a_val &amp;
SIGN_BIT) ? t : -t);
}

#define BIAS (0x84) /* Bias for linear code. */

/*
* linear2ulaw() - Convert a linear PCM value to u-law
*
* In order to simplify the encoding process, the original linear magnitude
* is biased by adding 33 which shifts the encoding range from (0 - 8158) to
* (33 - 8191). The result can be seen in the following encoding table:
*
* Biased Linear Input Code Compressed Code
* ------------------------ ---------------
* 00000001wxyza 000wxyz
* 0000001wxyzab 001wxyz
* 000001wxyzabc 010wxyz
* 00001wxyzabcd 011wxyz
* 0001wxyzabcde 100wxyz
* 001wxyzabcdef 101wxyz
* 01wxyzabcdefg 110wxyz
* 1wxyzabcdefgh 111wxyz
*
* Each biased linear code has a leading 1 which identifies the segment
* number. The value of the segment number is equal to 7 minus the number
* of leading 0's. The quantization interval is directly available as the
* four bits wxyz. * The trailing bits (a - h) are ignored.
*
* Ordinarily the complement of the resulting code word is used for
* transmission, and so the code word is complemented before it is returned.
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
unsigned char
linear2ulaw(
int pcm_val) /* 2's complement (16-bit range) */
{
int mask;
int seg;
unsigned char uval;

/* Get the sign and the magnitude of the value. */
if (pcm_val < 0) {
pcm_val = BIAS - pcm_val;
mask = 0x7F;
} else
{
pcm_val += BIAS;
mask = 0xFF;
}

/* Convert the scaled magnitude to segment number. */
seg = search(pcm_val, seg_end, 8);

/*
* Combine the sign, segment, quantization bits;
* and complement the code word.
*/
if (seg >= 8) /* out of range, return maximum value. */
return (0x7F ^ mask);
else
{
uval = (seg << 4) | ((pcm_val >> (seg + 3)) &amp;
0xF);
return (uval ^ mask);
}

}

/*
* ulaw2linear() - Convert a u-law value to 16-bit linear PCM
*
* First, a biased linear code is derived from the code word. An unbiased
* output can then
be obtained by subtracting 33 from the biased code.
*
* Note that this function expects to be passed the complement of the
* original code word. This is in keeping with ISDN conventions.
*/
int
ulaw2linear(
unsigned char u_val)
{
int t;

/* Complement to obtain normal u-law value. */
u_val = ~u_val;

/*
* Extract and bias the quantization bits. then

* shift up by the segment number and subtract out the bias.
*/
t = ((u_val &amp;
QUANT_MASK) << 3) + BIAS;
t <<= ((unsigned)u_val &amp;
SEG_MASK) >> SEG_SHIFT;

return ((u_val &amp;
SIGN_BIT) ? (BIAS - t) : (t - BIAS));
}

/* A-law to u-law conversion */
unsigned char
alaw2ulaw(
unsigned char aval)
{
aval &amp;= 0xff;
return ((aval &amp;
0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) :
(0x7F ^ _a2u[aval ^ 0x55]));
}

/* u-law to A-law conversion */
unsigned char
ulaw2alaw(
unsigned char uval)
{
uval &amp;= 0xff;
return ((uval &amp;
0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) :
(0x55 ^ (_u2a[0x7F ^ uval] - 1)));
}
----------------------------------------------------------------------------------------------

/* g723_40.c文件内容:

/*
* This source code is a product of Sun Microsystems, Inc. and is provided
* for unrestricted use. Users may copy or modify this source code without
* charge.
*
* SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
* THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun source code is provided with no support and without any obligation on
* the part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/

/*
* g711.c
*
* u-law, A-law and linear PCM conversions.
*/
#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};

/* copy from CCITT G.711 specifications */
unsigned char _u2a[128] = { /* u- to A-law conversions */
1, 1, 2, 2, 3, 3, 4, 4,
5, 5, 6, 6, 7, 7, 8, 8,
9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24,
25, 27, 29, 31, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44,
46, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62,
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120,
121, 122, 123, 124, 125, 126, 127, 128};

unsigned char _a2u[128] = { /* A- to u-law conversions */
1, 3, 5, 7, 9, 11, 13, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
32, 32, 33, 33, 34, 34, 35, 35,
36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 48, 49, 49,
50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 64,
65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127};

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
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
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) &amp;
QUANT_MASK;
else

aval |= (pcm_val >> (seg + 3)) &amp;
QUANT_MASK;
return (aval ^ mask);
}
}

/*
* alaw2linear() - Convert an A-law value to 16-bit linear PCM
*
*/
int
alaw2linear(
unsigned char a_val)
{
int t;
int seg;

a_val ^= 0x55;

t = (a_val &amp;
QUANT_MASK) << 4;
seg = ((unsigned)a_val &amp;
SEG_MASK) >> SEG_SHIFT;
switch (seg) {
case 0:
t += 8;
break;
case 1:
t += 0x108;
break;
default:
t += 0x108;
t <<= seg - 1;
}
return ((a_val &amp;
SIGN_BIT) ? t : -t);
}

#define BIAS (0x84) /* Bias for linear code. */

/*
* linear2ulaw() - Convert a linear PCM value to u-law
*
* In order to simplify the encoding process, the original linear magnitude
* is biased by adding 33 which shifts the encoding range from (0 - 8158) to
* (33 - 8191). The result can be seen in the following encoding table:
*
* Biased Linear Input Code Compressed Code
* ------------------------ ---------------
* 00000001wxyza 000wxyz
* 0000001wxyzab 001wxyz
* 000001wxyzabc 010wxyz
* 00001wxyzabcd 011wxyz
* 0001wxyzabcde 100wxyz
* 001wxyzabcdef 101wxyz
* 01wxyzabcdefg 110wxyz
* 1wxyzabcdefgh 111wxyz
*
* Each biased linear code has a leading 1 which identifies the segment
* number. The value of the segment number is equal to 7 minus the number
* of leading 0's. The quantization interval is directly available as the
* four bits wxyz. * The trailing bits (a - h) are ignored.
*
* Ordinarily the complement of the resulting code word is used for
* transmission, and so the code word is complemented before it is returned.
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
unsigned char
linear2ulaw(
int pcm_val) /* 2's complement (16-bit range) */
{
int mask;
int seg;
unsigned char uval;

/* Get the sign and the magnitude of the value. */
if (pcm_val < 0) {
pcm_val = BIAS - pcm_val;
mask = 0x7F;
} else
{
pcm_val += BIAS;
mask = 0xFF;
}

/* Convert the scaled magnitude to segment number. */
seg = search(pcm_val, seg_end, 8);

/*
* Combine the sign, segment, quantization bits;
* and complement the code word.
*/
if (seg >= 8) /* out of range, return maximum value. */
return (0x7F ^ mask);
else
{
uval = (seg << 4) | ((pcm_val >> (seg + 3)) &amp;
0xF);
return (uval ^ mask);
}

}

/*
* ulaw2linear() - Convert a u-law value to 16-bit linear PCM
*
* First, a biased linear code is derived from the code word. An unbiased
* output can then
be obtained by subtracting 33 from the biased code.
*
* Note that this function expects to be passed the complement of the
* original code word. This is in keeping with ISDN conventions.
*/
int
ulaw2linear(
unsigned char u_val)
{
int t;

/* Complement to obtain normal u-law value. */
u_val = ~u_val;

/*
* Extract and bias the quantization bits. then

* shift up by the segment number and subtract out the bias.
*/
t = ((u_val &amp;
QUANT_MASK) << 3) + BIAS;
t <<= ((unsigned)u_val &amp;
SEG_MASK) >> SEG_SHIFT;

return ((u_val &amp;
SIGN_BIT) ? (BIAS - t) : (t - BIAS));
}

/* A-law to u-law conversion */
unsigned char
alaw2ulaw(
unsigned char aval)
{
aval &amp;= 0xff;
return ((aval &amp;
0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) :
(0x7F ^ _a2u[aval ^ 0x55]));
}

/* u-law to A-law conversion */
unsigned char
ulaw2alaw(
unsigned char uval)
{
uval &amp;= 0xff;
return ((uval &amp;
0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) :
(0x55 ^ (_u2a[0x7F ^ uval] - 1)));
}
----------------------------------------------------------------------------------

/*g72x.c文件内容:

/*
* This source code is a product of Sun Microsystems, Inc. and is provided
* for unrestricted use. Users may copy or modify this source code without
* charge.
*
* SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
* THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun source code is provided with no support and without any obligation on
* the part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/

/*
* g711.c
*
* u-law, A-law and linear PCM conversions.
*/
#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};

/* copy from CCITT G.711 specifications */
unsigned char _u2a[128] = { /* u- to A-law conversions */
1, 1, 2, 2, 3, 3, 4, 4,
5, 5, 6, 6, 7, 7, 8, 8,
9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24,
25, 27, 29, 31, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44,
46, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62,
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120,
121, 122, 123, 124, 125, 126, 127, 128};

unsigned char _a2u[128] = { /* A- to u-law conversions */
1, 3, 5, 7, 9, 11, 13, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
32, 32, 33, 33, 34, 34, 35, 35,
36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 48, 49, 49,
50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 64,
65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127};

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
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
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) &amp;
QUANT_MASK;
else

aval |= (pcm_val >> (seg + 3)) &amp;
QUANT_MASK;
return (aval ^ mask);
}
}

/*
* alaw2linear() - Convert an A-law value to 16-bit linear PCM
*
*/
int
alaw2linear(
unsigned char a_val)
{
int t;
int seg;

a_val ^= 0x55;

t = (a_val &amp;
QUANT_MASK) << 4;
seg = ((unsigned)a_val &amp;
SEG_MASK) >> SEG_SHIFT;
switch (seg) {
case 0:
t += 8;
break;
case 1:
t += 0x108;
break;
default:
t += 0x108;
t <<= seg - 1;
}
return ((a_val &amp;
SIGN_BIT) ? t : -t);
}

#define BIAS (0x84) /* Bias for linear code. */

/*
* linear2ulaw() - Convert a linear PCM value to u-law
*
* In order to simplify the encoding process, the original linear magnitude
* is biased by adding 33 which shifts the encoding range from (0 - 8158) to
* (33 - 8191). The result can be seen in the following encoding table:
*
* Biased Linear Input Code Compressed Code
* ------------------------ ---------------
* 00000001wxyza 000wxyz
* 0000001wxyzab 001wxyz
* 000001wxyzabc 010wxyz
* 00001wxyzabcd 011wxyz
* 0001wxyzabcde 100wxyz
* 001wxyzabcdef 101wxyz
* 01wxyzabcdefg 110wxyz
* 1wxyzabcdefgh 111wxyz
*
* Each biased linear code has a leading 1 which identifies the segment
* number. The value of the segment number is equal to 7 minus the number
* of leading 0's. The quantization interval is directly available as the
* four bits wxyz. * The trailing bits (a - h) are ignored.
*
* Ordinarily the complement of the resulting code word is used for
* transmission, and so the code word is complemented before it is returned.
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
unsigned char
linear2ulaw(
int pcm_val) /* 2's complement (16-bit range) */
{
int mask;
int seg;
unsigned char uval;

/* Get the sign and the magnitude of the value. */
if (pcm_val < 0) {
pcm_val = BIAS - pcm_val;
mask = 0x7F;
} else
{
pcm_val += BIAS;
mask = 0xFF;
}

/* Convert the scaled magnitude to segment number. */
seg = search(pcm_val, seg_end, 8);

/*
* Combine the sign, segment, quantization bits;
* and complement the code word.
*/
if (seg >= 8) /* out of range, return maximum value. */
return (0x7F ^ mask);
else
{
uval = (seg << 4) | ((pcm_val >> (seg + 3)) &amp;
0xF);
return (uval ^ mask);
}

}

/*
* ulaw2linear() - Convert a u-law value to 16-bit linear PCM
*
* First, a biased linear code is derived from the code word. An unbiased
* output can then
be obtained by subtracting 33 from the biased code.
*
* Note that this function expects to be passed the complement of the
* original code word. This is in keeping with ISDN conventions.
*/
int
ulaw2linear(
unsigned char u_val)
{
int t;

/* Complement to obtain normal u-law value. */
u_val = ~u_val;

/*
* Extract and bias the quantization bits. then

* shift up by the segment number and subtract out the bias.
*/
t = ((u_val &amp;
QUANT_MASK) << 3) + BIAS;
t <<= ((unsigned)u_val &amp;
SEG_MASK) >> SEG_SHIFT;

return ((u_val &amp;
SIGN_BIT) ? (BIAS - t) : (t - BIAS));
}

/* A-law to u-law conversion */
unsigned char
alaw2ulaw(
unsigned char aval)
{
aval &amp;= 0xff;
return ((aval &amp;
0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) :
(0x7F ^ _a2u[aval ^ 0x55]));
}

/* u-law to A-law conversion */
unsigned char
ulaw2alaw(
unsigned char uval)
{
uval &amp;= 0xff;
return ((uval &amp;
0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) :
(0x55 ^ (_u2a[0x7F ^ uval] - 1)));
}
----------------------------------------------------------------------------------

/* g72x.h文件内容:

/*
* This source code is a product of Sun Microsystems, Inc. and is provided
* for unrestricted use. Users may copy or modify this source code without
* charge.
*
* SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
* THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun source code is provided with no support and without any obligation on
* the part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/

/*
* g711.c
*
* u-law, A-law and linear PCM conversions.
*/
#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};

/* copy from CCITT G.711 specifications */
unsigned char _u2a[128] = { /* u- to A-law conversions */
1, 1, 2, 2, 3, 3, 4, 4,
5, 5, 6, 6, 7, 7, 8, 8,
9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24,
25, 27, 29, 31, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44,
46, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62,
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120,
121, 122, 123, 124, 125, 126, 127, 128};

unsigned char _a2u[128] = { /* A- to u-law conversions */
1, 3, 5, 7, 9, 11, 13, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
32, 32, 33, 33, 34, 34, 35, 35,
36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 48, 49, 49,
50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 64,
65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127};

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
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
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) &amp;
QUANT_MASK;
else

aval |= (pcm_val >> (seg + 3)) &amp;
QUANT_MASK;
return (aval ^ mask);
}
}

/*
* alaw2linear() - Convert an A-law value to 16-bit linear PCM
*
*/
int
alaw2linear(
unsigned char a_val)
{
int t;
int seg;

a_val ^= 0x55;

t = (a_val &amp;
QUANT_MASK) << 4;
seg = ((unsigned)a_val &amp;
SEG_MASK) >> SEG_SHIFT;
switch (seg) {
case 0:
t += 8;
break;
case 1:
t += 0x108;
break;
default:
t += 0x108;
t <<= seg - 1;
}
return ((a_val &amp;
SIGN_BIT) ? t : -t);
}

#define BIAS (0x84) /* Bias for linear code. */

/*
* linear2ulaw() - Convert a linear PCM value to u-law
*
* In order to simplify the encoding process, the original linear magnitude
* is biased by adding 33 which shifts the encoding range from (0 - 8158) to
* (33 - 8191). The result can be seen in the following encoding table:
*
* Biased Linear Input Code Compressed Code
* ------------------------ ---------------
* 00000001wxyza 000wxyz
* 0000001wxyzab 001wxyz
* 000001wxyzabc 010wxyz
* 00001wxyzabcd 011wxyz
* 0001wxyzabcde 100wxyz
* 001wxyzabcdef 101wxyz
* 01wxyzabcdefg 110wxyz
* 1wxyzabcdefgh 111wxyz
*
* Each biased linear code has a leading 1 which identifies the segment
* number. The value of the segment number is equal to 7 minus the number
* of leading 0's. The quantization interval is directly available as the
* four bits wxyz. * The trailing bits (a - h) are ignored.
*
* Ordinarily the complement of the resulting code word is used for
* transmission, and so the code word is complemented before it is returned.
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
unsigned char
linear2ulaw(
int pcm_val) /* 2's complement (16-bit range) */
{
int mask;
int seg;
unsigned char uval;

/* Get the sign and the magnitude of the value. */
if (pcm_val < 0) {
pcm_val = BIAS - pcm_val;
mask = 0x7F;
} else
{
pcm_val += BIAS;
mask = 0xFF;
}

/* Convert the scaled magnitude to segment number. */
seg = search(pcm_val, seg_end, 8);

/*
* Combine the sign, segment, quantization bits;
* and complement the code word.
*/
if (seg >= 8) /* out of range, return maximum value. */
return (0x7F ^ mask);
else
{
uval = (seg << 4) | ((pcm_val >> (seg + 3)) &amp;
0xF);
return (uval ^ mask);
}

}

/*
* ulaw2linear() - Convert a u-law value to 16-bit linear PCM
*
* First, a biased linear code is derived from the code word. An unbiased
* output can then
be obtained by subtracting 33 from the biased code.
*
* Note that this function expects to be passed the complement of the
* original code word. This is in keeping with ISDN conventions.
*/
int
ulaw2linear(
unsigned char u_val)
{
int t;

/* Complement to obtain normal u-law value. */
u_val = ~u_val;

/*
* Extract and bias the quantization bits. then

* shift up by the segment number and subtract out the bias.
*/
t = ((u_val &amp;
QUANT_MASK) << 3) + BIAS;
t <<= ((unsigned)u_val &amp;
SEG_MASK) >> SEG_SHIFT;

return ((u_val &amp;
SIGN_BIT) ? (BIAS - t) : (t - BIAS));
}

/* A-law to u-law conversion */
unsigned char
alaw2ulaw(
unsigned char aval)
{
aval &amp;= 0xff;
return ((aval &amp;
0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) :
(0x7F ^ _a2u[aval ^ 0x55]));
}

/* u-law to A-law conversion */
unsigned char
ulaw2alaw(
unsigned char uval)
{
uval &amp;= 0xff;
return ((uval &amp;
0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) :
(0x55 ^ (_u2a[0x7F ^ uval] - 1)));
}
--------------------------------------------------------------------------------------

/* makefile 文件内容

/*
* This source code is a product of Sun Microsystems, Inc. and is provided
* for unrestricted use. Users may copy or modify this source code without
* charge.
*
* SUN SOURCE CODE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING
* THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun source code is provided with no support and without any obligation on
* the part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS SOFTWARE
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/

/*
* g711.c
*
* u-law, A-law and linear PCM conversions.
*/
#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};

/* copy from CCITT G.711 specifications */
unsigned char _u2a[128] = { /* u- to A-law conversions */
1, 1, 2, 2, 3, 3, 4, 4,
5, 5, 6, 6, 7, 7, 8, 8,
9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24,
25, 27, 29, 31, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44,
46, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62,
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120,
121, 122, 123, 124, 125, 126, 127, 128};

unsigned char _a2u[128] = { /* A- to u-law conversions */
1, 3, 5, 7, 9, 11, 13, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
32, 32, 33, 33, 34, 34, 35, 35,
36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 48, 49, 49,
50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 64,
65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127};

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
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
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) &amp;
QUANT_MASK;
else

aval |= (pcm_val >> (seg + 3)) &amp;
QUANT_MASK;
return (aval ^ mask);
}
}

/*
* alaw2linear() - Convert an A-law value to 16-bit linear PCM
*
*/
int
alaw2linear(
unsigned char a_val)
{
int t;
int seg;

a_val ^= 0x55;

t = (a_val &amp;
QUANT_MASK) << 4;
seg = ((unsigned)a_val &amp;
SEG_MASK) >> SEG_SHIFT;
switch (seg) {
case 0:
t += 8;
break;
case 1:
t += 0x108;
break;
default:
t += 0x108;
t <<= seg - 1;
}
return ((a_val &amp;
SIGN_BIT) ? t : -t);
}

#define BIAS (0x84) /* Bias for linear code. */

/*
* linear2ulaw() - Convert a linear PCM value to u-law
*
* In order to simplify the encoding process, the original linear magnitude
* is biased by adding 33 which shifts the encoding range from (0 - 8158) to
* (33 - 8191). The result can be seen in the following encoding table:
*
* Biased Linear Input Code Compressed Code
* ------------------------ ---------------
* 00000001wxyza 000wxyz
* 0000001wxyzab 001wxyz
* 000001wxyzabc 010wxyz
* 00001wxyzabcd 011wxyz
* 0001wxyzabcde 100wxyz
* 001wxyzabcdef 101wxyz
* 01wxyzabcdefg 110wxyz
* 1wxyzabcdefgh 111wxyz
*
* Each biased linear code has a leading 1 which identifies the segment
* number. The value of the segment number is equal to 7 minus the number
* of leading 0's. The quantization interval is directly available as the
* four bits wxyz. * The trailing bits (a - h) are ignored.
*
* Ordinarily the complement of the resulting code word is used for
* transmission, and so the code word is complemented before it is returned.
*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley &amp;
Sons, pps 98-111 and 472-476.
*/
unsigned char
linear2ulaw(
int pcm_val) /* 2's complement (16-bit range) */
{
int mask;
int seg;
unsigned char uval;

/* Get the sign and the magnitude of the value. */
if (pcm_val < 0) {
pcm_val = BIAS - pcm_val;
mask = 0x7F;
} else
{
pcm_val += BIAS;
mask = 0xFF;
}

/* Convert the scaled magnitude to segment number. */
seg = search(pcm_val, seg_end, 8);

/*
* Combine the sign, segment, quantization bits;
* and complement the code word.
*/
if (seg >= 8) /* out of range, return maximum value. */
return (0x7F ^ mask);
else
{
uval = (seg << 4) | ((pcm_val >> (seg + 3)) &amp;
0xF);
return (uval ^ mask);
}

}

/*
* ulaw2linear() - Convert a u-law value to 16-bit linear PCM
*
* First, a biased linear code is derived from the code word. An unbiased
* output can then
be obtained by subtracting 33 from the biased code.
*
* Note that this function expects to be passed the complement of the
* original code word. This is in keeping with ISDN conventions.
*/
int
ulaw2linear(
unsigned char u_val)
{
int t;

/* Complement to obtain normal u-law value. */
u_val = ~u_val;

/*
* Extract and bias the quantization bits. then

* shift up by the segment number and subtract out the bias.
*/
t = ((u_val &amp;
QUANT_MASK) << 3) + BIAS;
t <<= ((unsigned)u_val &amp;
SEG_MASK) >> SEG_SHIFT;

return ((u_val &amp;
SIGN_BIT) ? (BIAS - t) : (t - BIAS));
}

/* A-law to u-law conversion */
unsigned char
alaw2ulaw(
unsigned char aval)
{
aval &amp;= 0xff;
return ((aval &amp;
0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) :
(0x7F ^ _a2u[aval ^ 0x55]));
}

/* u-law to A-law conversion */
unsigned char
ulaw2alaw(
unsigned char uval)
{
uval &amp;= 0xff;
return ((uval &amp;
0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) :
(0x55 ^ (_u2a[0x7F ^ uval] - 1)));
}
---------------------------------------------------------------------------------

/* readme 文件内容:

The files in this directory comprise ANSI-C language reference implementations
of the CCITT (International Telegraph and Telephone Consultative Committee)
G.711, G.721 and G.723 voice compressions. They have been tested on Sun
SPARCstations and passed 82 out of 84 test vectors published by CCITT
(Dec. 20, 1988) for G.721 and G.723. [The two remaining test vectors,
which the G.721 decoder implementation for u-law samples did not pass,
may be in error because they are identical to two other vectors for G.723_40.]

This source code is released by Sun Microsystems, Inc. to the publicdo
main.
Please give your acknowledgement in product literature if this code is used
in your product implementation.

Sun Microsystems supports some CCITT audio formats in Solaris 2.0 system
software. However, Sun's implementations have been optimized for higher
performance on SPARCstations.


The source files for CCITT conversion routines in this directory are:

g72x.h header file for g721.c, g723_24.c and g723_40.c
g711.c CCITT G.711 u-law and A-law compression
g72x.c common denominator of G.721 and G.723 ADPCM codes
g721.c CCITT G.721 32Kbps ADPCM coder (with g72x.c)
g723_24.c CCITT G.723 24Kbps ADPCM coder (with g72x.c)
g723_40.c CCITT G.723 40Kbps ADPCM coder (with g72x.c)


Simple conversions between u-law, A-law, and 16-bit linear PCM are invoked
as follows:

unsigned char ucode, acode;
short pcm_val;

ucode = linear2ulaw(pcm_val);
ucode = alaw2ulaw(acode);

acode = linear2alaw(pcm_val);
acode = ulaw2alaw(ucode);

pcm_val = ulaw2linear(ucode);
pcm_val = alaw2linear(acode);


The other CCITT compression routines are invoked as follows:

#include "g72x.h"

struct g72x_state state;
int sample, code;

g72x_init_state(&amp;state);
code = {g721,g723_24,g723_40}_encoder(sample, coding, &amp;state);
sample = {g721,g723_24,g723_40}_decoder(code, coding, &amp;state);

where
coding = AUDIO_ENCODING_ULAW for 8-bit u-law samples
AUDIO_ENCODING_ALAW for 8-bit A-law samples
AUDIO_ENCODING_LINEAR for 16-bit linear PCM samples



This directory also includes the following sample programs:

encode.c CCITT ADPCM encoder
decode.c CCITT ADPCM decoder
Makefile makefile for the sample programs


The sample programs contain examples of how to call the various compression
routines and pack/unpack the bits. The sample programs read byte streams from
stdin and write to stdout. The input/output data is raw data (no file header
or other identifying information is embedded). The sample programs are
invoked as follows:

encode [-3|4|5] [-a|u|l] <infile >outfile
decode [-3|4|5] [-a|u|l] <infile >outfile
where:
-3 encode to (decode from) G.723 24kbps (3-bit) data
-4 encode to (decode from) G.721 32kbps (4-bit) data [the default]
-5 encode to (decode from) G.723 40kbps (5-bit) data
-a encode from (decode to) A-law data
-u encode from (decode to) u-law data [the default]
-l encode from (decode to) 16-bit linear data

Examples:
# Read 16-bit linear and output G.721
encode -4 -l <pcmfile >g721file

# Read 40Kbps G.723 and output A-law
decode -5 -a <g723file >alawfile

# Compress and then
decompress u-law data using 24Kbps G.723
encode -3 <ulawin | deoced -3 >ulawout

------------------------------------------------------------------------------------

有谁能把它给翻译成delphi格式的(控件)?做完记得给我一份:wywdwq@chinese.com
 
谢谢各位了,就这样吧
 
希望有较详细的原代码,Delphi ,c ,c++都可以
谢谢! delphiinfomail@163.net
 
多人接受答案了。
 
后退
顶部