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_encode.c - The ITU G.722 codec, encode part. | 4 * g722_encode.c - The ITU G.722 codec, encode 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 * All rights reserved. | 10 * All rights reserved. |
11 * | 11 * |
12 * Despite my general liking of the GPL, I place my own contributions | 12 * Despite my general liking of the GPL, I place my own contributions |
13 * to this code in the public domain for the benefit of all mankind - | 13 * to this code in the public domain for the benefit of all mankind - |
14 * even the slimy ones who might try to proprietize my work and use it | 14 * even the slimy ones who might try to proprietize my work and use it |
15 * to my detriment. | 15 * to my detriment. |
16 * | 16 * |
17 * Based on a single channel 64kbps only G.722 codec which is: | 17 * Based on a single channel 64kbps only G.722 codec which is: |
18 * | 18 * |
19 ***** Copyright (c) CMU 1993 ***** | 19 ***** Copyright (c) CMU 1993 ***** |
20 * Computer Science, Speech Group | 20 * Computer Science, Speech Group |
21 * Chengxiang Lu and Alex Hauptmann | 21 * Chengxiang Lu and Alex Hauptmann |
22 * | 22 * |
23 * $Id: g722_encode.c,v 1.14 2006/07/07 16:37:49 steveu Exp $ | 23 * $Id: g722_encode.c,v 1.14 2006/07/07 16:37:49 steveu Exp $ |
24 * | 24 * |
25 * Modifications for WebRtc, 2011/04/28, by tlegrand: | 25 * Modifications for WebRtc, 2011/04/28, by tlegrand: |
26 * -Removed usage of inttypes.h and tgmath.h | 26 * -Removed usage of inttypes.h and tgmath.h |
27 * -Changed to use WebRtc types | 27 * -Changed to use WebRtc types |
28 * -Added option to run encoder bitexact with ITU-T reference implementation | 28 * -Added option to run encoder bitexact with ITU-T reference implementation |
29 */ | 29 */ |
30 | 30 |
31 /*! \file */ | 31 /*! \file */ |
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 wd3 = (s->band[band].b[i]*32640) >> 15; | 111 wd3 = (s->band[band].b[i]*32640) >> 15; |
116 s->band[band].bp[i] = saturate(wd2 + wd3); | 112 s->band[band].bp[i] = saturate(wd2 + wd3); |
117 } | 113 } |
118 | 114 |
119 /* Block 4, DELAYA */ | 115 /* Block 4, DELAYA */ |
120 for (i = 6; i > 0; i--) | 116 for (i = 6; i > 0; i--) |
121 { | 117 { |
122 s->band[band].d[i] = s->band[band].d[i - 1]; | 118 s->band[band].d[i] = s->band[band].d[i - 1]; |
123 s->band[band].b[i] = s->band[band].bp[i]; | 119 s->band[band].b[i] = s->band[band].bp[i]; |
124 } | 120 } |
125 | 121 |
126 for (i = 2; i > 0; i--) | 122 for (i = 2; i > 0; i--) |
127 { | 123 { |
128 s->band[band].r[i] = s->band[band].r[i - 1]; | 124 s->band[band].r[i] = s->band[band].r[i - 1]; |
129 s->band[band].p[i] = s->band[band].p[i - 1]; | 125 s->band[band].p[i] = s->band[band].p[i - 1]; |
130 s->band[band].a[i] = s->band[band].ap[i]; | 126 s->band[band].a[i] = s->band[band].ap[i]; |
131 } | 127 } |
132 | 128 |
133 /* Block 4, FILTEP */ | 129 /* Block 4, FILTEP */ |
134 wd1 = saturate(s->band[band].r[1] + s->band[band].r[1]); | 130 wd1 = saturate(s->band[band].r[1] + s->band[band].r[1]); |
135 wd1 = (s->band[band].a[1]*wd1) >> 15; | 131 wd1 = (s->band[band].a[1]*wd1) >> 15; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 xlow = amp[j++] >> 1; | 300 xlow = amp[j++] >> 1; |
305 } | 301 } |
306 else | 302 else |
307 { | 303 { |
308 /* Apply the transmit QMF */ | 304 /* Apply the transmit QMF */ |
309 /* Shuffle the buffer down */ | 305 /* Shuffle the buffer down */ |
310 for (i = 0; i < 22; i++) | 306 for (i = 0; i < 22; i++) |
311 s->x[i] = s->x[i + 2]; | 307 s->x[i] = s->x[i + 2]; |
312 s->x[22] = amp[j++]; | 308 s->x[22] = amp[j++]; |
313 s->x[23] = amp[j++]; | 309 s->x[23] = amp[j++]; |
314 | 310 |
315 /* Discard every other QMF output */ | 311 /* Discard every other QMF output */ |
316 sumeven = 0; | 312 sumeven = 0; |
317 sumodd = 0; | 313 sumodd = 0; |
318 for (i = 0; i < 12; i++) | 314 for (i = 0; i < 12; i++) |
319 { | 315 { |
320 sumodd += s->x[2*i]*qmf_coeffs[i]; | 316 sumodd += s->x[2*i]*qmf_coeffs[i]; |
321 sumeven += s->x[2*i + 1]*qmf_coeffs[11 - i]; | 317 sumeven += s->x[2*i + 1]*qmf_coeffs[11 - i]; |
322 } | 318 } |
323 /* We shift by 12 to allow for the QMF filters (DC gain = 4096),
plus 1 | 319 /* We shift by 12 to allow for the QMF filters (DC gain = 4096),
plus 1 |
324 to allow for us summing two filters, plus 1 to allow for the
15 bit | 320 to allow for us summing two filters, plus 1 to allow for the
15 bit |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 else if (s->band[0].nb > 18432) | 360 else if (s->band[0].nb > 18432) |
365 s->band[0].nb = 18432; | 361 s->band[0].nb = 18432; |
366 | 362 |
367 /* Block 3L, SCALEL */ | 363 /* Block 3L, SCALEL */ |
368 wd1 = (s->band[0].nb >> 6) & 31; | 364 wd1 = (s->band[0].nb >> 6) & 31; |
369 wd2 = 8 - (s->band[0].nb >> 11); | 365 wd2 = 8 - (s->band[0].nb >> 11); |
370 wd3 = (wd2 < 0) ? (ilb[wd1] << -wd2) : (ilb[wd1] >> wd2); | 366 wd3 = (wd2 < 0) ? (ilb[wd1] << -wd2) : (ilb[wd1] >> wd2); |
371 s->band[0].det = wd3 << 2; | 367 s->band[0].det = wd3 << 2; |
372 | 368 |
373 block4(s, 0, dlow); | 369 block4(s, 0, dlow); |
374 | 370 |
375 if (s->eight_k) | 371 if (s->eight_k) |
376 { | 372 { |
377 /* Just leave the high bits as zero */ | 373 /* Just leave the high bits as zero */ |
378 code = (0xC0 | ilow) >> (8 - s->bits_per_sample); | 374 code = (0xC0 | ilow) >> (8 - s->bits_per_sample); |
379 } | 375 } |
380 else | 376 else |
381 { | 377 { |
382 /* Block 1H, SUBTRA */ | 378 /* Block 1H, SUBTRA */ |
383 eh = saturate(xhigh - s->band[1].s); | 379 eh = saturate(xhigh - s->band[1].s); |
384 | 380 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 } | 421 } |
426 else | 422 else |
427 { | 423 { |
428 g722_data[g722_bytes++] = (uint8_t) code; | 424 g722_data[g722_bytes++] = (uint8_t) code; |
429 } | 425 } |
430 } | 426 } |
431 return g722_bytes; | 427 return g722_bytes; |
432 } | 428 } |
433 /*- End of function --------------------------------------------------------*/ | 429 /*- End of function --------------------------------------------------------*/ |
434 /*- End of file ------------------------------------------------------------*/ | 430 /*- End of file ------------------------------------------------------------*/ |
OLD | NEW |