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 "defines.h"
20#include "constants.h"
21
22/*----------------------------------------------------------------*
23 *  Initiation of decoder instance.
24 *---------------------------------------------------------------*/
25
26int16_t WebRtcIlbcfix_InitDecode(  /* (o) Number of decoded samples */
27    iLBC_Dec_Inst_t *iLBCdec_inst,  /* (i/o) Decoder instance */
28    int16_t mode,  /* (i) frame size mode */
29    int use_enhancer) {  /* (i) 1: use enhancer, 0: no enhancer */
30  int i;
31
32  iLBCdec_inst->mode = mode;
33
34  /* Set all the variables that are dependent on the frame size mode */
35  if (mode==30) {
36    iLBCdec_inst->blockl = BLOCKL_30MS;
37    iLBCdec_inst->nsub = NSUB_30MS;
38    iLBCdec_inst->nasub = NASUB_30MS;
39    iLBCdec_inst->lpc_n = LPC_N_30MS;
40    iLBCdec_inst->no_of_bytes = NO_OF_BYTES_30MS;
41    iLBCdec_inst->no_of_words = NO_OF_WORDS_30MS;
42    iLBCdec_inst->state_short_len=STATE_SHORT_LEN_30MS;
43  }
44  else if (mode==20) {
45    iLBCdec_inst->blockl = BLOCKL_20MS;
46    iLBCdec_inst->nsub = NSUB_20MS;
47    iLBCdec_inst->nasub = NASUB_20MS;
48    iLBCdec_inst->lpc_n = LPC_N_20MS;
49    iLBCdec_inst->no_of_bytes = NO_OF_BYTES_20MS;
50    iLBCdec_inst->no_of_words = NO_OF_WORDS_20MS;
51    iLBCdec_inst->state_short_len=STATE_SHORT_LEN_20MS;
52  }
53  else {
54    return(-1);
55  }
56
57  /* Reset all the previous LSF to mean LSF */
58  WEBRTC_SPL_MEMCPY_W16(iLBCdec_inst->lsfdeqold, WebRtcIlbcfix_kLsfMean, LPC_FILTERORDER);
59
60  /* Clear the synthesis filter memory */
61  WebRtcSpl_MemSetW16(iLBCdec_inst->syntMem, 0, LPC_FILTERORDER);
62
63  /* Set the old synthesis filter to {1.0 0.0 ... 0.0} */
64  WebRtcSpl_MemSetW16(iLBCdec_inst->old_syntdenum, 0, ((LPC_FILTERORDER + 1)*NSUB_MAX));
65  for (i=0; i<NSUB_MAX; i++) {
66    iLBCdec_inst->old_syntdenum[i*(LPC_FILTERORDER+1)] = 4096;
67  }
68
69  /* Clear the variables that are used for the PLC */
70  iLBCdec_inst->last_lag = 20;
71  iLBCdec_inst->consPLICount = 0;
72  iLBCdec_inst->prevPLI = 0;
73  iLBCdec_inst->perSquare = 0;
74  iLBCdec_inst->prevLag = 120;
75  iLBCdec_inst->prevLpc[0] = 4096;
76  WebRtcSpl_MemSetW16(iLBCdec_inst->prevLpc+1, 0, LPC_FILTERORDER);
77  WebRtcSpl_MemSetW16(iLBCdec_inst->prevResidual, 0, BLOCKL_MAX);
78
79  /* Initialize the seed for the random number generator */
80  iLBCdec_inst->seed = 777;
81
82  /* Set the filter state of the HP filter to 0 */
83  WebRtcSpl_MemSetW16(iLBCdec_inst->hpimemx, 0, 2);
84  WebRtcSpl_MemSetW16(iLBCdec_inst->hpimemy, 0, 4);
85
86  /* Set the variables that are used in the ehnahcer */
87  iLBCdec_inst->use_enhancer = use_enhancer;
88  WebRtcSpl_MemSetW16(iLBCdec_inst->enh_buf, 0, (ENH_BUFL+ENH_BUFL_FILTEROVERHEAD));
89  for (i=0;i<ENH_NBLOCKS_TOT;i++) {
90    iLBCdec_inst->enh_period[i]=160; /* Q(-4) */
91  }
92
93  iLBCdec_inst->prev_enh_pl = 0;
94
95  return (iLBCdec_inst->blockl);
96}
97