This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Defines | |
| #define | FREESWITCH_G711_H |
| #define | ULAW_BIAS 0x84 |
| #define | ALAW_AMI_MASK 0x55 |
Functions | |
| static __inline__ int | top_bit (unsigned int bits) |
| static __inline__ int | bottom_bit (unsigned int bits) |
| static __inline__ uint8_t | linear_to_ulaw (int linear) |
| Encode a linear sample to u-law. | |
| 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_alaw (int linear) |
| Encode a linear sample to A-law. | |
| static __inline__ int16_t | alaw_to_linear (uint8_t alaw) |
| Decode an A-law sample to a linear value. | |
| uint8_t | alaw_to_ulaw (uint8_t alaw) |
| Transcode from A-law to u-law, using the procedure defined in G.711. | |
| uint8_t | ulaw_to_alaw (uint8_t ulaw) |
| Transcode from u-law to A-law, using the procedure defined in G.711. | |
Definition in file g711.h.
| #define ALAW_AMI_MASK 0x55 |
| #define ULAW_BIAS 0x84 |
| static __inline__ int16_t alaw_to_linear | ( | uint8_t | alaw | ) | [static] |
Decode an A-law sample to a linear value.
| alaw | The A-law sample to decode. |
Definition at line 309 of file g711.h.
References ALAW_AMI_MASK.
Referenced by switch_g711a_decode().
00309 { 00310 int i; 00311 int seg; 00312 00313 alaw ^= ALAW_AMI_MASK; 00314 i = ((alaw & 0x0F) << 4); 00315 seg = (((int) alaw & 0x70) >> 4); 00316 if (seg) 00317 i = (i + 0x108) << (seg - 1); 00318 else 00319 i += 8; 00320 return (int16_t) ((alaw & 0x80) ? i : -i); 00321 }
| uint8_t alaw_to_ulaw | ( | uint8_t | alaw | ) |
Transcode from A-law to u-law, using the procedure defined in G.711.
| alaw | The A-law sample to transcode. |
Definition at line 79 of file g711.c.
References alaw_to_ulaw_table.
00080 { 00081 return alaw_to_ulaw_table[alaw]; 00082 }
| static __inline__ int bottom_bit | ( | unsigned int | bits | ) | [static] |
Definition at line 127 of file g711.h.
00127 { 00128 int i; 00129 00130 if (bits == 0) 00131 return -1; 00132 i = 32; 00133 if (bits & 0x0000FFFF) { 00134 bits &= 0x0000FFFF; 00135 i -= 16; 00136 } 00137 if (bits & 0x00FF00FF) { 00138 bits &= 0x00FF00FF; 00139 i -= 8; 00140 } 00141 if (bits & 0x0F0F0F0F) { 00142 bits &= 0x0F0F0F0F; 00143 i -= 4; 00144 } 00145 if (bits & 0x33333333) { 00146 bits &= 0x33333333; 00147 i -= 2; 00148 } 00149 if (bits & 0x55555555) { 00150 bits &= 0x55555555; 00151 i -= 1; 00152 } 00153 return i; 00154 }
| static __inline__ uint8_t linear_to_alaw | ( | int | linear | ) | [static] |
Encode a linear sample to A-law.
| linear | The sample to encode. |
Definition at line 277 of file g711.h.
References ALAW_AMI_MASK, and top_bit().
Referenced by switch_g711a_encode().
00277 { 00278 int mask; 00279 int seg; 00280 00281 if (linear >= 0) { 00282 /* Sign (bit 7) bit = 1 */ 00283 mask = ALAW_AMI_MASK | 0x80; 00284 } else { 00285 /* Sign (bit 7) bit = 0 */ 00286 mask = ALAW_AMI_MASK; 00287 linear = -linear - 8; 00288 } 00289 00290 /* Convert the scaled magnitude to segment number. */ 00291 seg = top_bit(linear | 0xFF) - 7; 00292 if (seg >= 8) { 00293 if (linear >= 0) { 00294 /* Out of range. Return maximum value. */ 00295 return (uint8_t) (0x7F ^ mask); 00296 } 00297 /* We must be just a tiny step below zero */ 00298 return (uint8_t) (0x00 ^ mask); 00299 } 00300 /* Combine the sign, segment, and quantization bits. */ 00301 return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask); 00302 }
| static __inline__ uint8_t linear_to_ulaw | ( | int | linear | ) | [static] |
Encode a linear sample to u-law.
| linear | The sample to encode. |
Definition at line 202 of file g711.h.
References top_bit(), and ULAW_BIAS.
Referenced by switch_g711u_encode().
00202 { 00203 uint8_t u_val; 00204 int mask; 00205 int seg; 00206 00207 /* Get the sign and the magnitude of the value. */ 00208 if (linear < 0) { 00209 linear = ULAW_BIAS - linear; 00210 mask = 0x7F; 00211 } else { 00212 linear = ULAW_BIAS + linear; 00213 mask = 0xFF; 00214 } 00215 00216 seg = top_bit(linear | 0xFF) - 7; 00217 00218 /* 00219 * Combine the sign, segment, quantization bits, 00220 * and complement the code word. 00221 */ 00222 if (seg >= 8) 00223 u_val = (uint8_t) (0x7F ^ mask); 00224 else 00225 u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask); 00226 #ifdef ULAW_ZEROTRAP 00227 /* Optional ITU trap */ 00228 if (u_val == 0) 00229 u_val = 0x02; 00230 #endif 00231 return u_val; 00232 }
| static __inline__ int top_bit | ( | unsigned int | bits | ) | [static] |
Definition at line 97 of file g711.h.
Referenced by linear_to_alaw(), and linear_to_ulaw().
00097 { 00098 int i; 00099 00100 if (bits == 0) 00101 return -1; 00102 i = 0; 00103 if (bits & 0xFFFF0000) { 00104 bits &= 0xFFFF0000; 00105 i += 16; 00106 } 00107 if (bits & 0xFF00FF00) { 00108 bits &= 0xFF00FF00; 00109 i += 8; 00110 } 00111 if (bits & 0xF0F0F0F0) { 00112 bits &= 0xF0F0F0F0; 00113 i += 4; 00114 } 00115 if (bits & 0xCCCCCCCC) { 00116 bits &= 0xCCCCCCCC; 00117 i += 2; 00118 } 00119 if (bits & 0xAAAAAAAA) { 00120 bits &= 0xAAAAAAAA; 00121 i += 1; 00122 } 00123 return i; 00124 }
| uint8_t ulaw_to_alaw | ( | uint8_t | ulaw | ) |
Transcode from u-law to A-law, using the procedure defined in G.711.
| ulaw | The u-law sample to transcode. |
Definition at line 86 of file g711.c.
References ulaw_to_alaw_table.
00087 { 00088 return ulaw_to_alaw_table[ulaw]; 00089 }
| static __inline__ int16_t ulaw_to_linear | ( | uint8_t | ulaw | ) | [static] |
Decode an u-law sample to a linear value.
| ulaw | The u-law sample to decode. |
Definition at line 239 of file g711.h.
References ULAW_BIAS.
Referenced by switch_g711u_decode().
00239 { 00240 int t; 00241 00242 /* Complement to obtain normal u-law value. */ 00243 ulaw = ~ulaw; 00244 /* 00245 * Extract and bias the quantization bits. Then 00246 * shift up by the segment number and subtract out the bias. 00247 */ 00248 t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4); 00249 return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS)); 00250 }
1.4.7