55 static APR_INLINE
int top_bit(
unsigned int bits)
59 __asm__ __volatile__(
" movl $-1,%%edx;\n"
60 " bsrl %%eax,%%edx;\n"
70 static APR_INLINE
int bottom_bit(
unsigned int bits)
74 __asm__ __volatile__(
" movl $-1,%%edx;\n"
75 " bsfl %%eax,%%edx;\n"
81 #elif defined(__x86_64__)
82 static APR_INLINE
int top_bit(
unsigned int bits)
86 __asm__ __volatile__(
" movq $-1,%%rdx;\n"
87 " bsrq %%rax,%%rdx;\n"
94 static APR_INLINE
int bottom_bit(
unsigned int bits)
98 __asm__ __volatile__(
" movq $-1,%%rdx;\n"
99 " bsfq %%rax,%%rdx;\n"
106 static APR_INLINE
int top_bit(
unsigned int bits)
113 if (bits & 0xFFFF0000)
118 if (bits & 0xFF00FF00)
123 if (bits & 0xF0F0F0F0)
128 if (bits & 0xCCCCCCCC)
133 if (bits & 0xAAAAAAAA)
142 static APR_INLINE
int bottom_bit(
unsigned int bits)
149 if (bits & 0x0000FFFF)
154 if (bits & 0x00FF00FF)
159 if (bits & 0x0F0F0F0F)
164 if (bits & 0x33333333)
169 if (bits & 0x55555555)
217 #define ULAW_BIAS 0x84
223 static APR_INLINE apr_byte_t linear_to_ulaw(
int linear)
232 linear = ULAW_BIAS - linear - 1;
237 linear = ULAW_BIAS + linear;
241 seg = top_bit(linear | 0xFF) - 7;
248 u_val = (apr_byte_t) (0x7F ^ mask);
250 u_val = (apr_byte_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask);
264 static APR_INLINE apr_int16_t ulaw_to_linear(apr_byte_t ulaw)
274 t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((
int) ulaw & 0x70) >> 4);
275 return (apr_int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS));
297 #define ALAW_AMI_MASK 0x55
303 static APR_INLINE apr_byte_t linear_to_alaw(
int linear)
311 mask = ALAW_AMI_MASK | 0x80;
316 mask = ALAW_AMI_MASK;
317 linear = -linear - 1;
321 seg = top_bit(linear | 0xFF) - 7;
327 return (apr_byte_t) (0x7F ^ mask);
331 return (apr_byte_t) (0x00 ^ mask);
335 return (apr_byte_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask);
343 static APR_INLINE apr_int16_t alaw_to_linear(apr_byte_t alaw)
348 alaw ^= ALAW_AMI_MASK;
349 i = ((alaw & 0x0F) << 4);
350 seg = (((int) alaw & 0x70) >> 4);
352 i = (i + 0x108) << (seg - 1);
355 return (apr_int16_t) ((alaw & 0x80) ? i : -i);
#define APT_END_EXTERN_C
Definition: apt.h:38
apr_byte_t ulaw_to_alaw(apr_byte_t ulaw)
Transcode from u-law to A-law, using the procedure defined in G.711.
#define APT_BEGIN_EXTERN_C
Definition: apt.h:36
Media Processing Framework Definitions.
apr_byte_t alaw_to_ulaw(apr_byte_t alaw)
Transcode from A-law to u-law, using the procedure defined in G.711.