aboutsummaryrefslogtreecommitdiffstats
path: root/src/native
diff options
context:
space:
mode:
authorLyubomir Marinov <lyubomir.marinov@jitsi.org>2010-10-21 01:00:07 +0000
committerLyubomir Marinov <lyubomir.marinov@jitsi.org>2010-10-21 01:00:07 +0000
commit858330c2a5dbad836600ed0d6bbd6f5430a4ac87 (patch)
treecec47a8970deedf248a2181c1bd2fad71e7ccfe3 /src/native
parentf34d04eddb5a6e68f9c223af9a0963dbcfc9b5c1 (diff)
downloadjitsi-858330c2a5dbad836600ed0d6bbd6f5430a4ac87.zip
jitsi-858330c2a5dbad836600ed0d6bbd6f5430a4ac87.tar.gz
jitsi-858330c2a5dbad836600ed0d6bbd6f5430a4ac87.tar.bz2
Adds support for the G.722 audio codec.
Diffstat (limited to 'src/native')
-rw-r--r--src/native/g722/Makefile21
-rw-r--r--src/native/g722/g722_decoder.c714
-rw-r--r--src/native/g722/g722_decoder.h17
-rw-r--r--src/native/g722/g722_encoder.c854
-rw-r--r--src/native/g722/g722_encoder.h17
-rw-r--r--src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder.c46
-rw-r--r--src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder.h37
-rw-r--r--src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder.c46
-rw-r--r--src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder.h37
9 files changed, 1789 insertions, 0 deletions
diff --git a/src/native/g722/Makefile b/src/native/g722/Makefile
new file mode 100644
index 0000000..b7426b3
--- /dev/null
+++ b/src/native/g722/Makefile
@@ -0,0 +1,21 @@
+JAVA_HOME?=/usr/lib/jvm/java-6-sun
+
+TARGET=../../../lib/native/linux-64/libjg722.so
+
+CC=gcc
+CPPFLAGS=-DJNI_IMPLEMENTATION \
+ -Wall -Wreturn-type \
+ -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
+LDFLAGS=-shared -fPIC
+LIBS=
+
+$(TARGET): \
+ g722_decoder.c \
+ g722_encoder.c \
+ net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder.c \
+ net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder.c \
+ g722_decoder.h \
+ g722_encoder.h \
+ net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder.h \
+ net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder.h
+ $(CC) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ $(LIBS)
diff --git a/src/native/g722/g722_decoder.c b/src/native/g722/g722_decoder.c
new file mode 100644
index 0000000..1ee5a61
--- /dev/null
+++ b/src/native/g722/g722_decoder.c
@@ -0,0 +1,714 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+/**********************************************/
+/* */
+/***** Copyright (c) CMU 1993 *****/
+/* Computer Science, Speech Group */
+/* Chengxiang Lu and Alex Hauptmann */
+/* */
+/* This program performs the decoder for the */
+/* 64 kb/s codec. It reads ADPCM values and */
+/* writes PCM values to standard output */
+/* */
+/* With speed of 0.4xreal-time for coder */
+/* and 0.3xreal-time for decoder on NeXT. */
+/* */
+/* decoder */
+/* 64kbit/s============>16kHzSamplingx16bit */
+/* */
+/**********************************************/
+
+#include "g722_decoder.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int block4h(int);
+static int block4l(int);
+
+ /******************************** block3l *********************/
+ static int wl[8] = {-60, -30, 58, 172, 334, 538, 1198, 3042 } ;
+ static int rl42[16] = {0, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 0 } ;
+ static int ilb[32] = {2048, 2093, 2139, 2186, 2233, 2282, 2332,
+ 2383, 2435, 2489, 2543, 2599, 2656, 2714,
+ 2774, 2834, 2896, 2960, 3025, 3091, 3158,
+ 3228, 3298, 3371, 3444, 3520, 3597, 3676,
+ 3756, 3838, 3922, 4008 } ;
+ /************************************** block3h ***************/
+ static int wh[3] = {0, -214, 798} ;
+ static int rh2[4] = {2, 1, 2, 1} ;
+ /******************* block5l ***********************************/
+ static int qm6[64] =
+ {-136, -136, -136, -136,
+ -24808, -21904, -19008, -16704,
+ -14984, -13512, -12280, -11192,
+ -10232, -9360, -8576, -7856,
+ -7192, -6576, -6000, -5456,
+ -4944, -4464, -4008, -3576,
+ -3168, -2776, -2400, -2032,
+ -1688, -1360, -1040, -728,
+ 24808, 21904, 19008, 16704,
+ 14984, 13512, 12280, 11192,
+ 10232, 9360, 8576, 7856,
+ 7192, 6576, 6000, 5456,
+ 4944, 4464, 4008, 3576,
+ 3168, 2776, 2400, 2032,
+ 1688, 1360, 1040, 728,
+ 432, 136, -432, -136 } ;
+ /********************** block 2h *******************************/
+ static int qm2[4] = {-7408, -1616, 7408, 1616} ;
+ /********************** block 2l *******************************/
+ static int qm4[16] =
+ {0, -20456, -12896, -8968,
+ -6288, -4240, -2584, -1200,
+ 20456, 12896, 8968, 6288,
+ 4240, 2584, 1200, 0 } ;
+
+typedef struct
+{
+ int slow;
+ int detlow;
+ int shigh;
+ int dethigh;
+ int xd[12];
+ int xs[12];
+ int k; /* counter */
+ int nbl;
+ int nbh;
+}
+g722_decoder_t;
+
+static int block4h (int d)
+{
+ static int sh = 0 ;
+ register int wd1, wd2, wd3;
+ static int sph = 0 ;
+ static int szh = 0 ;
+
+ static int rh0=0, rh1=0, rh2=0 ;
+ static int ah1=0, ah2=0 ;
+ static int ph0=0, ph1=0, ph2=0 ;
+
+ static int dh [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+ static int bh [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+ static int bph [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+ static int sg0=0, sg1=0, sg2=0;
+ static int sg [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+
+ register int *dhp, *dhp_1, *bhp, *bphp, *sgp;
+
+ dh[0] = d;
+ /*************************************** BLOCK 4H, RECONS ***********/
+
+
+
+ rh0 = sh + d ;
+ /*
+ if (rh0 > 32767) rh0 = 32767;
+ if (rh0 < -32768) rh0 = -32768;
+ */
+
+ /*************************************** BLOCK 4H, PARREC ***********/
+
+
+ ph0 = d + szh ;
+ /*
+ if (ph0 > 32767) ph0 = 32767;
+ if (ph0 < -32768) ph0 = -32768;
+ */
+
+
+ /*****************************BLOCK 4H, UPPOL2*************************/
+
+
+ sg0 = ph0 >> 15 ;
+ sg1 = ph1 >> 15 ;
+ sg2 = ph2 >> 15 ;
+
+ wd1 = ah1 << 2;
+
+ if (wd1 > 32767)
+ wd1 = 32767;
+ else if (wd1 < -32768)
+ wd1 = -32768;
+
+ wd2= ( sg0 == sg1 )? - wd1 : wd1 ;
+ if (wd2 > 32767) wd2 = 32767;
+
+
+ wd2 = wd2 >> 7 ;
+
+
+ wd3= ( sg0 == sg2 )? 128 : - 128 ;
+
+
+ wd2 = wd2 + wd3 ;
+ wd3 = (ah2 * 127) >> 7 ;
+
+
+ ah2 = wd2 + wd3 ;
+ if ( ah2 > 12288 )
+ ah2 = 12288 ;
+ else if ( ah2 < -12288 )
+ ah2 = -12288 ;
+ /************************************* BLOCK 4H, UPPOL1 ***************/
+
+
+ sg0 = ph0 >> 15 ;
+ sg1 = ph1 >> 15 ;
+
+
+ wd1= ( sg0 == sg1 )? 192 : - 192 ;
+
+
+ wd2 = (ah1 * 255) >> 8 ;
+
+
+ ah1 = wd1 + wd2 ;
+ /*
+ if (ah2 > 32767) ah2 = 32767;
+ if (ah2 < -32768) ah2 = -32768;
+ */
+
+ wd3 = (15360 - ah2) ;
+ /*
+ if (wd3 > 32767) wd3 = 32767;
+ if (wd3 < -32768) wd3 = -32768;
+ */
+ if ( ah1 > wd3)
+ ah1 = wd3 ;
+ else if ( ah1 < -wd3)
+ ah1 = -wd3 ;
+
+
+ /*************************************** BLOCK 4H, UPZERO ************/
+
+
+ wd1= ( d == 0 )? 0 : 128 ;
+
+
+ sg0 = d >> 15 ;
+ sgp = sg, dhp = dh, bhp = bh, bphp = bph;
+
+ *++sgp = *++dhp >> 15 ;
+ wd2= ( *sgp == sg0 )? wd1 : - wd1 ;
+ wd3 = (*++bhp * 255) >> 8 ;
+ *++bphp = wd2 + wd3 ;
+ *++sgp = *++dhp >> 15 ;
+ wd2= ( *sgp == sg0 )? wd1 : - wd1 ;
+ wd3 = (*++bhp * 255) >> 8 ;
+ *++bphp = wd2 + wd3 ;
+ *++sgp = *++dhp >> 15 ;
+ wd2= ( *sgp == sg0 )? wd1 : - wd1 ;
+ wd3 = (*++bhp * 255) >> 8 ;
+ *++bphp = wd2 + wd3 ;
+ *++sgp = *++dhp >> 15 ;
+ wd2= ( *sgp == sg0 )? wd1 : - wd1 ;
+ wd3 = (*++bhp * 255) >> 8 ;
+ *++bphp = wd2 + wd3 ;
+ *++sgp = *++dhp >> 15 ;
+ wd2= ( *sgp == sg0 )? wd1 : - wd1 ;
+ wd3 = (*++bhp * 255) >> 8 ;
+ *++bphp = wd2 + wd3 ;
+ *++sgp = *++dhp >> 15 ;
+ wd2= ( *sgp == sg0 )? wd1 : - wd1 ;
+ wd3 = (*++bhp * 255) >> 8 ;
+ *++bphp = wd2 + wd3 ;
+ /********************************* BLOCK 4H, DELAYA ******************/
+ dhp_1=dhp-1,bhp=bh, bphp=bph;
+ *dhp--=*dhp_1--;
+ *++bhp=*++bphp;
+ *dhp--=*dhp_1--;
+ *++bhp=*++bphp;
+ *dhp--=*dhp_1--;
+ *++bhp=*++bphp;
+ *dhp--=*dhp_1--;
+ *++bhp=*++bphp;
+ *dhp--=*dhp_1--;
+ *++bhp=*++bphp;
+ *dhp--=*dhp_1--;
+ *++bhp=*++bphp;
+ rh2=rh1;
+ rh1=rh0;
+ ph2=ph1;
+ ph1=ph0;
+ /********************************* BLOCK 4H, FILTEP ******************/
+
+ wd1 = ( ah1 * rh1 ) >> 14 ;
+
+ wd2 = ( ah2 * rh2 ) >> 14 ;
+
+ sph = wd1 + wd2 ;
+ /*
+ if (sph > 32767) sph = 32767;
+ if (sph < -32768) sph = -32768;
+ */
+
+ /*************************************** BLOCK 4H, FILTEZ ***********/
+
+
+ dhp = dh, bhp = bh;
+ szh = ((*++bhp) * *++dhp )>>14;
+ /*
+ if (szh > 32767) szh = 32767;
+ else if (szh < -32768) szh = -32768;
+ */
+ szh += ((*++bhp) * *++dhp )>>14;
+ /*
+ if (szh > 32767) szh = 32767;
+ else if (szh < -32768) szh = -32768;
+ */
+ szh += ((*++bhp) * *++dhp )>>14;
+ /*
+ if (szh > 32767) szh = 32767;
+ else if (szh < -32768) szh = -32768;
+ */
+ szh += ((*++bhp) * *++dhp )>>14;
+ /*
+ if (szh > 32767) szh = 32767;
+ else if (szh < -32768) szh = -32768;
+ */
+ szh += ((*++bhp) * *++dhp )>>14;
+ /*
+ if (szh > 32767) szh = 32767;
+ else if (szh < -32768) szh = -32768;
+ */
+ szh += ((*++bhp) * *++dhp )>>14;
+ /*
+ if (szh > 32767) szh = 32767;
+ else if (szh < -32768) szh = -32768;
+ */
+
+ /*********************************BLOCK 4H, PREDIC *******************/
+
+
+ sh = sph + szh ;
+ /*
+ if (sh > 32767) sh = 32767;
+ if (sh < -32768) sh = -32768;
+ */
+
+ return (sh) ;
+}
+
+/**************************** BLOCK 4L *******************************/
+static int block4l (int dl)
+{
+ static int sl = 0 ;
+ register int wd1, wd2, wd3;
+ static int spl = 0 ;
+ static int szl = 0 ;
+
+ static int rlt0=0, rlt1=0, rlt2=0;
+ static int al1=0, al2=0;
+ static int plt0=0, plt1=0, plt2=0;
+
+ static int dlt [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+ static int bl [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+ static int bpl [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+ static int sg0=0, sg1=0, sg2=0;
+ static int sg [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+
+ register int *sgp, *dltp, *dltp_1, *blp, *bplp;
+
+ dlt[0] = dl;
+ /*************************************** BLOCK 4L, RECONS ***********/
+
+ rlt0 = sl + dl ;
+ /*
+ if (rlt0 > 32767) rlt0 = 32767;
+ if (rlt0 < -32768) rlt0 = -32768;
+ */
+ /*************************************** BLOCK 4L, PARREC ***********/
+
+ plt0 = dl + szl ;
+ /*
+ if (plt0 > 32767) plt0 = 32767;
+ if (plt0 < -32768) plt0 = -32768;
+ */
+
+ /*****************************BLOCK 4L, UPPOL2*************************/
+
+ sg0 = plt0 >> 15 ;
+ sg1 = plt1 >> 15 ;
+ sg2 = plt2 >> 15 ;
+
+ wd1 = al1 << 2;
+ if (wd1 > 32767)
+ wd1 = 32767;
+ else if (wd1 < -32768)
+ wd1 = -32768;
+
+ wd2= ( sg0 == sg1 )? - wd1 : wd1 ;
+ /*
+ if (wd2 > 32767) wd2 = 32767;
+ */
+ wd2 = wd2 >> 7 ;
+
+ wd3= ( sg0 == sg2 )? 128 : - 128 ;
+
+ wd2 = wd2 + wd3 ;
+ wd3 = (al2 * 127) >> 7 ;
+
+ al2 = wd2 + wd3 ;
+ if ( al2 > 12288 )
+ al2 = 12288 ;
+ else if ( al2 < -12288 )
+ al2 = -12288 ;
+ /************************************* BLOCK 4L, UPPOL1 ***************/
+
+ sg0 = plt0 >> 15 ;
+ sg1 = plt1 >> 15 ;
+
+ wd1= ( sg0 == sg1 )? 192 : - 192 ;
+
+ wd2 = (al1 * 255) >> 8 ;
+
+ al1 = wd1 + wd2 ;
+ /*
+ if (al1 > 32767) al1 = 32767;
+ if (al1 < -32768) al1 = -32768;
+ */
+
+ wd3 = (15360 - al2) ;
+ /*
+ if (wd3 > 32767) wd3 = 32767;
+ if (wd3 < -32768) wd3 = -32768;
+ */
+ if ( al1 > wd3)
+ al1 = wd3 ;
+ else if ( al1 < -wd3)
+ al1 = -wd3 ;
+
+ /*************************************** BLOCK 4L, UPZERO ************/
+
+ wd1= ( dl == 0 )? 0 : 128 ;
+
+ sg0 = dl >> 15 ;
+
+ sgp=sg, dltp=dlt, blp=bl, bplp=bpl;
+ *++sgp = *++dltp >> 15 ;
+ wd2= ( *sgp == sg0 )? wd1 : - wd1 ;
+ wd3 = (*++blp * 255) >> 8 ;
+ *++bplp = wd2 + wd3 ;
+/*
+ if (*bplp > 32767) *bplp = 32767;
+ else if (*bplp < -32768) *bplp = -32768;
+*/
+ *++sgp = *++dltp >> 15 ;
+ wd2= ( *sgp == sg0 )? wd1 : - wd1 ;
+ wd3 = (*++blp * 255) >> 8 ;
+ *++bplp = wd2 + wd3 ;
+/*
+ if (*bplp > 32767) *bplp = 32767;
+ else if (*bplp < -32768) *bplp = -32768;
+*/
+ *++sgp = *++dltp >> 15 ;
+ wd2= ( *sgp == sg0 )? wd1 : - wd1 ;
+ wd3 = (*++blp * 255) >> 8 ;
+ *++bplp = wd2 + wd3 ;
+/*
+ if (*bplp > 32767) *bplp = 32767;
+ else if (*bplp < -32768) *bplp = -32768;
+*/
+ *++sgp = *++dltp >> 15 ;
+ wd2= ( *sgp == sg0 )? wd1 : - wd1 ;
+ wd3 = (*++blp * 255) >> 8 ;
+ *++bplp = wd2 + wd3 ;
+/*
+ if (*bplp > 32767) *bplp = 32767;
+ else if (*bplp < -32768) *bplp = -32768;
+*/
+ *++sgp = *++dltp >> 15 ;
+ wd2= ( *sgp == sg0 )? wd1 : - wd1 ;
+ wd3 = (*++blp * 255) >> 8 ;
+ *++bplp = wd2 + wd3 ;
+/*
+ if (*bplp > 32767) *bplp = 32767;
+ else if (*bplp < -32768) *bplp = -32768;
+*/
+ *++sgp = *++dltp >> 15 ;
+ wd2= ( *sgp == sg0 )? wd1 : - wd1 ;
+ wd3 = (*++blp * 255) >> 8 ;
+ *++bplp = wd2 + wd3 ;
+/*
+ if (*bplp > 32767) *bplp = 32767;
+ else if (*bplp < -32768) *bplp = -32768;
+*/
+ /********************************* BLOCK 4L, DELAYA ******************/
+
+ dltp=dlt+6, dltp_1=dltp-1, blp=bl, bplp=bpl;
+ *dltp-- = *dltp_1--;
+ *++blp = *++bplp;
+ *dltp-- = *dltp_1--;
+ *++blp = *++bplp;
+ *dltp-- = *dltp_1--;
+ *++blp = *++bplp;
+ *dltp-- = *dltp_1--;
+ *++blp = *++bplp;
+ *dltp-- = *dltp_1--;
+ *++blp = *++bplp;
+ *dltp-- = *dltp_1--;
+ *++blp = *++bplp;
+
+ rlt2=rlt1;
+ rlt1=rlt0;
+ plt2=plt1;
+ plt1=plt0;
+
+ /********************************* BLOCK 4L, FILTEP ******************/
+
+ wd1 = ( al1 * rlt1 ) >> 14 ;
+
+ wd2 = ( al2 * rlt2 ) >> 14 ;
+
+ spl = wd1 + wd2 ;
+ /*
+ if (spl > 32767) spl = 32767;
+ if (spl < -32768) spl = -32768;
+ */
+
+ /*************************************** BLOCK 4L, FILTEZ ***********/
+
+
+ dltp = dlt, blp=bl;
+ szl = (*++blp * *++dltp)>>14;
+ /*
+ if (szl > 32767) szl = 32767;
+ else if (szl < -32768) szl = -32768;
+ */
+ szl += (*++blp * *++dltp)>>14;
+ /*
+ if (szl > 32767) szl = 32767;
+ else if (szl < -32768) szl = -32768;
+ */
+ szl += (*++blp * *++dltp)>>14;
+ /*
+ if (szl > 32767) szl = 32767;
+ else if (szl < -32768) szl = -32768;
+ */
+ szl += (*++blp * *++dltp)>>14;
+ /*
+ if (szl > 32767) szl = 32767;
+ else if (szl < -32768) szl = -32768;
+ */
+ szl += (*++blp * *++dltp)>>14;
+ /*
+ if (szl > 32767) szl = 32767;
+ else if (szl < -32768) szl = -32768;
+ */
+ szl += (*++blp * *++dltp)>>14;
+ /*
+ if (szl > 32767) szl = 32767;
+ else if (szl < -32768) szl = -32768;
+ */
+
+ /*********************************BLOCK 4L, PREDIC *******************/
+
+
+ sl = spl + szl ;
+ /*
+ if (sl > 32767) sl = 32767;
+ if (sl < -32768) sl = -32768;
+ */
+
+ return (sl) ;
+}
+
+void g722_decoder_close(void *decoder)
+{
+ free(decoder);
+}
+
+void *g722_decoder_open()
+{
+ g722_decoder_t *d = malloc(sizeof(g722_decoder_t));
+
+ if (d)
+ {
+ d->slow = 0;
+ d->detlow = 32;
+ d->shigh = 0;
+ d->dethigh = 8;
+ memset(d->xd, 0, sizeof(d->xd));
+ memset(d->xs, 0, sizeof(d->xs));
+ d->k = 1;
+ d->nbl = 0; /* block3l */
+ d->nbh = 0; /* block3h */
+ }
+ return d;
+}
+
+void g722_decoder_process(
+ void *decoder,
+ unsigned short *input, short *output, int outputLength)
+{
+ g722_decoder_t *d = (g722_decoder_t *) decoder;
+
+ int j;
+
+ for(j=0; j < outputLength;) {
+ int ilowr, dlowt, rlow;
+ int ihigh, dhigh, rhigh;
+ register int wd1, wd2, wd3;
+ register int *xdp, *xsp, *xdp_1, *xsp_1;
+ register int xout1;
+
+ int nbl, nbh;
+
+ ilowr = *input >> 10;
+ ihigh = (*input >> 8) & 3;
+
+nexttwodata:
+ /*********************** BLOCK 5L, LOW BAND INVQBL ****************/
+
+ wd2 = qm6[ilowr] ;
+ wd2 = ((d->detlow) * wd2 ) >> 15 ;
+ /******************************** BLOCK 5L, RECONS ****************/
+ rlow = (d->slow) + wd2 ;
+ /*
+ if (rlow > 32767) rlow = 32767;
+ if (rlow < -32768) rlow = -32768;
+ */
+ /******************************** BLOCK 6L, LIMIT ******************/
+ /*
+ if (rlow > 16383 ) rlow = 16383;
+ if (rlow < -16383 ) rlow = -16383;
+ */
+ /************************************** BLOCK 2L, INVQAL ************/
+
+ wd1 = ilowr >> 2 ;
+ wd2 = qm4[wd1] ;
+ dlowt = ((d->detlow) * wd2) >> 15 ;
+ /************************************** BLOCK 3L, LOGSCL *************/
+
+ wd2 = rl42[wd1] ;
+ nbl = d->nbl;
+ wd1 = (nbl * 127) >> 7 ;
+ nbl = wd1 + wl[wd2] ;
+ if (nbl < 0)
+ nbl = 0 ;
+ else if (nbl > 18432)
+ nbl = 18432 ;
+ d->nbl = nbl;
+ /************************************** BLOCK 3L, SCALEL *************/
+
+ wd1 = (nbl >> 6) & 31 ;
+ wd2 = nbl >> 11 ;
+ wd3= ((8 - wd2) < 0)? ilb[wd1] << (wd2 - 8) : ilb[wd1] >> (8 - wd2) ;
+ d->detlow = wd3 << 2 ;
+
+ d->slow = block4l (dlowt) ;
+ /************************************** BLOCK 2H, INVQAH ************/
+
+ wd2 = qm2[ihigh] ;
+ dhigh = ((d->dethigh) * wd2) >> 15 ;
+
+ rhigh = dhigh + (d->shigh);
+ /*
+ if (rhigh > 16383 ) rhigh = 16383 ;
+ if (rhigh < -16384 ) rhigh = -16384 ;
+ */
+ /************************************** BLOCK 2H, INVQAH ************/
+
+ wd2 = rh2[ihigh] ;
+ nbh = d->nbh;
+ wd1 = (nbh * 127) >> 7 ;
+ nbh = wd1 + wh[wd2] ;
+
+
+ if (nbh < 0)
+ nbh = 0 ;
+ else if (nbh > 22528)
+ nbh = 22528 ;
+ d->nbh = nbh;
+ /************************************** BLOCK 3H, SCALEH *************/
+
+ wd1 = (nbh >> 6) & 31 ;
+ wd2 = nbh >> 11 ;
+ wd3= ((10 - wd2) < 0)? ilb[wd1] << (wd2 - 10) : ilb[wd1] >> (10 - wd2) ;
+ d->dethigh = wd3 << 2 ;
+
+ d->shigh = block4h (dhigh) ;
+ /******************************* RECIEVE QMF ************************/
+
+ xdp=(d->xd)+11, xsp=(d->xs)+11, xdp_1=(d->xd)+10, xsp_1=(d->xs)+10;
+ *xdp-- = *xdp_1--; *xsp-- = *xsp_1--;
+ *xdp-- = *xdp_1--; *xsp-- = *xsp_1--;
+ *xdp-- = *xdp_1--; *xsp-- = *xsp_1--;
+ *xdp-- = *xdp_1--; *xsp-- = *xsp_1--;
+ *xdp-- = *xdp_1--; *xsp-- = *xsp_1--;
+ *xdp-- = *xdp_1--; *xsp-- = *xsp_1--;
+ *xdp-- = *xdp_1--; *xsp-- = *xsp_1--;
+ *xdp-- = *xdp_1--; *xsp-- = *xsp_1--;
+ *xdp-- = *xdp_1--; *xsp-- = *xsp_1--;
+ *xdp-- = *xdp_1--; *xsp-- = *xsp_1--;
+ *xdp-- = *xdp_1--; *xsp-- = *xsp_1--;
+ /************************************* RECA ***************************/
+
+ *xdp = rlow - rhigh ;
+ /*
+ if (*xdp > 16383) *xdp = 16383;
+ if (*xdp < -16384) *xdp = -16384;
+ */
+
+ /************************************* RECA ***************************/
+
+ *xsp = rlow + rhigh ;
+ /*
+ if (*xsp > 16383) *xsp = 16383;
+ if (*xsp < -16384) *xsp = -16384;
+ */
+ /************************************* ACCUM C&D *************************/
+ /* qmf tap coefficients */
+ xout1 = *xdp++ * 3;
+ xout1 += *xdp++ * -11;
+ xout1 += *xdp++ * 12;
+ xout1 += *xdp++ * 32;
+ xout1 += *xdp++ * -210;
+ xout1 += *xdp++ * 951;
+ xout1 += *xdp++ * 3876;
+ xout1 += *xdp++ * -805;
+ xout1 += *xdp++ * 362;
+ xout1 += *xdp++ * -156;
+ xout1 += *xdp++ * 53;
+ xout1 += *xdp++ * -11;
+
+ *output++ = xout1 >> 12 ;
+
+ xout1 = *xsp++ * -11;
+ xout1 += *xsp++ * 53;
+ xout1 += *xsp++ * -156;
+ xout1 += *xsp++ * 362;
+ xout1 += *xsp++ * -805;
+ xout1 += *xsp++ * 3876;
+ xout1 += *xsp++ * 951;
+ xout1 += *xsp++ * -210;
+ xout1 += *xsp++ * 32;
+ xout1 += *xsp++ * 12;
+ xout1 += *xsp++ * -11;
+ xout1 += *xsp++ * 3;
+
+ *output++ = xout1 >> 12 ;
+
+ j++, j++;
+
+ d->k=-(d->k);
+ /*
+ if (xout1 > 16383) xout1 = 16383 ;
+ if (xout1 < -16384) xout1 = -16384 ;
+ if (xout1 > 16383) xout1 = 16383 ;
+ if (xout1 < -16384) xout1 = -16384 ;
+ */
+ if((d->k)<0){
+ ilowr = (*input >> 2) & 63;
+ ihigh = (*input++) & 3;
+ goto nexttwodata;
+ }
+ }
+}
diff --git a/src/native/g722/g722_decoder.h b/src/native/g722/g722_decoder.h
new file mode 100644
index 0000000..7061914
--- /dev/null
+++ b/src/native/g722/g722_decoder.h
@@ -0,0 +1,17 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+#ifndef __G722_DECODER_H__
+#define __G722_DECODER_H__
+
+void g722_decoder_close(void *decoder);
+void *g722_decoder_open();
+void g722_decoder_process(
+ void *decoder,
+ unsigned short *input, short *output, int outputLength);
+
+#endif /* __G722_DECODER_H__ */ \ No newline at end of file
diff --git a/src/native/g722/g722_encoder.c b/src/native/g722/g722_encoder.c
new file mode 100644
index 0000000..0eb7a0e
--- /dev/null
+++ b/src/native/g722/g722_encoder.c
@@ -0,0 +1,854 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+/**********************************************/
+/* */
+/***** Copyright (c) CMU 1993 *****/
+/* Computer Science, Speech Group */
+/* Chengxiang Lu and Alex Hauptmann */
+/* */
+/* This program performs the encoder for the */
+/* 64 kb/s CCITT ADPCM codec. It reads 16kHz */
+/* sampled 14bit PCM values and writes high */
+/* and low band ADPCM values(2bits and 6bits,*/
+/* respectively) out. */
+/* */
+/* With speed of 0.4xreal-time for coder */
+/* and 0.3xreal-time for decoder on NeXT. */
+/* */
+/* encoder */
+/* 16kHzSamplingx16bit==============>64kb/s */
+/* */
+/**********************************************/
+
+#include "g722_encoder.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int block4h(int);
+static int block4l(int);
+
+/*************************** block1l *********************************/
+ static int q6[32] = {0, 35, 72, 110, 150, 190, 233, 276, 323,
+ 370, 422, 473, 530, 587, 650, 714, 786,
+ 858, 940, 1023, 1121, 1219, 1339, 1458,
+ 1612, 1765, 1980, 2195, 2557, 2919, 0, 0} ;
+
+ static int iln[32] = {0, 63, 62, 31, 30, 29, 28, 27, 26, 25,
+ 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14,
+ 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 0 } ;
+
+ static int ilp[32] = {0, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52,
+ 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41,
+ 40, 39, 38, 37, 36, 35, 34, 33, 32, 0 } ;
+/*************************** BLOCK 2L ********************************/
+ static int qm4[16] =
+ {0, -20456, -12896, -8968,
+ -6288, -4240, -2584, -1200,
+ 20456, 12896, 8968, 6288,
+ 4240, 2584, 1200, 0 } ;
+/*************************** BLOCK 3L ********************************/
+ static int wl[8] = {-60, -30, 58, 172, 334, 538, 1198, 3042 } ;
+ static int rl42[16] = {0, 7, 6, 5, 4, 3, 2, 1, 7, 6, 5, 4, 3, 2,
+ 1, 0 } ;
+ static int ilb[32] = {2048, 2093, 2139, 2186, 2233, 2282, 2332,
+ 2383, 2435, 2489, 2543, 2599, 2656, 2714,
+ 2774, 2834, 2896, 2960, 3025, 3091, 3158,
+ 3228, 3298, 3371, 3444, 3520, 3597, 3676,
+ 3756, 3838, 3922, 4008 } ;
+/*************************** BLOCK 1H ********************************/
+ static int ihn[3] = { 0, 1, 0 } ;
+ static int ihp[3] = { 0, 3, 2 } ;
+/************************** BLOCK 2H *********************************/
+ static int qm2[4] =
+ {-7408, -1616, 7408, 1616} ;
+/************************** BLOCK 3H *********************************/
+ static int wh[3] = {0, -214, 798} ;
+ static int rh2[4] = {2, 1, 2, 1} ;
+
+typedef struct
+{
+ int k; /* counter */
+ int x[24]; /* storage for signal passing through the qmf */
+ int slow;
+ int detlow;
+ int shigh;
+ int dethigh;
+ int nbl; /* block 3l */
+ int nbh; /* block 3h */
+}
+g722_encoder_t;
+
+/**************************** BLOCK 4H *******************************/
+static int block4h (int d)
+{
+static int sh = 0 ;
+ int wd1, wd2, wd3, wd4, wd5;
+ static int sph = 0 ;
+ static int szh = 0 ;
+ static int rh [3] = { 0, 0, 0 } ;
+ static int ah [3] = { 0, 0, 0 } ;
+ static int ph [3] = { 0, 0, 0 } ;
+ static int dh [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+ static int bh [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+ static int sg [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+
+ register int *sgp, *bhp, *dhp, *php, *ahp, *rhp;
+ register int *dhp_1, *rhp_1, *php_1;
+/*************************************** BLOCK 4H, RECONS ***********/
+
+ *dh = d;
+ *rh = sh + d ;
+/*
+ if ( rh[0] > 32767 ) rh[0] = 32767;
+ else if ( rh[0] < -32768 ) rh[0] = -32768;
+*/
+/*************************************** BLOCK 4H, PARREC ***********/
+
+ *ph = d + szh ;
+/*
+ if ( ph[0] > 32767 ) ph[0] = 32767;
+ else if ( ph[0] < -32768 ) ph[0] = -32768;
+*/
+/*****************************BLOCK 4H, UPPOL2*************************/
+ sgp = sg, php = ph, ahp =ah ;
+ *sg = *ph >> 15 ;
+ *++sgp = *++php >> 15 ;
+ *++sgp = *++php >> 15 ;
+ wd1 = (*++ahp) << 2;
+
+ if ( wd1 > 32767 ) wd1 = 32767;
+ else if ( wd1 < -32768 ) wd1 = -32768;
+
+ wd2 = ( *sg == *--sgp ) ? - wd1 : wd1;
+ if ( wd2 > 32767 ) wd2 = 32767;
+
+ wd2 = wd2 >> 7 ;
+ wd3 = ( *sg == *++sgp ) ? 128:-128 ;
+
+ wd4 = wd2 + wd3 ;
+ wd5 = (*++ahp * 32512) >> 15 ;
+
+ *ahp = wd4 + wd5 ;
+ if ( *ahp > 12288 ) *ahp = 12288 ;
+ else if ( *ahp < -12288 ) *ahp = -12288 ;
+/************************************* BLOCK 4H, UPPOL1 ***************/
+
+ *sg = *ph >> 15 ;
+ *--sgp = *--php >> 15 ;
+ wd1 = ( *sg == *sgp ) ? 192 : -192;
+
+ wd2 = (*--ahp * 32640) >> 15 ;
+
+ *ahp = wd1 + wd2 ;
+/*
+ if ( *ahp > 32767 ) *ahp = 32767;
+ else if ( *ahp < -32768 ) *ahp = -32768;
+*/
+ wd3 = (15360 - *++ahp) ;
+/*
+ if ( wd3 > 32767 ) wd3 = 32767;
+ else if ( wd3 < -32768 ) wd3 = -32768;
+*/
+ if ( *--ahp > wd3) *ahp = wd3 ;
+ else if ( *ahp < -wd3) *ahp = -wd3 ;
+
+/*************************************** BLOCK 4H, UPZERO ************/
+ wd1 = ( d == 0 ) ? 0 : 128;
+
+ *sg = d >> 15 ;
+ dhp = dh, bhp = bh;
+ *sgp = *++dhp >> 15 ;
+ wd2 = ( *sgp++ == *sg ) ? wd1 : -wd1;
+ wd3 = (*++bhp * 32640) >> 15 ;
+ *bhp = wd2 + wd3 ;
+/*
+ if ( *bhp > 32767 ) *bhp= 32767;
+ else if ( *bhp < -32768 ) *bhp = -32768;
+*/
+
+ *sgp = *++dhp >> 15 ;
+ wd2 = ( *sgp++ == *sg ) ? wd1 : -wd1;
+ wd3 = (*++bhp * 32640) >> 15 ;
+ *bhp = wd2 + wd3 ;
+/*
+ if ( *bhp > 32767 ) *bhp= 32767;
+ else if ( *bhp < -32768 ) *bhp = -32768;
+*/
+
+ *sgp = *++dhp >> 15 ;
+ wd2 = ( *sgp++ == *sg ) ? wd1 : -wd1;
+ wd3 = (*++bhp * 32640) >> 15 ;
+ *bhp = wd2 + wd3 ;
+/*
+ if ( *bhp > 32767 ) *bhp= 32767;
+ else if ( *bhp < -32768 ) *bhp = -32768;
+*/
+
+ *sgp = *++dhp >> 15 ;
+ wd2 = ( *sgp++ == *sg ) ? wd1 : -wd1;
+ wd3 = (*++bhp * 32640) >> 15 ;
+ *bhp = wd2 + wd3 ;
+/*
+ if ( *bhp > 32767 ) *bhp= 32767;
+ else if ( *bhp < -32768 ) *bhp = -32768;
+*/
+
+ *sgp = *++dhp >> 15 ;
+ wd2 = ( *sgp++ == *sg ) ? wd1 : -wd1;
+ wd3 = (*++bhp * 32640) >> 15 ;
+ *bhp = wd2 + wd3 ;
+/*
+ if ( *bhp > 32767 ) *bhp= 32767;
+ else if ( *bhp < -32768 ) *bhp = -32768;
+*/
+
+ *sgp = *++dhp >> 15 ;
+ wd2 = ( *sgp++ == *sg ) ? wd1 : -wd1;
+ wd3 = (*++bhp * 32640) >> 15 ;
+ *bhp = wd2 + wd3 ;
+/*
+ if ( *bhp > 32767 ) *bhp= 32767;
+ else if ( *bhp < -32768 ) *bhp = -32768;
+*/
+
+/********************************* BLOCK 4H, DELAYA ******************/
+ dhp_1 = dhp - 1;
+
+ *dhp-- = *dhp_1-- ;
+ *dhp-- = *dhp_1-- ;
+ *dhp-- = *dhp_1-- ;
+ *dhp-- = *dhp_1-- ;
+ *dhp-- = *dhp_1-- ;
+ *dhp-- = *dhp_1-- ;
+
+ rhp = rh+2;
+ php++;
+ rhp_1 = rhp - 1, php_1 = php - 1;
+
+ *rhp-- = *rhp_1-- ;
+ *php-- = *php_1-- ;
+ *rhp-- = *rhp_1-- ;
+ *php-- = *php_1-- ;
+/********************************* BLOCK 4H, FILTEP ******************/
+
+ wd1 = ( *ahp * *++rhp ) >> 14 ;
+
+ wd2 = ( *++ahp * *++rhp ) >> 14 ;
+
+ sph = wd1 + wd2 ;
+/*
+ if ( sph > 32767 ) sph = 32767;
+ if ( sph < -32768 ) sph = -32768;
+*/
+/*************************************** BLOCK 4H, FILTEZ ***********/
+
+ bhp = bhp -6;
+ szh = (*++bhp * *++dhp ) >> 14 ;
+/*
+ if ( szh > 32767 ) szh = 32767;
+ else if ( szh < -32768 ) szh = -32768;
+*/
+ szh += (*++bhp * *++dhp ) >> 14 ;
+/*
+ if ( szh > 32767 ) szh = 32767;
+ else if ( szh < -32768 ) szh = -32768;
+*/
+ szh += (*++bhp * *++dhp ) >> 14 ;
+/*
+ if ( szh > 32767 ) szh = 32767;
+ else if ( szh < -32768 ) szh = -32768;
+*/
+ szh += (*++bhp * *++dhp ) >> 14 ;
+/*
+ if ( szh > 32767 ) szh = 32767;
+ else if ( szh < -32768 ) szh = -32768;
+*/
+ szh += (*++bhp * *++dhp ) >> 14 ;
+/*
+ if ( szh > 32767 ) szh = 32767;
+ else if ( szh < -32768 ) szh = -32768;
+*/
+ szh += (*++bhp * *++dhp ) >> 14 ;
+/*
+ if ( szh > 32767 ) szh = 32767;
+ else if ( szh < -32768 ) szh = -32768;
+*/
+/*********************************BLOCK 4L, PREDIC *******************/
+
+ sh = sph + szh ;
+/*
+ if ( sh > 32767 ) sh = 32767;
+ if ( sh < -32768 ) sh = -32768;
+*/
+ return (sh) ;
+}
+
+/**************************** BLOCK 4L *******************************/
+static int block4l (int dl)
+{
+static int sl = 0 ;
+ int wd1, wd2, wd3, wd4, wd5;
+ static int spl = 0 ;
+ static int szl = 0 ;
+ static int rlt [3] = { 0, 0, 0 } ;
+ static int al [3] = { 0, 0, 0 } ;
+ static int plt [3] = { 0, 0, 0 } ;
+ static int dlt [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+ static int bl [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+ static int sg [7] = { 0, 0, 0, 0, 0, 0, 0 } ;
+/****************** pointer ****************************/
+ register int *sgp, *pltp, *alp, *dltp, *blp, *rltp;
+ register int *pltp_1, *dltp_1, *rltp_1;
+/*************************************** BLOCK 4L, RECONS ***********/
+ *dlt = dl;
+
+ *rlt = sl + dl ;
+/*
+ if ( *rlt > 32767 ) *rlt = 32767;
+ else if ( *rlt < -32768 ) *rlt = -32768;
+*/
+/*************************************** BLOCK 4L, PARREC ***********/
+
+ *plt = dl + szl ;
+/*
+ if ( plt[0] > 32767 ) plt[0] = 32767;
+ else if ( plt[0] < -32768 ) plt[0] = -32768;
+*/
+/*****************************BLOCK 4L, UPPOL2*************************/
+ sgp = sg, pltp = plt, alp = al ;
+ *sgp++ = *pltp++ >> 15 ;
+ *sgp++ = *pltp++ >> 15 ;
+ *sgp++ = *pltp++ >> 15 ;
+
+ wd1 = *++alp << 2;
+
+ if ( wd1 > 32767 ) wd1 = 32767;
+ else if ( wd1 < -32768 ) wd1 = -32768;
+
+ wd2= ( *sg == *(sg+1) )? -wd1: wd1 ;
+ if ( wd2 > 32767 ) wd2 = 32767;
+
+ wd2 = wd2 >> 7 ;
+ wd3= ( *sg == *(sg+2) )? 128: -128 ;
+ wd4 = wd2 + wd3 ;
+ wd5 = (*++alp * 32512) >> 15 ;
+
+ *alp = wd4 + wd5 ;
+
+ if ( *alp > 12288 ) *alp = 12288 ;
+ else if ( *alp < -12288 ) *alp = -12288 ;
+
+/************************************* BLOCK 4L, UPPOL1 ***************/
+
+ *sg = *plt >> 15 ;
+ *(sg+1) = *(plt+1) >> 15 ;
+ wd1 = ( *sg == *(sg+1) )? 192 : -192 ;
+
+ wd2 = (*--alp * 32640) >> 15 ;
+
+ *alp = wd1 + wd2 ;
+/*
+ if ( *alp > 32767 ) *alp = 32767;
+ else if ( *alp < -32768 ) *alp = -32768;
+*/
+ wd3 = (15360 - *++alp) ;
+/*
+ if ( wd3 > 32767 ) wd3 = 32767;
+ else if ( wd3 < -32768 ) wd3 = -32768;
+*/
+ if ( *--alp > wd3) *alp = wd3 ;
+ else if ( *alp < -wd3) *alp = -wd3 ;
+
+/*************************************** BLOCK 4L, UPZERO ************/
+ wd1 = ( dl == 0 ) ? 0 : 128;
+ *sg = dl >> 15 ;
+ sgp = sg, dltp = dlt, blp = bl;
+
+ *++sgp = *++dltp >> 15 ;
+ wd2 = ( *sgp == *sg ) ? wd1 : -wd1 ;
+ wd3 = (*++blp * 32640) >> 15 ;
+ *blp = wd2 + wd3 ;
+/*
+ if ( *blp > 32767 ) *blp = 32767;
+ else if ( *blp < -32768 ) *blp = -32768;
+*/
+
+ *++sgp = *++dltp >> 15 ;
+ wd2 = ( *sgp == *sg ) ? wd1 : -wd1 ;
+ wd3 = (*++blp * 32640) >> 15 ;
+ *blp = wd2 + wd3 ;
+/*
+ if ( *blp > 32767 ) *blp = 32767;
+ else if ( *blp < -32768 ) *blp = -32768;
+*/
+
+ *++sgp = *++dltp >> 15 ;
+ wd2 = ( *sgp == *sg ) ? wd1 : -wd1 ;
+ wd3 = (*++blp * 32640) >> 15 ;
+ *blp = wd2 + wd3 ;
+/*
+ if ( *blp > 32767 ) *blp = 32767;
+ else if ( *blp < -32768 ) *blp = -32768;
+*/
+
+ *++sgp = *++dltp >> 15 ;
+ wd2 = ( *sgp == *sg ) ? wd1 : -wd1 ;
+ wd3 = (*++blp * 32640) >> 15 ;
+ *blp = wd2 + wd3 ;
+/*
+ if ( *blp > 32767 ) *blp = 32767;
+ else if ( *blp < -32768 ) *blp = -32768;
+*/
+
+ *++sgp = *++dltp >> 15 ;
+ wd2 = ( *sgp == *sg ) ? wd1 : -wd1 ;
+ wd3 = (*++blp * 32640) >> 15 ;
+ *blp = wd2 + wd3 ;
+/*
+ if ( *blp > 32767 ) *blp = 32767;
+ else if ( *blp < -32768 ) *blp = -32768;
+*/
+
+ *++sgp = *++dltp >> 15 ;
+ wd2 = ( *sgp == *sg ) ? wd1 : -wd1 ;
+ wd3 = (*++blp * 32640) >> 15 ;
+ *blp = wd2 + wd3 ;
+/*
+ if ( *blp > 32767 ) *blp = 32767;
+ else if ( *blp < -32768 ) *blp = -32768;
+*/
+
+/********************************* BLOCK 4L, DELAYA ******************/
+ dltp_1 = dltp - 1;
+ *dltp-- = *dltp_1-- ;
+ *dltp-- = *dltp_1-- ;
+ *dltp-- = *dltp_1-- ;
+ *dltp-- = *dltp_1-- ;
+ *dltp-- = *dltp_1-- ;
+ *dltp-- = *dltp_1-- ;
+
+ rltp =rlt+2, pltp = plt+2 ;
+ rltp_1 = rltp - 1, pltp_1 = pltp - 1;
+
+ *rltp-- = *rltp_1--;
+ *pltp-- = *pltp_1--;
+ *rltp-- = *rltp_1--;
+ *pltp-- = *pltp_1--;
+/********************************* BLOCK 4L, FILTEP ******************/
+
+ wd1 = ( *alp * *++rltp ) >> 14 ;
+
+ wd2 = ( *++alp * *++rltp ) >> 14 ;
+
+ spl = wd1 + wd2 ;
+/*
+ if ( spl > 32767 ) spl = 32767;
+ else if ( spl < -32768 ) spl = -32768;
+*/
+/*************************************** BLOCK 4L, FILTEZ ***********/
+
+ blp = blp - 6;
+ szl = (*++blp * *++dltp) >> 14 ;
+/*
+ if ( szl > 32767 ) szl = 32767;
+ else if ( szl < -32768 ) szl = -32768;
+*/
+ szl += (*++blp * *++dltp) >> 14 ;
+/*
+ if ( szl > 32767 ) szl = 32767;
+ else if ( szl < -32768 ) szl = -32768;
+*/
+ szl += (*++blp * *++dltp) >> 14 ;
+/*
+ if ( szl > 32767 ) szl = 32767;
+ else if ( szl < -32768 ) szl = -32768;
+*/
+ szl += (*++blp * *++dltp) >> 14 ;
+/*
+ if ( szl > 32767 ) szl = 32767;
+ else if ( szl < -32768 ) szl = -32768;
+*/
+ szl += (*++blp * *++dltp) >> 14 ;
+/*
+ if ( szl > 32767 ) szl = 32767;
+ else if ( szl < -32768 ) szl = -32768;
+*/
+ szl += (*++blp * *++dltp) >> 14 ;
+/*
+ if ( szl > 32767 ) szl = 32767;
+ else if ( szl < -32768 ) szl = -32768;
+*/
+/*********************************BLOCK 4L, PREDIC *******************/
+
+ sl = spl + szl ;
+/*
+ if ( sl > 32767 ) sl = 32767;
+ else if ( sl < -32768 ) sl = -32768;
+*/
+
+ return (sl) ;
+}
+
+void g722_encoder_close(void *encoder)
+{
+ free(encoder);
+}
+
+void *g722_encoder_open()
+{
+ g722_encoder_t *e = malloc(sizeof(g722_encoder_t));
+
+ if (e)
+ {
+ e->k = 1;
+ memset(e->x, 0, sizeof(e->x));
+ e->slow = 0;
+ e->detlow = 32;
+ e->shigh = 0;
+ e->dethigh = 8;
+ e->nbl = 0;
+ e->nbh = 0;
+ }
+ return e;
+}
+
+void g722_encoder_process(
+ void *encoder,
+ short *input, unsigned short *output, int outputLength)
+{
+ g722_encoder_t *e = (g722_encoder_t *) encoder;
+
+ int j=0;
+
+ while( j< outputLength ){
+ register int *xp, *xp_2, *q6p;
+ int sumeven, sumodd; /* even and odd tap accumulators */
+ int xlow, xhigh; /* low and high band pcm from qmf */
+ register int el, wd, mil, wd1;
+ int wd2;
+ int ilow=0, ihigh=0;
+ int ril;
+ int dlowt;
+ int il4, wd3;
+ int eh, mih;
+ register int hdu;
+ int dhigh;
+ int ih2;
+
+ int detlow, nbl, nbh;
+
+/* PROCESS PCM THROUGH THE QMF FILTER */
+
+nexttwodata:
+ xp = (e->x) + 23; xp_2 = (e->x) +21;
+
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+ *xp-- = *xp_2--;
+
+
+ *xp = *input++;
+ *--xp = *input++;
+
+/* DISCARD EVERY OTHER QMF OUTPUT */
+
+ sumeven = *xp++ * 3;
+ sumodd = *xp++ * (-11);
+ sumeven += *xp++ * (-11);
+ sumodd += *xp++ * 53;
+ sumeven += *xp++ * 12;
+ sumodd += *xp++ * (-156);
+ sumeven += *xp++ * 32;
+ sumodd += *xp++ * 362;
+ sumeven += *xp++ * (-210);
+ sumodd += *xp++ * (-805);
+ sumeven += *xp++ * 951;
+ sumodd += *xp++ * 3876;
+ sumeven += *xp++ * 3876;
+ sumodd += *xp++ * 951;
+ sumeven += *xp++ * (-805);
+ sumodd += *xp++ * (-210);
+ sumeven += *xp++ * 362;
+ sumodd += *xp++ * 32;
+ sumeven += *xp++ * (-156);
+ sumodd += *xp++ * 12;
+ sumeven += *xp++ * 53;
+ sumodd += *xp++ * (-11);
+ sumeven += *xp++ * (-11);
+ sumodd += *xp++ * 3;
+
+ xlow = (sumeven + sumodd) >>13;
+ xhigh = (sumeven - sumodd) >>13;
+
+/*************************************** BLOCK 1L, SUBTRA ************/
+
+ el = xlow - (e->slow);
+
+ if ( el > 32767 ) el = 32767;
+ else if ( el < -32768 ) el = -32768;
+
+/*************************************** BLOCK 1L, QUANTL ************/
+
+ wd= (el>= 0 ) ? el: -(el+1) ;
+
+ q6p = q6;
+ detlow = e->detlow;
+ mil = 1;
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+ wd2 = *++q6p * detlow ;
+ wd1 = wd2 >> 12 ;
+ if (wd >= wd1) mil++;
+ else goto next_ilow;
+
+next_ilow:
+ ilow = ( el < 0 ) ? iln[mil] : ilp[mil];
+
+/************************************** BLOCK 2L, INVQAL ************/
+
+ ril = ilow >> 2 ;
+ wd2 = qm4[ril] ;
+ dlowt = (detlow * wd2) >> 15 ;
+
+/************************************** BLOCK 3L, LOGSCL *************/
+
+ il4 = rl42[ril] ;
+
+ nbl = e->nbl;
+ wd = (nbl * 127) >> 7 ;
+
+ nbl = wd + wl[il4] ;
+
+ if (nbl < 0) nbl = 0 ;
+ else if (nbl > 18432) nbl = 18432 ;
+ e->nbl = nbl;
+
+/************************************** BLOCK 3L, SCALEL *************/
+ wd1 = (nbl >> 6) & 31 ;
+ wd2 = nbl >> 11 ;
+ wd3=((8 - wd2) < 0) ? ilb[wd1]<<(wd2 - 8) : ilb[wd1]>>(8 - wd2);
+ e->detlow = detlow = wd3 << 2 ;
+/************************************** BLOCK 3L, DELAYA *************/
+
+ e->slow = block4l (dlowt) ;
+
+
+/*************************************** BLOCK 1H, SUBTRA ************/
+
+ eh = xhigh - (e->shigh);
+/*
+ if ( eh > 32767 ) eh = 32767;
+ else if ( eh < -32768 ) eh = -32768;
+*/
+/*************************************** BLOCK 1H, QUANTH ************/
+
+ wd = (eh>= 0 )? eh : -( eh +1 ) ;
+
+ hdu = 564 * (e->dethigh);
+ wd1 = hdu >> 12 ;
+ mih = (wd >= wd1)? 2: 1 ;
+ ihigh = (eh<0) ? ihn[mih] : ihp[mih] ;
+
+/************************************** BLOCK 2H, INVQAH ************/
+
+ wd2 = qm2[ihigh] ;
+ dhigh = ((e->dethigh) * wd2) >> 15 ;
+
+
+/************************************** BLOCK 3H, LOGSCH *************/
+
+ ih2 = rh2[ihigh] ;
+
+ nbh = e->nbh;
+ wd = (nbh * 127) >> 7 ;
+ nbh = wd + wh[ih2] ;
+
+ if (nbh < 0) nbh = 0 ;
+ else if (nbh > 22528) nbh = 22528 ;
+ e->nbh = nbh;
+
+/************************************** BLOCK 3H, SCALEH *************/
+ wd1 = (nbh >> 6) & 31 ;
+ wd2 = nbh >> 11 ;
+ wd3=((10-wd2) < 0)? ilb[wd1] << (wd2-10): ilb[wd1] >> (10-wd2) ;
+ e->dethigh = wd3 << 2 ;
+/************************************** BLOCK 3L, DELAYA *************/
+
+ e->shigh = block4h (dhigh) ;
+ if((e->k)>0){
+ output[j] = ilow;
+ output[j] = (output[j]<<2) + ihigh;
+ e->k = -(e->k);
+ goto nexttwodata;
+ }
+ else {
+ output[j] = (output[j]<<6) + ilow;
+ output[j] = (output[j]<<2) + ihigh;
+ e->k = -(e->k);
+ }
+ j++;
+ }
+}
diff --git a/src/native/g722/g722_encoder.h b/src/native/g722/g722_encoder.h
new file mode 100644
index 0000000..5cd3a85
--- /dev/null
+++ b/src/native/g722/g722_encoder.h
@@ -0,0 +1,17 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+#ifndef __G722_ENCODER_H__
+#define __G722_ENCODER_H__
+
+void g722_encoder_close(void *encoder);
+void *g722_encoder_open();
+void g722_encoder_process(
+ void *encoder,
+ short *input, unsigned short *output, int outputLength);
+
+#endif /* __G722_ENCODER_H__ */
diff --git a/src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder.c b/src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder.c
new file mode 100644
index 0000000..4cbb4e0
--- /dev/null
+++ b/src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder.c
@@ -0,0 +1,46 @@
+#include "net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder.h"
+#include "g722_decoder.h"
+
+JNIEXPORT void JNICALL
+Java_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder_g722_1decoder_1close
+ (JNIEnv *jniEnv, jclass clazz, jlong decoder)
+{
+ g722_decoder_close((void *) decoder);
+}
+
+JNIEXPORT jlong JNICALL
+Java_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder_g722_1decoder_1open
+ (JNIEnv *jniEnv, jclass clazz)
+{
+ return (jlong) g722_decoder_open();
+}
+
+JNIEXPORT void JNICALL
+Java_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder_g722_1decoder_1process
+ (JNIEnv *jniEnv, jclass clazz,
+ jlong decoder,
+ jbyteArray input, jint inputOffset,
+ jbyteArray output, jint outputOffset, jint outputLength)
+{
+ jbyte *outputPtr = (*jniEnv)->GetByteArrayElements(jniEnv, output, NULL);
+
+ if (outputPtr)
+ {
+ jbyte *inputPtr
+ = (*jniEnv)->GetPrimitiveArrayCritical(jniEnv, input, NULL);
+
+ if (inputPtr)
+ {
+ g722_decoder_process(
+ (void *) decoder,
+ (unsigned short *) (inputPtr + inputOffset),
+ (short *) (outputPtr + outputOffset),
+ outputLength / sizeof(short));
+ (*jniEnv)->ReleasePrimitiveArrayCritical(
+ jniEnv,
+ input, inputPtr,
+ JNI_ABORT);
+ }
+ (*jniEnv)->ReleaseByteArrayElements(jniEnv, output, outputPtr, 0);
+ }
+}
diff --git a/src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder.h b/src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder.h
new file mode 100644
index 0000000..d82c846
--- /dev/null
+++ b/src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder.h
@@ -0,0 +1,37 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder */
+
+#ifndef _Included_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder
+#define _Included_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder
+ * Method: g722_decoder_close
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder_g722_1decoder_1close
+ (JNIEnv *, jclass, jlong);
+
+/*
+ * Class: net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder
+ * Method: g722_decoder_open
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder_g722_1decoder_1open
+ (JNIEnv *, jclass);
+
+/*
+ * Class: net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder
+ * Method: g722_decoder_process
+ * Signature: (J[BI[BII)V
+ */
+JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIDecoder_g722_1decoder_1process
+ (JNIEnv *, jclass, jlong, jbyteArray, jint, jbyteArray, jint, jint);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder.c b/src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder.c
new file mode 100644
index 0000000..dcb64ec
--- /dev/null
+++ b/src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder.c
@@ -0,0 +1,46 @@
+#include "net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder.h"
+#include "g722_encoder.h"
+
+JNIEXPORT void JNICALL
+Java_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder_g722_1encoder_1close
+ (JNIEnv *jniEnv, jclass clazz, jlong encoder)
+{
+ g722_encoder_close((void *) encoder);
+}
+
+JNIEXPORT jlong JNICALL
+Java_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder_g722_1encoder_1open
+ (JNIEnv *jniEnv, jclass clazz)
+{
+ return (jlong) g722_encoder_open();
+}
+
+JNIEXPORT void JNICALL
+Java_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder_g722_1encoder_1process
+ (JNIEnv *jniEnv, jclass clazz,
+ jlong encoder,
+ jbyteArray input, jint inputOffset,
+ jbyteArray output, jint outputOffset, jint outputLength)
+{
+ jbyte *outputPtr = (*jniEnv)->GetByteArrayElements(jniEnv, output, NULL);
+
+ if (outputPtr)
+ {
+ jbyte *inputPtr
+ = (*jniEnv)->GetPrimitiveArrayCritical(jniEnv, input, NULL);
+
+ if (inputPtr)
+ {
+ g722_encoder_process(
+ (void *) encoder,
+ (short *) (inputPtr + inputOffset),
+ (unsigned short *) (outputPtr + outputOffset),
+ outputLength / sizeof(unsigned short));
+ (*jniEnv)->ReleasePrimitiveArrayCritical(
+ jniEnv,
+ input, inputPtr,
+ JNI_ABORT);
+ }
+ (*jniEnv)->ReleaseByteArrayElements(jniEnv, output, outputPtr, 0);
+ }
+}
diff --git a/src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder.h b/src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder.h
new file mode 100644
index 0000000..e743977
--- /dev/null
+++ b/src/native/g722/net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder.h
@@ -0,0 +1,37 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder */
+
+#ifndef _Included_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder
+#define _Included_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder
+ * Method: g722_encoder_close
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder_g722_1encoder_1close
+ (JNIEnv *, jclass, jlong);
+
+/*
+ * Class: net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder
+ * Method: g722_encoder_open
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder_g722_1encoder_1open
+ (JNIEnv *, jclass);
+
+/*
+ * Class: net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder
+ * Method: g722_encoder_process
+ * Signature: (J[BI[BII)V
+ */
+JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_codec_audio_g722_JNIEncoder_g722_1encoder_1process
+ (JNIEnv *, jclass, jlong, jbyteArray, jint, jbyteArray, jint, jint);
+
+#ifdef __cplusplus
+}
+#endif
+#endif