1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 /******************************************************************
12
13 iLBC Speech Coder ANSI-C Source Code
14
15 WebRtcIlbcfix_InitDecode.c
16
17 ******************************************************************/
18
19 #include "modules/audio_coding/codecs/ilbc/init_decode.h"
20
21 #include "modules/audio_coding/codecs/ilbc/constants.h"
22 #include "modules/audio_coding/codecs/ilbc/defines.h"
23
24 /*----------------------------------------------------------------*
25 * Initiation of decoder instance.
26 *---------------------------------------------------------------*/
27
WebRtcIlbcfix_InitDecode(IlbcDecoder * iLBCdec_inst,int16_t mode,int use_enhancer)28 int WebRtcIlbcfix_InitDecode( /* (o) Number of decoded samples */
29 IlbcDecoder *iLBCdec_inst, /* (i/o) Decoder instance */
30 int16_t mode, /* (i) frame size mode */
31 int use_enhancer) { /* (i) 1: use enhancer, 0: no enhancer */
32 int i;
33
34 iLBCdec_inst->mode = mode;
35
36 /* Set all the variables that are dependent on the frame size mode */
37 if (mode==30) {
38 iLBCdec_inst->blockl = BLOCKL_30MS;
39 iLBCdec_inst->nsub = NSUB_30MS;
40 iLBCdec_inst->nasub = NASUB_30MS;
41 iLBCdec_inst->lpc_n = LPC_N_30MS;
42 iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS;
43 iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS;
44 iLBCdec_inst->state_short_len=STATE_SHORT_LEN_30MS;
45 }
46 else if (mode==20) {
47 iLBCdec_inst->blockl = BLOCKL_20MS;
48 iLBCdec_inst->nsub = NSUB_20MS;
49 iLBCdec_inst->nasub = NASUB_20MS;
50 iLBCdec_inst->lpc_n = LPC_N_20MS;
51 iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS;
52 iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS;
53 iLBCdec_inst->state_short_len=STATE_SHORT_LEN_20MS;
54 }
55 else {
56 return(-1);
57 }
58
59 /* Reset all the previous LSF to mean LSF */
60 WEBRTC_SPL_MEMCPY_W16(iLBCdec_inst->lsfdeqold, WebRtcIlbcfix_kLsfMean, LPC_FILTERORDER);
61
62 /* Clear the synthesis filter memory */
63 WebRtcSpl_MemSetW16(iLBCdec_inst->syntMem, 0, LPC_FILTERORDER);
64
65 /* Set the old synthesis filter to {1.0 0.0 ... 0.0} */
66 WebRtcSpl_MemSetW16(iLBCdec_inst->old_syntdenum, 0, ((LPC_FILTERORDER + 1)*NSUB_MAX));
67 for (i=0; i<NSUB_MAX; i++) {
68 iLBCdec_inst->old_syntdenum[i*(LPC_FILTERORDER+1)] = 4096;
69 }
70
71 /* Clear the variables that are used for the PLC */
72 iLBCdec_inst->last_lag = 20;
73 iLBCdec_inst->consPLICount = 0;
74 iLBCdec_inst->prevPLI = 0;
75 iLBCdec_inst->perSquare = 0;
76 iLBCdec_inst->prevLag = 120;
77 iLBCdec_inst->prevLpc[0] = 4096;
78 WebRtcSpl_MemSetW16(iLBCdec_inst->prevLpc+1, 0, LPC_FILTERORDER);
79 WebRtcSpl_MemSetW16(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX);
80
81 /* Initialize the seed for the random number generator */
82 iLBCdec_inst->seed = 777;
83
84 /* Set the filter state of the HP filter to 0 */
85 WebRtcSpl_MemSetW16(iLBCdec_inst->hpimemx, 0, 2);
86 WebRtcSpl_MemSetW16(iLBCdec_inst->hpimemy, 0, 4);
87
88 /* Set the variables that are used in the ehnahcer */
89 iLBCdec_inst->use_enhancer = use_enhancer;
90 WebRtcSpl_MemSetW16(iLBCdec_inst->enh_buf, 0, (ENH_BUFL+ENH_BUFL_FILTEROVERHEAD));
91 for (i=0;i<ENH_NBLOCKS_TOT;i++) {
92 iLBCdec_inst->enh_period[i]=160; /* Q(-4) */
93 }
94
95 iLBCdec_inst->prev_enh_pl = 0;
96
97 return (int)(iLBCdec_inst->blockl);
98 }
99