Adds support for the G.722 audio codec.

cusax-fix
Lyubomir Marinov 16 years ago
parent f34d04eddb
commit 858330c2a5

@ -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)

@ -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;
}
}
}

@ -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__ */

@ -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++;
}
}

@ -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__ */

@ -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);
}
}

@ -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

@ -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);
}
}

@ -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

@ -68,7 +68,12 @@ public class AudioMediaStreamImpl
8,
1,
Format.NOT_SPECIFIED,
AudioFormat.SIGNED)
AudioFormat.SIGNED),
new AudioFormat(
Constants.G722_RTP,
8000,
Format.NOT_SPECIFIED /* sampleSizeInBits */,
1)
};
/**
@ -419,6 +424,7 @@ public void fireDTMFEvent(DTMFTone tone, boolean end)
*
* @see MediaStream#close()
*/
@Override
public void close()
{
super.close();

@ -16,7 +16,8 @@
import net.java.sip.communicator.service.neomedia.format.*;
/**
* @author Lubomir Marinov
*
* @author Lyubomir Marinov
*/
public class EncodingConfigurationTableModel
extends AbstractTableModel
@ -47,6 +48,7 @@ public EncodingConfigurationTableModel(
}
}
@Override
public Class<?> getColumnClass(int columnIndex)
{
return (columnIndex == 0) ? Boolean.class : super
@ -119,15 +121,26 @@ public Object getValueAt(int rowIndex, int columnIndex)
== encoding.getClockRate()))
return encoding.getEncoding();
else
return
encoding.getEncoding()
+ "/"
+ ((long) encoding.getClockRate());
{
String e = encoding.getEncoding();
/*
* RFC 1890 erroneously assigned 8 kHz to the RTP clock rate for
* the G722 payload format. The actual sampling rate for G.722
* audio is 16 kHz.
*/
double cr
= "G722".equalsIgnoreCase(e)
? 16000
: encoding.getClockRate();
return e + "/" + ((long) cr);
}
default:
return null;
}
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex)
{
return (columnIndex == 0);
@ -172,6 +185,7 @@ private void setPriorities(int[] priorities)
encodingConfiguration.setPriority(encodings[i], priorities[i]);
}
@Override
public void setValueAt(Object value, int rowIndex, int columnIndex)
{
if ((columnIndex == 0) && (value instanceof Boolean))

@ -128,6 +128,12 @@ public class MediaUtils
8000,
16000,
32000);
addMediaFormats(
(byte) SdpConstants.G722,
"G722",
MediaType.AUDIO,
Constants.G722_RTP,
8000);
addMediaFormats(
(byte) SdpConstants.G728,
"G728",
@ -546,6 +552,10 @@ else if (jmfEncoding.equals(AudioFormat.DVI_RTP)
return SdpConstants.DVI4_16000;
else if (jmfEncoding.equals(AudioFormat.ALAW))
return SdpConstants.PCMA;
else if (jmfEncoding.equals(Constants.G722))
return SdpConstants.G722;
else if (jmfEncoding.equals(Constants.G722_RTP))
return SdpConstants.G722;
else if (jmfEncoding.equals(AudioFormat.G728_RTP))
return SdpConstants.G728;
else if (jmfEncoding.equals(AudioFormat.G729_RTP))

@ -35,6 +35,7 @@ protected AbstractCodecExt(
this.supportedOutputFormats = supportedOutputFormats;
}
@Override
public void close()
{
if (!opened)
@ -75,6 +76,7 @@ protected Format[] getMatchingOutputFormats(Format inputFormat)
return new Format[0];
}
@Override
public String getName()
{
return (name == null) ? super.getName() : name;
@ -121,6 +123,7 @@ public static Format matches(Format in, Format outs[])
* <tt>PlugIn</tt> needs to operate cannot be acquired
* @see AbstractPlugIn#open()
*/
@Override
public void open()
throws ResourceUnavailableException
{
@ -159,6 +162,7 @@ public int process(Buffer inputBuffer, Buffer outputBuffer)
return doProcess(inputBuffer, outputBuffer);
}
@Override
public Format setInputFormat(Format format)
{
if (!formatClass.isInstance(format)
@ -168,6 +172,7 @@ public Format setInputFormat(Format format)
return super.setInputFormat(format);
}
@Override
public Format setOutputFormat(Format format)
{
if (!formatClass.isInstance(format)

@ -19,20 +19,21 @@
public class Constants
{
public static final String ALAW_RTP = "ALAW/rtp";
public static final String SPEEX_RTP = "speex/rtp";
public static final String SPEEX = "speex";
public static final String ILBC_RTP = "ilbc/rtp";
public static final String G722 = "g722";
public static final String G722_RTP = "g722/rtp";
public static final String ILBC = "ilbc";
public static final String ILBC_RTP = "ilbc/rtp";
public static final String SPEEX = "speex";
public static final String SPEEX_RTP = "speex/rtp";
public static final String H264 = "h264";
public static final String H264_RTP = "h264/rtp";
/**
* Pseudo format representing DTMF tones sent over RTP.
*/
public static final String TELEPHONE_EVENT = "telephone-event";
public static final String H264_RTP = "h264/rtp";
public static final String H264 = "h264";
public static final int H264_RTP_SDP = 99;
/**
* mode : Frame size for the encoding/decoding
* 20 - 20 ms

@ -60,37 +60,39 @@ public class EncodingConfiguration
*/
private static final String[] CUSTOM_CODECS =
{
FMJConditionals.FMJ_CODECS
? "net.sf.fmj.media.codec.audio.alaw.Encoder"
: "net.java.sip.communicator.impl.neomedia.codec.audio.alaw.JavaEncoder",
FMJConditionals.FMJ_CODECS
? "net.sf.fmj.media.codec.audio.alaw.DePacketizer"
: "net.java.sip.communicator.impl.neomedia.codec.audio.alaw.DePacketizer",
FMJConditionals.FMJ_CODECS
? "net.sf.fmj.media.codec.audio.alaw.Encoder"
: "net.java.sip.communicator.impl.neomedia.codec.audio.alaw.JavaEncoder",
FMJConditionals.FMJ_CODECS
? "net.sf.fmj.media.codec.audio.alaw.Packetizer"
: "net.java.sip.communicator.impl.neomedia.codec.audio.alaw.Packetizer",
FMJConditionals.FMJ_CODECS
? "net.sf.fmj.media.codec.audio.ulaw.Packetizer"
: "net.java.sip.communicator.impl.neomedia.codec.audio.ulaw.Packetizer",
"net.java.sip.communicator.impl.neomedia.codec.video.h264.DePacketizer",
"net.java.sip.communicator.impl.neomedia.codec.video.h264.JNIDecoder",
"net.java.sip.communicator.impl.neomedia.codec.video.h264.JNIEncoder",
"net.java.sip.communicator.impl.neomedia.codec.video.h264.Packetizer",
"net.java.sip.communicator.impl.neomedia.codec.video.SwScaler",
"net.java.sip.communicator.impl.neomedia.codec.audio.speex.JNIEncoder",
"net.java.sip.communicator.impl.neomedia.codec.audio.speex.JNIDecoder",
"net.java.sip.communicator.impl.neomedia.codec.audio.speex.JNIEncoder",
SPEEX_RESAMPLER,
"net.java.sip.communicator.impl.neomedia.codec.audio.speex.JavaEncoder",
"net.java.sip.communicator.impl.neomedia.codec.audio.speex.JavaDecoder",
"net.java.sip.communicator.impl.neomedia.codec.audio.speex.JavaEncoder",
"net.java.sip.communicator.impl.neomedia.codec.audio.mp3.JNIEncoder",
"net.java.sip.communicator.impl.neomedia.codec.audio.ilbc.JavaEncoder",
"net.java.sip.communicator.impl.neomedia.codec.audio.ilbc.JavaDecoder",
"net.java.sip.communicator.impl.neomedia.codec.audio.ilbc.JavaEncoder",
G729
? "net.java.sip.communicator.impl.neomedia.codec.audio.g729.JavaEncoder"
? "net.java.sip.communicator.impl.neomedia.codec.audio.g729.JavaDecoder"
: null,
G729
? "net.java.sip.communicator.impl.neomedia.codec.audio.g729.JavaDecoder"
: null
? "net.java.sip.communicator.impl.neomedia.codec.audio.g729.JavaEncoder"
: null,
"net.java.sip.communicator.impl.neomedia.codec.audio.g722.JNIDecoder",
"net.java.sip.communicator.impl.neomedia.codec.audio.g722.JNIEncoder",
"net.java.sip.communicator.impl.neomedia.codec.video.h264.DePacketizer",
"net.java.sip.communicator.impl.neomedia.codec.video.h264.JNIDecoder",
"net.java.sip.communicator.impl.neomedia.codec.video.h264.JNIEncoder",
"net.java.sip.communicator.impl.neomedia.codec.video.h264.Packetizer",
"net.java.sip.communicator.impl.neomedia.codec.video.SwScaler"
};
/**
@ -184,8 +186,9 @@ public void initializeFormatPreferences()
setEncodingPreference("DVI4", 16000, 250);
setEncodingPreference("G723", 8000, 150);
setEncodingPreference("G728", 8000, 100);
// not selected by default as a proprietary one
setEncodingPreference("G729", 8000, 0);
setEncodingPreference("G722", 8000, 0);
setEncodingPreference("G729", 8000, 0 /* proprietary */);
// enables by default telephone event(DTMF rfc4733), with lowest
// priority as it is not needed to order it with audio codecs

@ -0,0 +1,121 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.neomedia.codec.audio.g722;
import javax.media.*;
import javax.media.format.*;
import net.java.sip.communicator.impl.neomedia.codec.*;
/**
*
* @author Lyubomir Marinov
*/
public class JNIDecoder
extends AbstractCodecExt
{
static final Format[] SUPPORTED_INPUT_FORMATS
= new Format[]
{
new AudioFormat(
Constants.G722_RTP,
8000,
Format.NOT_SPECIFIED /* sampleSizeInBits */,
1)
};
static final Format[] SUPPORTED_OUTPUT_FORMATS
= new Format[]
{
new AudioFormat(
AudioFormat.LINEAR,
16000,
16,
1,
AudioFormat.LITTLE_ENDIAN,
AudioFormat.SIGNED,
Format.NOT_SPECIFIED /* frameSizeInBits */,
Format.NOT_SPECIFIED /* frameRate */,
Format.byteArray)
};
static
{
System.loadLibrary("jg722");
}
private static native void g722_decoder_close(long decoder);
private static native long g722_decoder_open();
private static native void g722_decoder_process(
long decoder,
byte[] input, int inputOffset,
byte[] output, int outputOffset, int outputLength);
private long decoder;
/**
* Initializes a new <tt>JNIDecoder</tt> instance.
*/
public JNIDecoder()
{
super("G.722 JNI Decoder", AudioFormat.class, SUPPORTED_OUTPUT_FORMATS);
inputFormats = SUPPORTED_INPUT_FORMATS;
}
/**
*
* @see AbstractCodecExt#doClose()
*/
protected void doClose()
{
g722_decoder_close(decoder);
}
/**
*
* @throws ResourceUnavailableException
* @see AbstractCodecExt#doOpen()
*/
protected void doOpen()
throws ResourceUnavailableException
{
decoder = g722_decoder_open();
if (decoder == 0)
throw new ResourceUnavailableException("g722_decoder_open");
}
/**
*
* @param inputBuffer
* @param outputBuffer
* @return
* @see AbstractCodecExt#doProcess(Buffer, Buffer)
*/
protected int doProcess(Buffer inputBuffer, Buffer outputBuffer)
{
byte[] input = (byte[]) inputBuffer.getData();
int outputOffset = outputBuffer.getOffset();
int outputLength = inputBuffer.getLength() * 4;
byte[] output
= validateByteArraySize(outputBuffer, outputOffset + outputLength);
g722_decoder_process(
decoder,
input, inputBuffer.getOffset(),
output, outputOffset, outputLength);
outputBuffer.setDuration(
(outputLength * 1000000L)
/ (16L /* kHz */ * 2L /* sampleSizeInBits / 8 */));
outputBuffer.setFormat(getOutputFormat());
outputBuffer.setLength(outputLength);
return BUFFER_PROCESSED_OK;
}
}

@ -0,0 +1,142 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.neomedia.codec.audio.g722;
import javax.media.*;
import javax.media.format.*;
import net.java.sip.communicator.impl.neomedia.codec.*;
/**
* @author Lyubomir Marinov
*/
public class JNIEncoder
extends AbstractCodecExt
{
static
{
System.loadLibrary("jg722");
}
private static native void g722_encoder_close(long encoder);
private static native long g722_encoder_open();
private static native void g722_encoder_process(
long encoder,
byte[] input, int inputOffset,
byte[] output, int outputOffset, int outputLength);
private long encoder;
/**
* Initializes a new <tt>JNIEncoder</tt> instance.
*/
public JNIEncoder()
{
super(
"G.722 JNI Encoder",
AudioFormat.class,
JNIDecoder.SUPPORTED_INPUT_FORMATS);
inputFormats = JNIDecoder.SUPPORTED_OUTPUT_FORMATS;
}
/**
*
* @param length
* @return
*/
private long computeDuration(long length)
{
return (length * 1000000L) / 8L;
}
/**
*
* @see AbstractCodecExt#doClose()
*/
protected void doClose()
{
g722_encoder_close(encoder);
}
/**
*
* @throws ResourceUnavailableException
* @see AbstractCodecExt#doOpen()
*/
protected void doOpen()
throws ResourceUnavailableException
{
encoder = g722_encoder_open();
if (encoder == 0)
throw new ResourceUnavailableException("g722_encoder_open");
}
/**
*
* @param inputBuffer
* @param outputBuffer
* @return
* @see AbstractCodecExt#doProcess(Buffer, Buffer)
*/
protected int doProcess(Buffer inputBuffer, Buffer outputBuffer)
{
byte[] input = (byte[]) inputBuffer.getData();
int outputOffset = outputBuffer.getOffset();
int outputLength = inputBuffer.getLength() / 4;
byte[] output
= validateByteArraySize(outputBuffer, outputOffset + outputLength);
g722_encoder_process(
encoder,
input, inputBuffer.getOffset(),
output, outputOffset, outputLength);
outputBuffer.setDuration(computeDuration(outputLength));
outputBuffer.setFormat(getOutputFormat());
outputBuffer.setLength(outputLength);
return BUFFER_PROCESSED_OK;
}
/**
*
* @return
* @see net.sf.fmj.media.AbstractCodec#getOutputFormat()
*/
@Override
public Format getOutputFormat()
{
Format outputFormat = super.getOutputFormat();
if ((outputFormat != null)
&& (outputFormat.getClass() == AudioFormat.class))
{
AudioFormat outputAudioFormat = (AudioFormat) outputFormat;
setOutputFormat(
new AudioFormat(
outputAudioFormat.getEncoding(),
outputAudioFormat.getSampleRate(),
outputAudioFormat.getSampleSizeInBits(),
outputAudioFormat.getChannels(),
outputAudioFormat.getEndian(),
outputAudioFormat.getSigned(),
outputAudioFormat.getFrameSizeInBits(),
outputAudioFormat.getFrameRate(),
outputAudioFormat.getDataType())
{
@Override
public long computeDuration(long length)
{
return JNIEncoder.this.computeDuration(length);
}
});
}
return outputFormat;
}
}
Loading…
Cancel
Save