31 #include <itpp/itexports.h>
77 namespace g711_details {
83 class G711_Base_Properties
87 static ITPP_EXPORT uint8_t compression_table[128];
91 class MuLaw_Properties :
public G711_Base_Properties
94 static const int input_bitwidth = 14;
96 static const int16_t magnitude_offset = 33;
98 static const int16_t input_max = 8158;
100 static const int16_t input_min = -8159;
102 static ITPP_EXPORT int16_t expansion_table[256];
110 class ALaw_Properties :
public G711_Base_Properties
113 static const int input_bitwidth = 13;
115 static const int16_t input_max = 4095;
117 static const int16_t input_min = -4096;
119 static ITPP_EXPORT int16_t expansion_table[256];
134 using namespace g711_details;
135 return std::make_pair(MuLaw_Properties::input_min,MuLaw_Properties::input_max);
145 using namespace g711_details;
150 uint8_t
sign; uint16_t shifted_magnitude;
152 if(s > MuLaw_Properties::input_max) s = MuLaw_Properties::input_max;
153 shifted_magnitude = s + MuLaw_Properties::magnitude_offset;
157 if(s < MuLaw_Properties::input_min) s = MuLaw_Properties::input_min;
158 shifted_magnitude = (MuLaw_Properties::magnitude_offset - 1) - s;
163 uint8_t seg_no = MuLaw_Properties::compression_table[shifted_magnitude>>6];
166 uint8_t ret = (seg_no << 4) | ((shifted_magnitude >> (seg_no + 1)) & 0x0f);
176 inline int16_t
ulaw_expand(uint8_t s){
return g711_details::MuLaw_Properties::expansion_table[s];}
184 using namespace g711_details;
185 return std::make_pair(ALaw_Properties::input_min,ALaw_Properties::input_max);
194 using namespace g711_details;
198 uint8_t
sign; uint16_t magnitude;
200 if(s > ALaw_Properties::input_max) s = ALaw_Properties::input_max;
201 magnitude = s;
sign = 0xd5;
204 if(s < ALaw_Properties::input_min) s = ALaw_Properties::input_min;
205 magnitude = -1 - s;
sign = 0x55;
208 uint8_t exp_val = ALaw_Properties::compression_table[magnitude>>5];
212 ret = (exp_val << 4) | ((magnitude >> (exp_val)) & 0x0f);
215 ret = (uint8_t)magnitude >> 1;
226 inline int16_t
alaw_expand(uint8_t s){
return g711_details::ALaw_Properties::expansion_table[s];}