OLD | NEW |
1 /* | 1 /* |
2 * SpanDSP - a series of DSP components for telephony | 2 * SpanDSP - a series of DSP components for telephony |
3 * | 3 * |
4 * g722_decode.c - The ITU G.722 codec, decode part. | 4 * g722_decode.c - The ITU G.722 codec, decode part. |
5 * | 5 * |
6 * Written by Steve Underwood <steveu@coppice.org> | 6 * Written by Steve Underwood <steveu@coppice.org> |
7 * | 7 * |
8 * Copyright (C) 2005 Steve Underwood | 8 * Copyright (C) 2005 Steve Underwood |
9 * | 9 * |
10 * Despite my general liking of the GPL, I place my own contributions | 10 * Despite my general liking of the GPL, I place my own contributions |
11 * to this code in the public domain for the benefit of all mankind - | 11 * to this code in the public domain for the benefit of all mankind - |
12 * even the slimy ones who might try to proprietize my work and use it | 12 * even the slimy ones who might try to proprietize my work and use it |
13 * to my detriment. | 13 * to my detriment. |
14 * | 14 * |
15 * Based in part on a single channel G.722 codec which is: | 15 * Based in part on a single channel G.722 codec which is: |
16 * | 16 * |
17 * Copyright (c) CMU 1993 | 17 * Copyright (c) CMU 1993 |
18 * Computer Science, Speech Group | 18 * Computer Science, Speech Group |
19 * Chengxiang Lu and Alex Hauptmann | 19 * Chengxiang Lu and Alex Hauptmann |
20 * | 20 * |
21 * $Id: g722_decode.c,v 1.15 2006/07/07 16:37:49 steveu Exp $ | 21 * $Id: g722_decode.c,v 1.15 2006/07/07 16:37:49 steveu Exp $ |
22 * | 22 * |
23 * Modifications for WebRtc, 2011/04/28, by tlegrand: | 23 * Modifications for WebRtc, 2011/04/28, by tlegrand: |
24 * -Removed usage of inttypes.h and tgmath.h | 24 * -Removed usage of inttypes.h and tgmath.h |
25 * -Changed to use WebRtc types | 25 * -Changed to use WebRtc types |
26 * -Changed __inline__ to __inline | 26 * -Changed __inline__ to __inline |
27 * -Added saturation check on output | 27 * -Added saturation check on output |
28 */ | 28 */ |
29 | 29 |
30 /*! \file */ | 30 /*! \file */ |
31 | 31 |
32 | 32 |
33 #ifdef HAVE_CONFIG_H | |
34 #include <config.h> | |
35 #endif | |
36 | |
37 #include <memory.h> | 33 #include <memory.h> |
38 #include <stdio.h> | 34 #include <stdio.h> |
39 #include <stdlib.h> | 35 #include <stdlib.h> |
40 | 36 |
41 #include "g722_enc_dec.h" | 37 #include "g722_enc_dec.h" |
42 #include "webrtc/typedefs.h" | 38 #include "webrtc/typedefs.h" |
43 | 39 |
44 #if !defined(FALSE) | 40 #if !defined(FALSE) |
45 #define FALSE 0 | 41 #define FALSE 0 |
46 #endif | 42 #endif |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 wd3 = (s->band[band].b[i]*32640) >> 15; | 114 wd3 = (s->band[band].b[i]*32640) >> 15; |
119 s->band[band].bp[i] = saturate(wd2 + wd3); | 115 s->band[band].bp[i] = saturate(wd2 + wd3); |
120 } | 116 } |
121 | 117 |
122 /* Block 4, DELAYA */ | 118 /* Block 4, DELAYA */ |
123 for (i = 6; i > 0; i--) | 119 for (i = 6; i > 0; i--) |
124 { | 120 { |
125 s->band[band].d[i] = s->band[band].d[i - 1]; | 121 s->band[band].d[i] = s->band[band].d[i - 1]; |
126 s->band[band].b[i] = s->band[band].bp[i]; | 122 s->band[band].b[i] = s->band[band].bp[i]; |
127 } | 123 } |
128 | 124 |
129 for (i = 2; i > 0; i--) | 125 for (i = 2; i > 0; i--) |
130 { | 126 { |
131 s->band[band].r[i] = s->band[band].r[i - 1]; | 127 s->band[band].r[i] = s->band[band].r[i - 1]; |
132 s->band[band].p[i] = s->band[band].p[i - 1]; | 128 s->band[band].p[i] = s->band[band].p[i - 1]; |
133 s->band[band].a[i] = s->band[band].ap[i]; | 129 s->band[band].a[i] = s->band[band].ap[i]; |
134 } | 130 } |
135 | 131 |
136 /* Block 4, FILTEP */ | 132 /* Block 4, FILTEP */ |
137 wd1 = saturate(s->band[band].r[1] + s->band[band].r[1]); | 133 wd1 = saturate(s->band[band].r[1] + s->band[band].r[1]); |
138 wd1 = (s->band[band].a[1]*wd1) >> 15; | 134 wd1 = (s->band[band].a[1]*wd1) >> 15; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 { | 190 { |
195 2048, 2093, 2139, 2186, 2233, 2282, 2332, | 191 2048, 2093, 2139, 2186, 2233, 2282, 2332, |
196 2383, 2435, 2489, 2543, 2599, 2656, 2714, | 192 2383, 2435, 2489, 2543, 2599, 2656, 2714, |
197 2774, 2834, 2896, 2960, 3025, 3091, 3158, | 193 2774, 2834, 2896, 2960, 3025, 3091, 3158, |
198 3228, 3298, 3371, 3444, 3520, 3597, 3676, | 194 3228, 3298, 3371, 3444, 3520, 3597, 3676, |
199 3756, 3838, 3922, 4008 | 195 3756, 3838, 3922, 4008 |
200 }; | 196 }; |
201 static const int wh[3] = {0, -214, 798}; | 197 static const int wh[3] = {0, -214, 798}; |
202 static const int rh2[4] = {2, 1, 2, 1}; | 198 static const int rh2[4] = {2, 1, 2, 1}; |
203 static const int qm2[4] = {-7408, -1616, 7408, 1616}; | 199 static const int qm2[4] = {-7408, -1616, 7408, 1616}; |
204 static const int qm4[16] = | 200 static const int qm4[16] = |
205 { | 201 { |
206 0, -20456, -12896, -8968, | 202 0, -20456, -12896, -8968, |
207 -6288, -4240, -2584, -1200, | 203 -6288, -4240, -2584, -1200, |
208 20456, 12896, 8968, 6288, | 204 20456, 12896, 8968, 6288, |
209 4240, 2584, 1200, 0 | 205 4240, 2584, 1200, 0 |
210 }; | 206 }; |
211 static const int qm5[32] = | 207 static const int qm5[32] = |
212 { | 208 { |
213 -280, -280, -23352, -17560, | 209 -280, -280, -23352, -17560, |
214 -14120, -11664, -9752, -8184, | 210 -14120, -11664, -9752, -8184, |
215 -6864, -5712, -4696, -3784, | 211 -6864, -5712, -4696, -3784, |
216 -2960, -2208, -1520, -880, | 212 -2960, -2208, -1520, -880, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 | 312 |
317 /* Block 3L, LOGSCL */ | 313 /* Block 3L, LOGSCL */ |
318 wd2 = rl42[wd1]; | 314 wd2 = rl42[wd1]; |
319 wd1 = (s->band[0].nb*127) >> 7; | 315 wd1 = (s->band[0].nb*127) >> 7; |
320 wd1 += wl[wd2]; | 316 wd1 += wl[wd2]; |
321 if (wd1 < 0) | 317 if (wd1 < 0) |
322 wd1 = 0; | 318 wd1 = 0; |
323 else if (wd1 > 18432) | 319 else if (wd1 > 18432) |
324 wd1 = 18432; | 320 wd1 = 18432; |
325 s->band[0].nb = wd1; | 321 s->band[0].nb = wd1; |
326 | 322 |
327 /* Block 3L, SCALEL */ | 323 /* Block 3L, SCALEL */ |
328 wd1 = (s->band[0].nb >> 6) & 31; | 324 wd1 = (s->band[0].nb >> 6) & 31; |
329 wd2 = 8 - (s->band[0].nb >> 11); | 325 wd2 = 8 - (s->band[0].nb >> 11); |
330 wd3 = (wd2 < 0) ? (ilb[wd1] << -wd2) : (ilb[wd1] >> wd2); | 326 wd3 = (wd2 < 0) ? (ilb[wd1] << -wd2) : (ilb[wd1] >> wd2); |
331 s->band[0].det = wd3 << 2; | 327 s->band[0].det = wd3 << 2; |
332 | 328 |
333 block4(s, 0, dlowt); | 329 block4(s, 0, dlowt); |
334 | 330 |
335 if (!s->eight_k) | 331 if (!s->eight_k) |
336 { | 332 { |
337 /* Block 2H, INVQAH */ | 333 /* Block 2H, INVQAH */ |
338 wd2 = qm2[ihigh]; | 334 wd2 = qm2[ihigh]; |
339 dhigh = (s->band[1].det*wd2) >> 15; | 335 dhigh = (s->band[1].det*wd2) >> 15; |
340 /* Block 5H, RECONS */ | 336 /* Block 5H, RECONS */ |
341 rhigh = dhigh + s->band[1].s; | 337 rhigh = dhigh + s->band[1].s; |
342 /* Block 6H, LIMIT */ | 338 /* Block 6H, LIMIT */ |
343 if (rhigh > 16383) | 339 if (rhigh > 16383) |
344 rhigh = 16383; | 340 rhigh = 16383; |
345 else if (rhigh < -16384) | 341 else if (rhigh < -16384) |
346 rhigh = -16384; | 342 rhigh = -16384; |
347 | 343 |
348 /* Block 2H, INVQAH */ | 344 /* Block 2H, INVQAH */ |
349 wd2 = rh2[ihigh]; | 345 wd2 = rh2[ihigh]; |
350 wd1 = (s->band[1].nb*127) >> 7; | 346 wd1 = (s->band[1].nb*127) >> 7; |
351 wd1 += wh[wd2]; | 347 wd1 += wh[wd2]; |
352 if (wd1 < 0) | 348 if (wd1 < 0) |
353 wd1 = 0; | 349 wd1 = 0; |
354 else if (wd1 > 22528) | 350 else if (wd1 > 22528) |
355 wd1 = 22528; | 351 wd1 = 22528; |
356 s->band[1].nb = wd1; | 352 s->band[1].nb = wd1; |
357 | 353 |
358 /* Block 3H, SCALEH */ | 354 /* Block 3H, SCALEH */ |
359 wd1 = (s->band[1].nb >> 6) & 31; | 355 wd1 = (s->band[1].nb >> 6) & 31; |
360 wd2 = 10 - (s->band[1].nb >> 11); | 356 wd2 = 10 - (s->band[1].nb >> 11); |
361 wd3 = (wd2 < 0) ? (ilb[wd1] << -wd2) : (ilb[wd1] >> wd2); | 357 wd3 = (wd2 < 0) ? (ilb[wd1] << -wd2) : (ilb[wd1] >> wd2); |
362 s->band[1].det = wd3 << 2; | 358 s->band[1].det = wd3 << 2; |
363 | 359 |
364 block4(s, 1, dhigh); | 360 block4(s, 1, dhigh); |
365 } | 361 } |
366 | 362 |
367 if (s->itu_test_mode) | 363 if (s->itu_test_mode) |
(...skipping 27 matching lines...) Expand all Loading... |
395 /* WebRtc, tlegrand: added saturation */ | 391 /* WebRtc, tlegrand: added saturation */ |
396 amp[outlen++] = saturate(xout1 >> 11); | 392 amp[outlen++] = saturate(xout1 >> 11); |
397 amp[outlen++] = saturate(xout2 >> 11); | 393 amp[outlen++] = saturate(xout2 >> 11); |
398 } | 394 } |
399 } | 395 } |
400 } | 396 } |
401 return outlen; | 397 return outlen; |
402 } | 398 } |
403 /*- End of function --------------------------------------------------------*/ | 399 /*- End of function --------------------------------------------------------*/ |
404 /*- End of file ------------------------------------------------------------*/ | 400 /*- End of file ------------------------------------------------------------*/ |
OLD | NEW |