2 * iaxclient: a cross-platform IAX softphone library
5 * Copyright (C) 2003-2006, Horizon Wimba, Inc.
6 * Copyright (C) 2007, Wimba, Inc.
9 * Steve Kann <stevek@stevek.com>
11 * This program is free software, distributed under the terms of
12 * the GNU Lesser (Library) General Public License.
15 #include "codec_ilbc.h"
16 #include "iaxclient_lib.h"
17 #include "iLBC/iLBC_encode.h"
18 #include "iLBC/iLBC_decode.h"
21 static void destroy ( struct iaxc_audio_codec *c) {
28 static int decode ( struct iaxc_audio_codec *c,
29 int *inlen, char *in, int *outlen, short *out ) {
35 //fprintf(stderr, "ILBC Interpolate\n");
36 iLBC_decode(fbuf, NULL, c->decstate, 0);
44 /* need to decode minimum of 33 bytes to 160 byte output */
45 if( (*inlen < 50) || (*outlen < 240) ) {
46 fprintf(stderr, "codec_ilbc: inlen = %d outlen= %d\n",*inlen,*outlen);
50 while( (*inlen >= 50) && (*outlen >= 240) ) {
51 iLBC_decode(fbuf, in, c->decstate, 1);
64 static int encode ( struct iaxc_audio_codec *c,
65 int *inlen, short *in, int *outlen, char *out ) {
70 while( (*inlen >= 240) && (*outlen >= 50) ) {
75 iLBC_encode(out,fbuf, c->encstate);
86 struct iaxc_audio_codec *codec_audio_ilbc_new() {
87 struct iaxc_audio_codec *c = calloc(sizeof(struct iaxc_audio_codec),1);
92 strcpy(c->name,"iLBC");
93 c->format = IAXC_FORMAT_ILBC;
98 c->minimum_frame_size = 240;
100 c->encstate = calloc(sizeof(iLBC_Enc_Inst_t),1);
101 c->decstate = calloc(sizeof(iLBC_Dec_Inst_t),1);
103 /* leaks a bit on no-memory */
104 if(!(c->encstate && c->decstate))
107 /* the 30 parameters are used for the latest iLBC sources, in
108 * http://www.ietf.org/internet-drafts/draft-ietf-avt-ilbc-codec-05.txt
109 * as used in asterisk-CVS as of 14 Oct 2004 */
110 initEncode(c->encstate, 30);
111 initDecode(c->decstate, 30, 1); /* use enhancer */