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 | define.h |
| 16 | |
| 17 | ******************************************************************/ |
| 18 | #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ILBC_MAIN_SOURCE_DEFINES_H_ |
| 19 | #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ILBC_MAIN_SOURCE_DEFINES_H_ |
| 20 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | #include <string.h> |
andresp@webrtc.org | 9730d3a | 2014-09-03 14:37:18 +0000 | [diff] [blame^] | 22 | #include "signal_processing_library.h" |
| 23 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
| 25 | /* general codec settings */ |
| 26 | |
| 27 | #define FS 8000 |
| 28 | #define BLOCKL_20MS 160 |
| 29 | #define BLOCKL_30MS 240 |
| 30 | #define BLOCKL_MAX 240 |
| 31 | #define NSUB_20MS 4 |
| 32 | #define NSUB_30MS 6 |
| 33 | #define NSUB_MAX 6 |
| 34 | #define NASUB_20MS 2 |
| 35 | #define NASUB_30MS 4 |
| 36 | #define NASUB_MAX 4 |
| 37 | #define SUBL 40 |
| 38 | #define STATE_LEN 80 |
| 39 | #define STATE_SHORT_LEN_30MS 58 |
| 40 | #define STATE_SHORT_LEN_20MS 57 |
| 41 | |
| 42 | /* LPC settings */ |
| 43 | |
| 44 | #define LPC_FILTERORDER 10 |
| 45 | #define LPC_LOOKBACK 60 |
| 46 | #define LPC_N_20MS 1 |
| 47 | #define LPC_N_30MS 2 |
| 48 | #define LPC_N_MAX 2 |
| 49 | #define LPC_ASYMDIFF 20 |
| 50 | #define LSF_NSPLIT 3 |
| 51 | #define LSF_NUMBER_OF_STEPS 4 |
| 52 | #define LPC_HALFORDER 5 |
| 53 | #define COS_GRID_POINTS 60 |
| 54 | |
| 55 | /* cb settings */ |
| 56 | |
| 57 | #define CB_NSTAGES 3 |
| 58 | #define CB_EXPAND 2 |
| 59 | #define CB_MEML 147 |
| 60 | #define CB_FILTERLEN (2*4) |
| 61 | #define CB_HALFFILTERLEN 4 |
| 62 | #define CB_RESRANGE 34 |
| 63 | #define CB_MAXGAIN_FIXQ6 83 /* error = -0.24% */ |
| 64 | #define CB_MAXGAIN_FIXQ14 21299 |
| 65 | |
| 66 | /* enhancer */ |
| 67 | |
| 68 | #define ENH_BLOCKL 80 /* block length */ |
| 69 | #define ENH_BLOCKL_HALF (ENH_BLOCKL/2) |
| 70 | #define ENH_HL 3 /* 2*ENH_HL+1 is number blocks |
| 71 | in said second sequence */ |
| 72 | #define ENH_SLOP 2 /* max difference estimated and |
| 73 | correct pitch period */ |
| 74 | #define ENH_PLOCSL 8 /* pitch-estimates and |
| 75 | pitch-locations buffer length */ |
| 76 | #define ENH_OVERHANG 2 |
| 77 | #define ENH_UPS0 4 /* upsampling rate */ |
| 78 | #define ENH_FL0 3 /* 2*FLO+1 is the length of each filter */ |
| 79 | #define ENH_FLO_MULT2_PLUS1 7 |
| 80 | #define ENH_VECTL (ENH_BLOCKL+2*ENH_FL0) |
| 81 | #define ENH_CORRDIM (2*ENH_SLOP+1) |
| 82 | #define ENH_NBLOCKS (BLOCKL/ENH_BLOCKL) |
| 83 | #define ENH_NBLOCKS_EXTRA 5 |
| 84 | #define ENH_NBLOCKS_TOT 8 /* ENH_NBLOCKS+ENH_NBLOCKS_EXTRA */ |
| 85 | #define ENH_BUFL (ENH_NBLOCKS_TOT)*ENH_BLOCKL |
| 86 | #define ENH_BUFL_FILTEROVERHEAD 3 |
| 87 | #define ENH_A0 819 /* Q14 */ |
| 88 | #define ENH_A0_MINUS_A0A0DIV4 848256041 /* Q34 */ |
| 89 | #define ENH_A0DIV2 26843546 /* Q30 */ |
| 90 | |
| 91 | /* PLC */ |
| 92 | |
| 93 | /* Down sampling */ |
| 94 | |
| 95 | #define FILTERORDER_DS_PLUS1 7 |
| 96 | #define DELAY_DS 3 |
| 97 | #define FACTOR_DS 2 |
| 98 | |
| 99 | /* bit stream defs */ |
| 100 | |
| 101 | #define NO_OF_BYTES_20MS 38 |
| 102 | #define NO_OF_BYTES_30MS 50 |
| 103 | #define NO_OF_WORDS_20MS 19 |
| 104 | #define NO_OF_WORDS_30MS 25 |
| 105 | #define STATE_BITS 3 |
| 106 | #define BYTE_LEN 8 |
| 107 | #define ULP_CLASSES 3 |
| 108 | |
| 109 | /* help parameters */ |
| 110 | |
| 111 | #define TWO_PI_FIX 25736 /* Q12 */ |
| 112 | |
| 113 | /* Constants for codebook search and creation */ |
| 114 | |
| 115 | #define ST_MEM_L_TBL 85 |
| 116 | #define MEM_LF_TBL 147 |
| 117 | |
| 118 | |
| 119 | /* Struct for the bits */ |
| 120 | typedef struct iLBC_bits_t_ { |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 121 | int16_t lsf[LSF_NSPLIT*LPC_N_MAX]; |
| 122 | int16_t cb_index[CB_NSTAGES*(NASUB_MAX+1)]; /* First CB_NSTAGES values contains extra CB index */ |
| 123 | int16_t gain_index[CB_NSTAGES*(NASUB_MAX+1)]; /* First CB_NSTAGES values contains extra CB gain */ |
| 124 | int16_t idxForMax; |
| 125 | int16_t state_first; |
| 126 | int16_t idxVec[STATE_SHORT_LEN_30MS]; |
| 127 | int16_t firstbits; |
| 128 | int16_t startIdx; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | } iLBC_bits; |
| 130 | |
| 131 | /* type definition encoder instance */ |
| 132 | typedef struct iLBC_Enc_Inst_t_ { |
| 133 | |
| 134 | /* flag for frame size mode */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 135 | int16_t mode; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 136 | |
| 137 | /* basic parameters for different frame sizes */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 138 | int16_t blockl; |
| 139 | int16_t nsub; |
| 140 | int16_t nasub; |
| 141 | int16_t no_of_bytes, no_of_words; |
| 142 | int16_t lpc_n; |
| 143 | int16_t state_short_len; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 144 | |
| 145 | /* analysis filter state */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 146 | int16_t anaMem[LPC_FILTERORDER]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 147 | |
| 148 | /* Fix-point old lsf parameters for interpolation */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 149 | int16_t lsfold[LPC_FILTERORDER]; |
| 150 | int16_t lsfdeqold[LPC_FILTERORDER]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 151 | |
| 152 | /* signal buffer for LP analysis */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 153 | int16_t lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 154 | |
| 155 | /* state of input HP filter */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 156 | int16_t hpimemx[2]; |
| 157 | int16_t hpimemy[4]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 158 | |
| 159 | #ifdef SPLIT_10MS |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 160 | int16_t weightdenumbuf[66]; |
| 161 | int16_t past_samples[160]; |
| 162 | uint16_t bytes[25]; |
| 163 | int16_t section; |
| 164 | int16_t Nfor_flag; |
| 165 | int16_t Nback_flag; |
| 166 | int16_t start_pos; |
| 167 | int16_t diff; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 168 | #endif |
| 169 | |
| 170 | } iLBC_Enc_Inst_t; |
| 171 | |
| 172 | /* type definition decoder instance */ |
| 173 | typedef struct iLBC_Dec_Inst_t_ { |
| 174 | |
| 175 | /* flag for frame size mode */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 176 | int16_t mode; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 177 | |
| 178 | /* basic parameters for different frame sizes */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 179 | int16_t blockl; |
| 180 | int16_t nsub; |
| 181 | int16_t nasub; |
| 182 | int16_t no_of_bytes, no_of_words; |
| 183 | int16_t lpc_n; |
| 184 | int16_t state_short_len; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 185 | |
| 186 | /* synthesis filter state */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 187 | int16_t syntMem[LPC_FILTERORDER]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 188 | |
| 189 | /* old LSF for interpolation */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 190 | int16_t lsfdeqold[LPC_FILTERORDER]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 191 | |
| 192 | /* pitch lag estimated in enhancer and used in PLC */ |
| 193 | int last_lag; |
| 194 | |
| 195 | /* PLC state information */ |
| 196 | int consPLICount, prev_enh_pl; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 197 | int16_t perSquare; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 198 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 199 | int16_t prevScale, prevPLI; |
| 200 | int16_t prevLag, prevLpc[LPC_FILTERORDER+1]; |
| 201 | int16_t prevResidual[NSUB_MAX*SUBL]; |
| 202 | int16_t seed; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 203 | |
| 204 | /* previous synthesis filter parameters */ |
| 205 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 206 | int16_t old_syntdenum[(LPC_FILTERORDER + 1)*NSUB_MAX]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | |
| 208 | /* state of output HP filter */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 209 | int16_t hpimemx[2]; |
| 210 | int16_t hpimemy[4]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 211 | |
| 212 | /* enhancer state information */ |
| 213 | int use_enhancer; |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 214 | int16_t enh_buf[ENH_BUFL+ENH_BUFL_FILTEROVERHEAD]; |
| 215 | int16_t enh_period[ENH_NBLOCKS_TOT]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 216 | |
| 217 | } iLBC_Dec_Inst_t; |
| 218 | |
| 219 | #endif |