niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 06c2aa9 | 2018-02-01 15:11:41 +0100 | [diff] [blame^] | 19 | #include "modules/audio_coding/codecs/ilbc/defines.h" |
| 20 | #include "modules/audio_coding/codecs/ilbc/constants.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
| 22 | /*----------------------------------------------------------------* |
| 23 | * Initiation of decoder instance. |
| 24 | *---------------------------------------------------------------*/ |
| 25 | |
Peter Kasting | a8b335c | 2015-06-11 18:51:20 -0700 | [diff] [blame] | 26 | int WebRtcIlbcfix_InitDecode( /* (o) Number of decoded samples */ |
pbos@webrtc.org | eb54446 | 2014-12-17 15:23:29 +0000 | [diff] [blame] | 27 | IlbcDecoder *iLBCdec_inst, /* (i/o) Decoder instance */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 28 | int16_t mode, /* (i) frame size mode */ |
kma@webrtc.org | 0221b78 | 2012-09-08 00:09:26 +0000 | [diff] [blame] | 29 | int use_enhancer) { /* (i) 1: use enhancer, 0: no enhancer */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | int i; |
| 31 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 95 | return (int)(iLBCdec_inst->blockl); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | } |