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