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_InitEncode.c
16
17 ******************************************************************/
18
19 #include "modules/audio_coding/codecs/ilbc/init_encode.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 encoder instance.
26 *---------------------------------------------------------------*/
27
WebRtcIlbcfix_InitEncode(IlbcEncoder * iLBCenc_inst,int16_t mode)28 int WebRtcIlbcfix_InitEncode( /* (o) Number of bytes encoded */
29 IlbcEncoder *iLBCenc_inst, /* (i/o) Encoder instance */
30 int16_t mode) { /* (i) frame size mode */
31 iLBCenc_inst->mode = mode;
32
33 /* Set all the variables that are dependent on the frame size mode */
34 if (mode==30) {
35 iLBCenc_inst->blockl = BLOCKL_30MS;
36 iLBCenc_inst->nsub = NSUB_30MS;
37 iLBCenc_inst->nasub = NASUB_30MS;
38 iLBCenc_inst->lpc_n = LPC_N_30MS;
39 iLBCenc_inst->no_of_bytes = NO_OF_BYTES_30MS;
40 iLBCenc_inst->no_of_words = NO_OF_WORDS_30MS;
41 iLBCenc_inst->state_short_len=STATE_SHORT_LEN_30MS;
42 }
43 else if (mode==20) {
44 iLBCenc_inst->blockl = BLOCKL_20MS;
45 iLBCenc_inst->nsub = NSUB_20MS;
46 iLBCenc_inst->nasub = NASUB_20MS;
47 iLBCenc_inst->lpc_n = LPC_N_20MS;
48 iLBCenc_inst->no_of_bytes = NO_OF_BYTES_20MS;
49 iLBCenc_inst->no_of_words = NO_OF_WORDS_20MS;
50 iLBCenc_inst->state_short_len=STATE_SHORT_LEN_20MS;
51 }
52 else {
53 return(-1);
54 }
55
56 /* Clear the buffers and set the previous LSF and LSP to the mean value */
57 WebRtcSpl_MemSetW16(iLBCenc_inst->anaMem, 0, LPC_FILTERORDER);
58 WEBRTC_SPL_MEMCPY_W16(iLBCenc_inst->lsfold, WebRtcIlbcfix_kLsfMean, LPC_FILTERORDER);
59 WEBRTC_SPL_MEMCPY_W16(iLBCenc_inst->lsfdeqold, WebRtcIlbcfix_kLsfMean, LPC_FILTERORDER);
60 WebRtcSpl_MemSetW16(iLBCenc_inst->lpc_buffer, 0, LPC_LOOKBACK + BLOCKL_MAX);
61
62 /* Set the filter state of the HP filter to 0 */
63 WebRtcSpl_MemSetW16(iLBCenc_inst->hpimemx, 0, 2);
64 WebRtcSpl_MemSetW16(iLBCenc_inst->hpimemy, 0, 4);
65
66 #ifdef SPLIT_10MS
67 /*Zeroing the past samples for 10msec Split*/
68 WebRtcSpl_MemSetW16(iLBCenc_inst->past_samples,0,160);
69 iLBCenc_inst->section = 0;
70 #endif
71
72 return (int)(iLBCenc_inst->no_of_bytes);
73 }
74