libilbc  0.0.1
ilbc/ilbc.h
1 /*
2  * iLBC - a library for the iLBC codec
3  *
4  * ilbc.h - The iLBC low bit rate speech codec.
5  *
6  * Adapted by Steve Underwood <steveu@coppice.org> from the reference
7  * iLBC code supplied in RFC3951.
8  *
9  * Copyright (C) The Internet Society (2004).
10  * All Rights Reserved.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * $Id: ilbc.h,v 1.2 2008/10/02 12:00:56 steveu Exp $
22  */
23 
24 #if !defined(_ILBC_ILBC_H_)
25 #define _ILBC_ILBC_H_
26 
27 #define ILBC_BLOCK_LEN_20MS 160
28 #define ILBC_BLOCK_LEN_30MS 240
29 #define ILBC_BLOCK_LEN_MAX 240
30 
31 #define ILBC_NO_OF_BYTES_20MS 38
32 #define ILBC_NO_OF_BYTES_30MS 50
33 #define ILBC_NO_OF_BYTES_MAX 50
34 
35 #define ILBC_NUM_SUB_MAX 6
36 
37 #define SUBL 40
38 
39 #define ENH_BLOCKL 80 /* block length */
40 #define ENH_NBLOCKS_TOT 8 /* ENH_NBLOCKS + ENH_NBLOCKS_EXTRA */
41 #define ENH_BUFL (ENH_NBLOCKS_TOT*ENH_BLOCKL)
42 
43 #define ILBC_LPC_FILTERORDER 10
44 #define LPC_LOOKBACK 60
45 
46 #define CB_NSTAGES 3
47 
48 #define STATE_BITS 3
49 #define BYTE_LEN 8
50 #define ILBC_ULP_CLASSES 3
51 
52 typedef struct
53 {
54  int lsf_bits[6][ILBC_ULP_CLASSES + 2];
55  int start_bits[ILBC_ULP_CLASSES + 2];
56  int startfirst_bits[ILBC_ULP_CLASSES + 2];
57  int scale_bits[ILBC_ULP_CLASSES + 2];
58  int state_bits[ILBC_ULP_CLASSES + 2];
59  int extra_cb_index[CB_NSTAGES][ILBC_ULP_CLASSES + 2];
60  int extra_cb_gain[CB_NSTAGES][ILBC_ULP_CLASSES + 2];
61  int cb_index[ILBC_NUM_SUB_MAX][CB_NSTAGES][ILBC_ULP_CLASSES + 2];
62  int cb_gain[ILBC_NUM_SUB_MAX][CB_NSTAGES][ILBC_ULP_CLASSES + 2];
64 
65 /* Type definition encoder instance */
66 typedef struct
67 {
68  /* flag for frame size mode */
69  int mode;
70 
71  /* basic parameters for different frame sizes */
72  int blockl;
73  int nsub;
74  int nasub;
75  int no_of_bytes;
76  int lpc_n;
77  int state_short_len;
78  const ilbc_ulp_inst_t *ULP_inst;
79 
80  /* analysis filter state */
81  float anaMem[ILBC_LPC_FILTERORDER];
82 
83  /* old lsf parameters for interpolation */
84  float lsfold[ILBC_LPC_FILTERORDER];
85  float lsfdeqold[ILBC_LPC_FILTERORDER];
86 
87  /* signal buffer for LP analysis */
88  float lpc_buffer[LPC_LOOKBACK + ILBC_BLOCK_LEN_MAX];
89 
90  /* state of input HP filter */
91  float hpimem[4];
93 
94 /* Type definition decoder instance */
95 typedef struct
96 {
97  /* Flag for frame size mode */
98  int mode;
99 
100  /* Basic parameters for different frame sizes */
101  int blockl;
102  int nsub;
103  int nasub;
104  int no_of_bytes;
105  int lpc_n;
106  int state_short_len;
107  const ilbc_ulp_inst_t *ULP_inst;
108 
109  /* Synthesis filter state */
110  float syntMem[ILBC_LPC_FILTERORDER];
111 
112  /* Old LSF for interpolation */
113  float lsfdeqold[ILBC_LPC_FILTERORDER];
114 
115  /* Pitch lag estimated in enhancer and used in PLC */
116  int last_lag;
117 
118  /* PLC state information */
119  int prevLag, consPLICount, prevPLI, prev_enh_pl;
120  float prevLpc[ILBC_LPC_FILTERORDER + 1];
121  float prevResidual[ILBC_NUM_SUB_MAX*SUBL];
122  float per;
123  unsigned long seed;
124 
125  /* Previous synthesis filter parameters */
126  float old_syntdenum[(ILBC_LPC_FILTERORDER + 1)*ILBC_NUM_SUB_MAX];
127 
128  /* State of output HP filter */
129  float hpomem[4];
130 
131  /* Enhancer state information */
132  int use_enhancer;
133  float enh_buf[ENH_BUFL];
134  float enh_period[ENH_NBLOCKS_TOT];
136 
137 #if defined(__cplusplus)
138 extern "C"
139 {
140 #endif
141 
142 /*! Initialise an iLBC encode context.
143  \param s The iLBC encode context.
144  \param mode The frame size.
145  \return A pointer to the iLBC encode context, or NULL for error. */
147  int mode);
148 
149 int ilbc_encode_release(ilbc_encode_state_t *s);
150 
151 /*! Encode a buffer of linear PCM data to iLBC
152  \param s The iLBC encode context.
153  \param bytes The iLBC data produced.
154  \param amp The audio sample buffer.
155  \param len The number of samples in the buffer.
156  \return The number of bytes of iLBC data produced. */
158  uint8_t bytes[],
159  const int16_t amp[],
160  int len);
161 
162 /*! Initialise an iLBC decode context.
163  \param s The iLBC decode context.
164  \param mode The frame size.
165  \param use_enhancer TRUE to use the audio enhancer option.
166  \return A pointer to the iLBC decode context, or NULL for error. */
168  int mode,
169  int use_enhancer);
170 
171 int ilbc_decode_release(ilbc_decode_state_t *s);
172 
173 /*! Decode a buffer of iLBC data to linear PCM.
174  \param s The iLBC deocde context.
175  \param amp The audio sample buffer.
176  \param bytes The excoded data.
177  \param len The length of the encoded data, in bytes.
178  \return The number of samples returned. */
180  int16_t amp[],
181  const uint8_t bytes[],
182  int len);
183 
184 /*! Produce linear PCM data to fill in where received iLBC data is missing.
185  \param s The iLBC context.
186  \param amp The audio sample buffer.
187  \param len
188  \return The number of samples returned. */
190  int16_t amp[],
191  int len);
192 
193 #if defined(__cplusplus)
194 }
195 #endif
196 
197 #endif
198 /*- End of file ------------------------------------------------------------*/
Definition: ilbc/ilbc.h:66
int ilbc_decode(ilbc_decode_state_t *s, int16_t amp[], const uint8_t bytes[], int len)
Definition: iLBC_decode.c:581
Definition: ilbc/ilbc.h:95
ilbc_encode_state_t * ilbc_encode_init(ilbc_encode_state_t *s, int mode)
Definition: iLBC_encode.c:48
int ilbc_fillin(ilbc_decode_state_t *s, int16_t amp[], int len)
Definition: iLBC_decode.c:611
Definition: ilbc/ilbc.h:52
int ilbc_encode(ilbc_encode_state_t *s, uint8_t bytes[], const int16_t amp[], int len)
Definition: iLBC_encode.c:511
ilbc_decode_state_t * ilbc_decode_init(ilbc_decode_state_t *s, int mode, int use_enhancer)
Definition: iLBC_decode.c:46