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
22#if !defined(_ILBC_ILBC_H_)
23#define _ILBC_ILBC_H_
24
25#if defined(_M_IX86) || defined(_M_X64)
26#if defined(LIBILBC_EXPORTS)
27#define ILBC_DECLARE(type) __declspec(dllexport) type __stdcall
28#define ILBC_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl
29#define ILBC_DECLARE_DATA __declspec(dllexport)
30#else
31#define ILBC_DECLARE(type) __declspec(dllimport) type __stdcall
32#define ILBC_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl
33#define ILBC_DECLARE_DATA __declspec(dllimport)
34#endif
35#elif defined(ILBC_USE_EXPORT_CAPABILITY) && (defined(__GNUC__) || defined(__SUNCC__))
36#define ILBC_DECLARE(type) __attribute__((visibility("default"))) type
37#define ILBC_DECLARE_NONSTD(type) __attribute__((visibility("default"))) type
38#define ILBC_DECLARE_DATA __attribute__((visibility("default")))
39#else
40#define ILBC_DECLARE(type) /**/ type
41#define ILBC_DECLARE_NONSTD(type) /**/ type
42#define ILBC_DECLARE_DATA /**/
43#endif
44
45#define ILBC_BLOCK_LEN_20MS 160
46#define ILBC_BLOCK_LEN_30MS 240
47#define ILBC_BLOCK_LEN_MAX 240
48
49#define ILBC_NO_OF_BYTES_20MS 38
50#define ILBC_NO_OF_BYTES_30MS 50
51#define ILBC_NO_OF_BYTES_MAX 50
52
53#define ILBC_NUM_SUB_MAX 6
54
55#define SUBL 40
56
57#define ENH_BLOCKL 80 /* block length */
58#define ENH_NBLOCKS_TOT 8 /* ENH_NBLOCKS + ENH_NBLOCKS_EXTRA */
59#define ENH_BUFL (ENH_NBLOCKS_TOT*ENH_BLOCKL)
60
61#define ILBC_LPC_FILTERORDER 10
62#define LPC_LOOKBACK 60
63
64#define CB_NSTAGES 3
65
66#define STATE_BITS 3
67#define BYTE_LEN 8
68#define ILBC_ULP_CLASSES 3
69
70typedef struct
71{
72 int lsf_bits[6][ILBC_ULP_CLASSES + 2];
73 int start_bits[ILBC_ULP_CLASSES + 2];
74 int startfirst_bits[ILBC_ULP_CLASSES + 2];
75 int scale_bits[ILBC_ULP_CLASSES + 2];
76 int state_bits[ILBC_ULP_CLASSES + 2];
77 int extra_cb_index[CB_NSTAGES][ILBC_ULP_CLASSES + 2];
78 int extra_cb_gain[CB_NSTAGES][ILBC_ULP_CLASSES + 2];
79 int cb_index[ILBC_NUM_SUB_MAX][CB_NSTAGES][ILBC_ULP_CLASSES + 2];
80 int cb_gain[ILBC_NUM_SUB_MAX][CB_NSTAGES][ILBC_ULP_CLASSES + 2];
82
83/* Type definition encoder instance */
84typedef struct
85{
86 /* flag for frame size mode */
87 int mode;
88
89 /* basic parameters for different frame sizes */
90 int blockl;
91 int nsub;
92 int nasub;
93 int no_of_bytes;
94 int lpc_n;
95 int state_short_len;
96 const ilbc_ulp_inst_t *ULP_inst;
97
98 /* analysis filter state */
99 float anaMem[ILBC_LPC_FILTERORDER];
100
101 /* old lsf parameters for interpolation */
102 float lsfold[ILBC_LPC_FILTERORDER];
103 float lsfdeqold[ILBC_LPC_FILTERORDER];
104
105 /* signal buffer for LP analysis */
106 float lpc_buffer[LPC_LOOKBACK + ILBC_BLOCK_LEN_MAX];
107
108 /* state of input HP filter */
109 float hpimem[4];
111
112/* Type definition decoder instance */
113typedef struct
114{
115 /* Flag for frame size mode */
116 int mode;
117
118 /* Basic parameters for different frame sizes */
119 int blockl;
120 int nsub;
121 int nasub;
122 int no_of_bytes;
123 int lpc_n;
124 int state_short_len;
125 const ilbc_ulp_inst_t *ULP_inst;
126
127 /* Synthesis filter state */
128 float syntMem[ILBC_LPC_FILTERORDER];
129
130 /* Old LSF for interpolation */
131 float lsfdeqold[ILBC_LPC_FILTERORDER];
132
133 /* Pitch lag estimated in enhancer and used in PLC */
134 int last_lag;
135
136 /* PLC state information */
137 int prevLag, consPLICount, prevPLI, prev_enh_pl;
138 float prevLpc[ILBC_LPC_FILTERORDER + 1];
139 float prevResidual[ILBC_NUM_SUB_MAX*SUBL];
140 float per;
141 unsigned long seed;
142
143 /* Previous synthesis filter parameters */
144 float old_syntdenum[(ILBC_LPC_FILTERORDER + 1)*ILBC_NUM_SUB_MAX];
145
146 /* State of output HP filter */
147 float hpomem[4];
148
149 /* Enhancer state information */
150 int use_enhancer;
151 float enh_buf[ENH_BUFL];
152 float enh_period[ENH_NBLOCKS_TOT];
154
155#if defined(__cplusplus)
156extern "C"
157{
158#endif
159
160/*! Encode a buffer of linear PCM data to iLBC
161 \param s The iLBC encode context.
162 \param bytes The iLBC data produced.
163 \param amp The audio sample buffer.
164 \param len The number of samples in the buffer.
165 \return The number of bytes of iLBC data produced. */
166ILBC_DECLARE(int) ilbc_encode(ilbc_encode_state_t *s,
167 uint8_t bytes[],
168 const int16_t amp[],
169 int len);
170
171/*! Initialise an iLBC encode context.
172 \param s The iLBC encode context.
173 \param mode The frame size.
174 \return A pointer to the iLBC encode context, or NULL for error. */
175ILBC_DECLARE(ilbc_encode_state_t *) ilbc_encode_init(ilbc_encode_state_t *s,
176 int mode);
177
178ILBC_DECLARE(int) ilbc_encode_release(ilbc_encode_state_t *s);
179
180/*! Decode a buffer of iLBC data to linear PCM.
181 \param s The iLBC deocde context.
182 \param amp The audio sample buffer.
183 \param bytes The excoded data.
184 \param len The length of the encoded data, in bytes.
185 \return The number of samples returned. */
186ILBC_DECLARE(int) ilbc_decode(ilbc_decode_state_t *s,
187 int16_t amp[],
188 const uint8_t bytes[],
189 int len);
190
191/*! Produce linear PCM data to fill in where received iLBC data is missing.
192 \param s The iLBC context.
193 \param amp The audio sample buffer.
194 \param len
195 \return The number of samples returned. */
196ILBC_DECLARE(int) ilbc_fillin(ilbc_decode_state_t *s,
197 int16_t amp[],
198 int len);
199
200/*! Initialise an iLBC decode context.
201 \param s The iLBC decode context.
202 \param mode The frame size.
203 \param use_enhancer TRUE to use the audio enhancer option.
204 \return A pointer to the iLBC decode context, or NULL for error. */
205ILBC_DECLARE(ilbc_decode_state_t *) ilbc_decode_init(ilbc_decode_state_t *s,
206 int mode,
207 int use_enhancer);
208
209ILBC_DECLARE(int) ilbc_decode_release(ilbc_decode_state_t *s);
210
211#if defined(__cplusplus)
212}
213#endif
214
215#endif
216/*- End of file ------------------------------------------------------------*/
Definition ilbc/ilbc.h:114
Definition ilbc/ilbc.h:85
Definition ilbc/ilbc.h:71