78 for (i = 0; i < 3; i++)
82 wd2 = (s->
band[band].
sg[0] == s->
band[band].
sg[1]) ? -wd1 : wd1;
85 wd3 = (wd2 >> 7) + ((s->
band[band].
sg[0] == s->
band[band].
sg[2]) ? 128 : -128);
86 wd3 += (s->
band[band].
a[2]*32512) >> 15;
89 else if (wd3 < -12288)
96 wd1 = (s->
band[band].
sg[0] == s->
band[band].
sg[1]) ? 192 : -192;
97 wd2 = (s->
band[band].
a[1]*32640) >> 15;
101 if (s->
band[band].
ap[1] > wd3)
102 s->
band[band].
ap[1] = wd3;
103 else if (s->
band[band].
ap[1] < -wd3)
104 s->
band[band].
ap[1] = -wd3;
107 wd1 = (
d == 0) ? 0 : 128;
109 for (i = 1; i < 7; i++)
112 wd2 = (s->
band[band].
sg[i] == s->
band[band].
sg[0]) ? wd1 : -wd1;
113 wd3 = (s->
band[band].
b[i]*32640) >> 15;
118 for (i = 6; i > 0; i--)
124 for (i = 2; i > 0; i--)
133 wd1 = (s->
band[band].
a[1]*wd1) >> 15;
135 wd2 = (s->
band[band].
a[2]*wd2) >> 15;
140 for (i = 6; i > 0; i--)
143 s->
band[band].
sz += (s->
band[band].
b[i]*wd1) >> 15;
159 memset(s, 0,
sizeof(*s));
162 else if (rate == 56000)
187 static const int q6[32] =
189 0, 35, 72, 110, 150, 190, 233, 276,
190 323, 370, 422, 473, 530, 587, 650, 714,
191 786, 858, 940, 1023, 1121, 1219, 1339, 1458,
192 1612, 1765, 1980, 2195, 2557, 2919, 0, 0
194 static const int iln[32] =
196 0, 63, 62, 31, 30, 29, 28, 27,
197 26, 25, 24, 23, 22, 21, 20, 19,
198 18, 17, 16, 15, 14, 13, 12, 11,
199 10, 9, 8, 7, 6, 5, 4, 0
201 static const int ilp[32] =
203 0, 61, 60, 59, 58, 57, 56, 55,
204 54, 53, 52, 51, 50, 49, 48, 47,
205 46, 45, 44, 43, 42, 41, 40, 39,
206 38, 37, 36, 35, 34, 33, 32, 0
208 static const int wl[8] =
210 -60, -30, 58, 172, 334, 538, 1198, 3042
212 static const int rl42[16] =
214 0, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 0
216 static const int ilb[32] =
218 2048, 2093, 2139, 2186, 2233, 2282, 2332,
219 2383, 2435, 2489, 2543, 2599, 2656, 2714,
220 2774, 2834, 2896, 2960, 3025, 3091, 3158,
221 3228, 3298, 3371, 3444, 3520, 3597, 3676,
222 3756, 3838, 3922, 4008
224 static const int qm4[16] =
226 0, -20456, -12896, -8968,
227 -6288, -4240, -2584, -1200,
228 20456, 12896, 8968, 6288,
231 static const int qm2[4] =
233 -7408, -1616, 7408, 1616
235 static const int qmf_coeffs[12] =
237 3, -11, 12, 32, -210, 951, 3876, -805, 362, -156, 53, -11,
239 static const int ihn[3] = {0, 1, 0};
240 static const int ihp[3] = {0, 3, 2};
241 static const int wh[3] = {0, -214, 798};
242 static const int rh2[4] = {2, 1, 2, 1};
271 for (j = 0; j <
len; )
276 xhigh = amp[j++] >> 1;
282 xlow = amp[j++] >> 1;
288 for (i = 0; i < 22; i++)
289 s->
x[i] = s->
x[i + 2];
296 for (i = 0; i < 12; i++)
298 sumodd += s->
x[2*i]*qmf_coeffs[i];
299 sumeven += s->
x[2*i + 1]*qmf_coeffs[11 - i];
301 xlow = (sumeven + sumodd) >> 14;
302 xhigh = (sumeven - sumodd) >> 14;
309 wd = (
el >= 0) ?
el : -(
el + 1);
311 for (i = 1; i < 30; i++)
313 wd1 = (q6[i]*s->
band[0].
det) >> 12;
317 ilow = (
el < 0) ? iln[i] : ilp[i];
322 dlow = (s->
band[0].
det*wd2) >> 15;
326 wd = (s->
band[0].
nb*127) >> 7;
327 s->
band[0].
nb = wd + wl[il4];
330 else if (s->
band[0].
nb > 18432)
334 wd1 = (s->
band[0].
nb >> 6) & 31;
335 wd2 = 8 - (s->
band[0].
nb >> 11);
336 wd3 = (wd2 < 0) ? (ilb[wd1] << -wd2) : (ilb[wd1] >> wd2);
352 wd = (eh >= 0) ? eh : -(eh + 1);
353 wd1 = (564*s->
band[1].
det) >> 12;
354 mih = (wd >= wd1) ? 2 : 1;
355 ihigh = (eh < 0) ? ihn[mih] : ihp[mih];
359 dhigh = (s->
band[1].
det*wd2) >> 15;
363 wd = (s->
band[1].
nb*127) >> 7;
364 s->
band[1].
nb = wd + wh[ih2];
367 else if (s->
band[1].
nb > 22528)
371 wd1 = (s->
band[1].
nb >> 6) & 31;
372 wd2 = 10 - (s->
band[1].
nb >> 11);
373 wd3 = (wd2 < 0) ? (ilb[wd1] << -wd2) : (ilb[wd1] >> wd2);
387 g722_data[g722_bytes++] = (uint8_t) (s->
out_buffer & 0xFF);
394 g722_data[g722_bytes++] = (uint8_t) code;
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int g722_encode_release(g722_encode_state_t *s)
static void block4(g722_encode_state_t *s, int band, int d)
int g722_encode(g722_encode_state_t *s, uint8_t g722_data[], const int16_t amp[], int len)
g722_encode_state_t * g722_encode_init(g722_encode_state_t *s, int rate, int options)
static __inline__ int16_t saturate(int32_t amp)
struct g722_encode_state_t::@148 band[2]