blob: 43948a20c2b0623fa15a5b6d6e307d6c6cbbbf7c [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020018#ifndef MODULES_AUDIO_CODING_CODECS_ILBC_MAIN_SOURCE_DEFINES_H_
19#define MODULES_AUDIO_CODING_CODECS_ILBC_MAIN_SOURCE_DEFINES_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000020
henrike@webrtc.org1b8b4c42014-09-03 19:42:16 +000021#include <string.h>
Mirko Bonadei06c2aa92018-02-01 15:11:41 +010022
23#include "common_audio/signal_processing/include/signal_processing_library.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024
25/* general codec settings */
26
Yves Gerey665174f2018-06-19 15:03:05 +020027#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
niklase@google.com470e71d2011-07-07 08:21:25 +000041
42/* LPC settings */
43
Yves Gerey665174f2018-06-19 15:03:05 +020044#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
niklase@google.com470e71d2011-07-07 08:21:25 +000053#define COS_GRID_POINTS 60
54
55/* cb settings */
56
Yves Gerey665174f2018-06-19 15:03:05 +020057#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
niklase@google.com470e71d2011-07-07 08:21:25 +000065
66/* enhancer */
67
Yves Gerey665174f2018-06-19 15:03:05 +020068#define ENH_BLOCKL 80 /* block length */
69#define ENH_BLOCKL_HALF (ENH_BLOCKL / 2)
70#define ENH_HL \
71 3 /* 2*ENH_HL+1 is number blocks \
72 in said second \
73 sequence */
74#define ENH_SLOP \
75 2 /* max difference estimated and \
76 correct pitch period */
77#define ENH_PLOCSL \
78 8 /* pitch-estimates and \
79 pitch-locations buffer \
80 length */
81#define ENH_OVERHANG 2
82#define ENH_UPS0 4 /* upsampling rate */
83#define ENH_FL0 3 /* 2*FLO+1 is the length of each filter */
84#define ENH_FLO_MULT2_PLUS1 7
85#define ENH_VECTL (ENH_BLOCKL + 2 * ENH_FL0)
86#define ENH_CORRDIM (2 * ENH_SLOP + 1)
87#define ENH_NBLOCKS (BLOCKL / ENH_BLOCKL)
88#define ENH_NBLOCKS_EXTRA 5
89#define ENH_NBLOCKS_TOT 8 /* ENH_NBLOCKS+ENH_NBLOCKS_EXTRA */
90#define ENH_BUFL (ENH_NBLOCKS_TOT) * ENH_BLOCKL
91#define ENH_BUFL_FILTEROVERHEAD 3
92#define ENH_A0 819 /* Q14 */
93#define ENH_A0_MINUS_A0A0DIV4 848256041 /* Q34 */
94#define ENH_A0DIV2 26843546 /* Q30 */
niklase@google.com470e71d2011-07-07 08:21:25 +000095
96/* PLC */
97
98/* Down sampling */
99
Yves Gerey665174f2018-06-19 15:03:05 +0200100#define FILTERORDER_DS_PLUS1 7
101#define DELAY_DS 3
102#define FACTOR_DS 2
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
104/* bit stream defs */
105
Yves Gerey665174f2018-06-19 15:03:05 +0200106#define NO_OF_BYTES_20MS 38
107#define NO_OF_BYTES_30MS 50
108#define NO_OF_WORDS_20MS 19
109#define NO_OF_WORDS_30MS 25
110#define STATE_BITS 3
111#define BYTE_LEN 8
112#define ULP_CLASSES 3
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
114/* help parameters */
115
Yves Gerey665174f2018-06-19 15:03:05 +0200116#define TWO_PI_FIX 25736 /* Q12 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000117
118/* Constants for codebook search and creation */
119
Yves Gerey665174f2018-06-19 15:03:05 +0200120#define ST_MEM_L_TBL 85
121#define MEM_LF_TBL 147
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
123/* Struct for the bits */
124typedef struct iLBC_bits_t_ {
Yves Gerey665174f2018-06-19 15:03:05 +0200125 int16_t lsf[LSF_NSPLIT * LPC_N_MAX];
126 int16_t cb_index[CB_NSTAGES * (NASUB_MAX + 1)]; /* First CB_NSTAGES values
127 contains extra CB index */
128 int16_t gain_index[CB_NSTAGES * (NASUB_MAX + 1)]; /* First CB_NSTAGES values
129 contains extra CB gain */
Peter Kastingdce40cf2015-08-24 14:52:23 -0700130 size_t idxForMax;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000131 int16_t state_first;
132 int16_t idxVec[STATE_SHORT_LEN_30MS];
133 int16_t firstbits;
Peter Kastingdce40cf2015-08-24 14:52:23 -0700134 size_t startIdx;
niklase@google.com470e71d2011-07-07 08:21:25 +0000135} iLBC_bits;
136
137/* type definition encoder instance */
pbos@webrtc.orgeb544462014-12-17 15:23:29 +0000138typedef struct IlbcEncoder_ {
niklase@google.com470e71d2011-07-07 08:21:25 +0000139 /* flag for frame size mode */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000140 int16_t mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
142 /* basic parameters for different frame sizes */
Peter Kastingdce40cf2015-08-24 14:52:23 -0700143 size_t blockl;
144 size_t nsub;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000145 int16_t nasub;
Peter Kastingdce40cf2015-08-24 14:52:23 -0700146 size_t no_of_bytes, no_of_words;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000147 int16_t lpc_n;
Peter Kastingdce40cf2015-08-24 14:52:23 -0700148 size_t state_short_len;
niklase@google.com470e71d2011-07-07 08:21:25 +0000149
150 /* analysis filter state */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000151 int16_t anaMem[LPC_FILTERORDER];
niklase@google.com470e71d2011-07-07 08:21:25 +0000152
153 /* Fix-point old lsf parameters for interpolation */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000154 int16_t lsfold[LPC_FILTERORDER];
155 int16_t lsfdeqold[LPC_FILTERORDER];
niklase@google.com470e71d2011-07-07 08:21:25 +0000156
157 /* signal buffer for LP analysis */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000158 int16_t lpc_buffer[LPC_LOOKBACK + BLOCKL_MAX];
niklase@google.com470e71d2011-07-07 08:21:25 +0000159
160 /* state of input HP filter */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000161 int16_t hpimemx[2];
162 int16_t hpimemy[4];
niklase@google.com470e71d2011-07-07 08:21:25 +0000163
164#ifdef SPLIT_10MS
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000165 int16_t weightdenumbuf[66];
166 int16_t past_samples[160];
167 uint16_t bytes[25];
168 int16_t section;
169 int16_t Nfor_flag;
170 int16_t Nback_flag;
171 int16_t start_pos;
Peter Kastingdce40cf2015-08-24 14:52:23 -0700172 size_t diff;
niklase@google.com470e71d2011-07-07 08:21:25 +0000173#endif
174
pbos@webrtc.orgeb544462014-12-17 15:23:29 +0000175} IlbcEncoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000176
177/* type definition decoder instance */
pbos@webrtc.orgeb544462014-12-17 15:23:29 +0000178typedef struct IlbcDecoder_ {
niklase@google.com470e71d2011-07-07 08:21:25 +0000179 /* flag for frame size mode */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000180 int16_t mode;
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
182 /* basic parameters for different frame sizes */
Peter Kastingdce40cf2015-08-24 14:52:23 -0700183 size_t blockl;
184 size_t nsub;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000185 int16_t nasub;
Peter Kastingdce40cf2015-08-24 14:52:23 -0700186 size_t no_of_bytes, no_of_words;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000187 int16_t lpc_n;
Peter Kastingdce40cf2015-08-24 14:52:23 -0700188 size_t state_short_len;
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
190 /* synthesis filter state */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000191 int16_t syntMem[LPC_FILTERORDER];
niklase@google.com470e71d2011-07-07 08:21:25 +0000192
193 /* old LSF for interpolation */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000194 int16_t lsfdeqold[LPC_FILTERORDER];
niklase@google.com470e71d2011-07-07 08:21:25 +0000195
196 /* pitch lag estimated in enhancer and used in PLC */
Peter Kastingdce40cf2015-08-24 14:52:23 -0700197 size_t last_lag;
niklase@google.com470e71d2011-07-07 08:21:25 +0000198
199 /* PLC state information */
200 int consPLICount, prev_enh_pl;
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000201 int16_t perSquare;
niklase@google.com470e71d2011-07-07 08:21:25 +0000202
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000203 int16_t prevScale, prevPLI;
Peter Kastingdce40cf2015-08-24 14:52:23 -0700204 size_t prevLag;
Yves Gerey665174f2018-06-19 15:03:05 +0200205 int16_t prevLpc[LPC_FILTERORDER + 1];
206 int16_t prevResidual[NSUB_MAX * SUBL];
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000207 int16_t seed;
niklase@google.com470e71d2011-07-07 08:21:25 +0000208
209 /* previous synthesis filter parameters */
210
Yves Gerey665174f2018-06-19 15:03:05 +0200211 int16_t old_syntdenum[(LPC_FILTERORDER + 1) * NSUB_MAX];
niklase@google.com470e71d2011-07-07 08:21:25 +0000212
213 /* state of output HP filter */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000214 int16_t hpimemx[2];
215 int16_t hpimemy[4];
niklase@google.com470e71d2011-07-07 08:21:25 +0000216
217 /* enhancer state information */
218 int use_enhancer;
Yves Gerey665174f2018-06-19 15:03:05 +0200219 int16_t enh_buf[ENH_BUFL + ENH_BUFL_FILTEROVERHEAD];
Peter Kasting1380e262015-08-28 17:31:03 -0700220 size_t enh_period[ENH_NBLOCKS_TOT];
niklase@google.com470e71d2011-07-07 08:21:25 +0000221
pbos@webrtc.orgeb544462014-12-17 15:23:29 +0000222} IlbcDecoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000223
224#endif