42 #if !defined(FREESWITCH_G711_H) 43 #define FREESWITCH_G711_H 51 #define __inline__ __inline 53 #if !defined(_STDINT) && !defined(uint32_t) 54 typedef unsigned __int8 uint8_t;
55 typedef __int16 int16_t;
56 typedef __int32 int32_t;
57 typedef unsigned __int16 uint16_t;
65 static __inline__
int top_bit(
unsigned int bits) {
68 __asm__ __volatile__(
" movl $-1,%%edx;\n" " bsrl %%eax,%%edx;\n":
"=d"(res)
74 static __inline__
int bottom_bit(
unsigned int bits) {
77 __asm__ __volatile__(
" movl $-1,%%edx;\n" " bsfl %%eax,%%edx;\n":
"=d"(res)
82 #elif defined(__x86_64__) 83 static __inline__
int top_bit(
unsigned int bits) {
86 __asm__ __volatile__(
" movq $-1,%%rdx;\n" " bsrq %%rax,%%rdx;\n":
"=d"(res)
90 static __inline__
int bottom_bit(
unsigned int bits) {
93 __asm__ __volatile__(
" movq $-1,%%rdx;\n" " bsfq %%rax,%%rdx;\n":
"=d"(res)
99 static __inline__
int top_bit(
unsigned int bits) {
105 if (bits & 0xFFFF0000) {
109 if (bits & 0xFF00FF00) {
113 if (bits & 0xF0F0F0F0) {
117 if (bits & 0xCCCCCCCC) {
121 if (bits & 0xAAAAAAAA) {
135 if (bits & 0x0000FFFF) {
139 if (bits & 0x00FF00FF) {
143 if (bits & 0x0F0F0F0F) {
147 if (bits & 0x33333333) {
151 if (bits & 0x55555555) {
198 #define ULAW_BIAS 0x84 218 seg =
top_bit(linear | 0xFF) - 7;
225 u_val = (uint8_t) (0x7F ^ mask);
227 u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask);
250 t = (((ulaw & 0x0F) << 3) +
ULAW_BIAS) << (((
int) ulaw & 0x70) >> 4);
273 #define ALAW_AMI_MASK 0x55 289 linear = -linear - 8;
293 seg =
top_bit(linear | 0xFF) - 7;
297 return (uint8_t) (0x7F ^ mask);
300 return (uint8_t) (0x00 ^ mask);
303 return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask);
316 i = ((alaw & 0x0F) << 4);
317 seg = (((int) alaw & 0x70) >> 4);
319 i = (i + 0x108) << (seg - 1);
322 return (int16_t) ((alaw & 0x80) ? i : -i);
uint8_t ulaw_to_alaw(uint8_t ulaw)
Transcode from u-law to A-law, using the procedure defined in G.711.
static __inline__ int bottom_bit(unsigned int bits)
static __inline__ uint8_t linear_to_alaw(int linear)
Encode a linear sample to A-law.
uint8_t alaw_to_ulaw(uint8_t alaw)
Transcode from A-law to u-law, using the procedure defined in G.711.
static __inline__ int16_t alaw_to_linear(uint8_t alaw)
Decode an A-law sample to a linear value.
static __inline__ int16_t ulaw_to_linear(uint8_t ulaw)
Decode an u-law sample to a linear value.
static __inline__ uint8_t linear_to_ulaw(int linear)
Encode a linear sample to u-law.
static __inline__ int top_bit(unsigned int bits)