#ifdefined(__i386__) /*! \brief Find the bit position of the highest set bit in a word \parambitsThewordtobesearched
\return The bit number of the highest set bit, or -1 if the word is zero. */ static __inline__ int top_bit(unsigned int bits) {
int res;
/*! \brief Find the bit position of the lowest set bit in a word \parambitsThewordtobesearched
\return The bit number of the lowest set bit, or -1 if the word is zero. */ static __inline__ int bottom_bit(unsigned int bits) {
int res;
__asm__ __volatile__( " movl $-1,%%edx;\n" " bsfl %%eax,%%edx;\n"
: "=d"(res)
: "a"(bits)); return res;
} #elifdefined(__x86_64__) static __inline__ int top_bit(unsigned int bits) {
int res;
static __inline__ int bottom_bit(unsigned int bits) {
int res;
__asm__ __volatile__( " movq $-1,%%rdx;\n" " bsfq %%rax,%%rdx;\n"
: "=d"(res)
: "a"(bits)); return res;
} #else static __inline int top_bit(unsigned int bits) {
int i;
if (bits == 0) { return -1;
}
i = 0;
if (bits & 0xFFFF0000) {
bits &= 0xFFFF0000;
i += 16;
}
if (bits & 0xFF00FF00) {
bits &= 0xFF00FF00;
i += 8;
}
if (bits & 0xF0F0F0F0) {
bits &= 0xF0F0F0F0;
i += 4;
}
if (bits & 0xCCCCCCCC) {
bits &= 0xCCCCCCCC;
i += 2;
}
if (bits & 0xAAAAAAAA) {
bits &= 0xAAAAAAAA;
i += 1;
} return i;
}
static __inline int bottom_bit(unsigned int bits) {
int i;
if (bits == 0) { return -1;
}
i = 32;
if (bits & 0x0000FFFF) {
bits &= 0x0000FFFF;
i -= 16;
}
if (bits & 0x00FF00FF) {
bits &= 0x00FF00FF;
i -= 8;
}
if (bits & 0x0F0F0F0F) {
bits &= 0x0F0F0F0F;
i -= 4;
}
if (bits & 0x33333333) {
bits &= 0x33333333;
i -= 2;
}
if (bits & 0x55555555) {
bits &= 0x55555555;
i -= 1;
} return i;
} #endif
/* N.B. It is tempting to use look-up tables for A-law and u-law conversion. *However,youshouldconsiderthecachefootprint. * *A64Kbytetableforlineartox-lawanda512bytetableforx-lawto *linearsoundlikepeanutsthesedays,andshouldn'tanarraylookupbe *realfast?No!Whenthecachesloshesasbadlyasthisonewill,atight *calculationmaybebetter.Themessiestpartisnormallyfindingthe *segment,butalittleinlineassemblycanfixthatonani386,x86_64 *andmanyothermodernprocessors.
*/
// #define ULAW_ZEROTRAP /* turn on the trap as per the MIL-STD //*/ #define ULAW_BIAS 0x84 /* Bias for linear code. */
/*! \brief Encode a linear sample to u-law \paramlinearThesampletoencode. \returnTheu-lawvalue.
*/ static __inline uint8_t linear_to_ulaw(int linear) {
uint8_t u_val;
int mask;
int seg;
/* Get the sign and the magnitude of the value. */
if (linear < 0) { /* WebRtc, tlegrand: -1 added to get bitexact to reference implementation */
linear = ULAW_BIAS - linear - 1;
mask = 0x7F;
} else {
linear = ULAW_BIAS + linear;
mask = 0xFF;
}
/*! \brief Decode an u-law sample to a linear value. \paramulawTheu-lawsampletodecode. \returnThelinearvalue.
*/ static __inline int16_t ulaw_to_linear(uint8_t ulaw) {
int t;
/*! \brief Encode a linear sample to A-law \paramlinearThesampletoencode. \returnTheA-lawvalue.
*/ static __inline uint8_t linear_to_alaw(int linear) {
int mask;
int seg;
if (linear >= 0) { /* Sign (bit 7) bit = 1 */
mask = ALAW_AMI_MASK | 0x80;
} else { /* Sign (bit 7) bit = 0 */
mask = ALAW_AMI_MASK; /* WebRtc, tlegrand: Changed from -8 to -1 to get bitexact to reference
* implementation */
linear = -linear - 1;
}
/* Convert the scaled magnitude to segment number. */
seg = top_bit(linear | 0xFF) - 7;
if (seg >= 8) {
if (linear >= 0) { /* Out of range. Return maximum value. */ return (uint8_t)(0x7F ^ mask);
} /* We must be just a tiny step below zero */ return (uint8_t)(0x00 ^ mask);
} /* Combine the sign, segment, and quantization bits. */ return (uint8_t)(((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^
mask);
}
/*! \brief Decode an A-law sample to a linear value. \paramalawTheA-lawsampletodecode. \returnThelinearvalue.
*/ static __inline int16_t alaw_to_linear(uint8_t alaw) {
int i;
int seg;
alaw ^= ALAW_AMI_MASK;
i = ((alaw & 0x0F) << 4);
seg = (((int)alaw & 0x70) >> 4);
if (seg)
i = (i + 0x108) << (seg - 1); else
i += 8; return (int16_t)((alaw & 0x80) ? i : -i);
}
/*! \brief Transcode from A-law to u-law, using the procedure defined in G.711. \paramalawTheA-lawsampletotranscode. \returnThebestmatchingu-lawvalue.
*/
uint8_t alaw_to_ulaw(uint8_t alaw);
/*! \brief Transcode from u-law to A-law, using the procedure defined in G.711. \paramalawTheu-lawsampletotranscode. \returnThebestmatchingA-lawvalue.
*/
uint8_t ulaw_to_alaw(uint8_t ulaw);
#ifdef __cplusplus
} #endif
#endif/* MODULES_THIRD_PARTY_G711_G711_H_ */
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-08-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.