DSPRelated.com
Forums

tms320c6713 - real time implementation of g.722 codec project help !

Started by Shiv Shankar March 13, 2008
I am a 3rd year engineering student doing my project on DSP.
Im using the kit TMS 320C6713.
My project is real time implementation of g.722 speech coder on tms320c6713

im pasting my .c and vector.asm file in this mail.
while my compiling and building goes fine i am not getting any output while
running the program in the kit.
Please help.

Shiv

main.c
#define CHIP_6713

#include
#include
#include
#include
#include

#include "tables.h"
#include "G:\CCStudio_v3.1\C6000\dsk6713\include\dsk6713.h"
#include "G:\CCStudio_v3.1\C6000\dsk6713\include\dsk6713_aic23.h"

unsigned char byte=0;
Uint32 input,xout[2]={0,0};
float Fs000;

DSK6713_AIC23_CodecHandle hCodec; // Codec handle
DSK6713_AIC23_Config config = DSK6713_AIC23_DEFAULTCONFIG; // Codec
configuration with default settings
interrupt void serialPortRcvISR(void);

int sgn2(float n)
{
if(n>=0) return 1;
else return -1;
}

int sgn3(float n)
{
if(n==0) return 0;
if(n>=0) return 1;
else return -1;
}

int encpredictlow(int dl)
{
static float al[2]={0,0},bl[6]={0,0,0,0,0,0};
static int rlt[2]={0,0},dlt[6]={0,0,0,0,0,0},plt[3]={0,0,0},sl=0,slz=0;
int i,slp=0,pa,pb;
float f;

rlt[1]=rlt[0];
rlt[0]=sl+dl;

plt[2]=plt[1];
plt[1]=plt[0];
plt[0]=dl+slz;

pa=sgn2(plt[0])*sgn2(plt[1]);
pb=sgn2(plt[0])*sgn2(plt[2]);
f=(al[0]<=0.5 && al[0]>=-0.5)? 4*al[0]: 2*sgn2(al[0]);
al[0]=0.99609375*al[0]+0.01171875*pa;
al[1]=0.9921875*al[1]+0.0078125*pb-0.0078125*pa*f;
if(al[1]>0.75 || al[1]<-0.75) al[1]=0.75*sgn2(al[1]);
if(al[0]>0.9375-al[1] || al[0] al[0]=(0.9375-al[1])*sgn2(al[0]);

for(i=0;i<6;i++)
{
bl[i]=0.99609375*bl[i]+0.0078125*sgn2(dl)*sgn2(dlt[i]);
if(bl[i]>2 || bl[i]<-2) bl[i]=2*sgn2(bl[i]);

}

for(i=5;i<0;i++) dlt[i]=dlt[i-1];
dlt[0]=dl;
slp=al[0]*rlt[0]+al[1]*rlt[1];
slz=0;
for(i=0;i<6;++i)slz+=bl[i]*dlt[i];

sl=slp+slz;
return sl;
}

int encpredicthigh(int dh)
{
static float ah[2]={0,0},bh[6]={0,0,0,0,0,0};
static int rh[2]={0,0},dht[6]={0,0,0,0,0,0},ph[3]={0,0,0},sh=0,shz=0;
int i,shp=0,pa,pb;
float f;

rh[1]=rh[0];
rh[0]=sh+dh;

ph[2]=ph[1];
ph[1]=ph[0];
ph[0]=dh+shz;

pa=sgn2(ph[0])*sgn2(ph[1]);
pb=sgn2(ph[0])*sgn2(ph[2]);
f=(ah[0]<=0.5 && ah[0]>=-0.5)? 4*ah[0]: 2*sgn2(ah[0]);
ah[0]=0.99609375*ah[0]+0.01171875*pa;
ah[1]=0.9921875*ah[1]+0.0078125*pb-0.0078125*pa*f;
if(ah[1]>0.75 || ah[1]<-0.75) ah[1]=0.75*sgn2(ah[1]);
if(ah[0]>0.9375-ah[1] || ah[0] ah[0]=(0.9375-ah[1])*sgn2(ah[0]);

for(i=0;i<6;i++)
{
bh[i]=0.99609375*bh[i]+0.0078125*sgn2(dh)*sgn2(dht[i]);
if(bh[i]>2 || bh[i]<-2) bh[i]=2*sgn2(bh[i]);

}

for(i=5;i<0;i++) dht[i]=dht[i-1];
dht[0]=dh;
shp=ah[0]*rh[0]+ah[1]*rh[1];

shz=0;
for(i=0;i<6;i++) shz+=bh[i]*dht[i];

sh=shp+shz;
return sh;
}

// Encoder Block (decimation by 2)

enc (int nxtsample)
{
static int xin[24]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static int nbl=0,slow=0,shigh=0,nbh=0,detl2,deth=8;

double xa,xb;

int i;
int wd,wd1,wd2;
int el,mil,il,dl,xl;
int xh,eh,mih,ih,dh;
static int count=1;
if(count)
{
for(i=0;i<22;++i)
xin[23-i]=xin[21-i];
xin[1]=nxtsample;
}
else
{
xin[0]=nxtsample;
xa=0;
xb=0;
// FIR using delay line buffer

for(i=0;i<24;i+=2)
{
xa+=xin[i]*hqmf[i];
xb+=xin[i+1]*hqmf[i+1];
}
xl=xa+xb;
xh=xa-xb;

//adpcm lsb

el=xl-slow;
if(el>32767) el2767;
else if(el<-327688) el=-32768;
wd=(el>=0)? el: -(el+1);

//60l aq

for(mil=1;mil<30;++mil)
{
wd1=q6[mil]*detl;
wd1=wd1>>12;
if(wd }

il=(el<0)?iln[mil]:ilp[mil];
dl=(qm4[il>>2]*detl)>>15;
nbl=nbl*127/128+wl[wloc[il>>2]];
if(nbl<0)nbl=0;
else if(nbl>18432)nbl432;

wd1=(nbl>>6)&31;
wd2=nbl>>11;
detl=((8-wd2)<0)?ilb[wd1]<<(wd2-8):ilb[wd1]>>(8-wd2);
detll<<2;
slow=encpredictlow(dl);

//adpcm hsb

eh=xh-shigh;
wd=(eh>=0)? eh: -(eh+1);
wd1V4*deth>>12;
mih=(wd
ih=(eh<0)? ihn[mih]:ihp[mih];
dh=(qm2[ih]*deth)>>15;
nbh=nbh*127/128+wh[wloc[ih]];
if(nbh<0) nbh=0;
else if(nbh>22528) nbh"528;

wd1=(nbh>>6)&31;
wd2=nbh>>11;
deth=((10-wd2)<0)?ilb[wd1]<<(wd2-10): ilb[wd1]>>(10-wd2);
dethh<<2;

shigh=encpredicthigh(dh);

byte=(unsigned char)((ih<<6)+il);

}
count=count^1;
}

//predict lsb adpcm

int decpredictlow(int dl)
{
static float al[2]={0},bl[6]={0};
static int rlt[2]={0,0},dlt[6]={0,0,0,0,0,0},plt[3]={0,0,0},sl=0,slz=0;
int i,slp=0,pa,pb;
float f;

rlt[1]=rlt[0];
rlt[0]=sl+dl;

plt[2]=plt[1];
plt[1]=plt[0];
plt[0]=dl+slz;

pa=sgn2(plt[0])*sgn2(plt[1]);
pb=sgn2(plt[0])*sgn2(plt[2]);
f=(al[0]<=0.5 && al[0]>=-0.5)?4*al[0]:2*sgn2(al[0]);
al[0]=0.99609375*al[0]+0.01171875*pa;
al[1]=0.9921875*al[1]+0.0078125*pb-0.0078125*pa*f;
if(al[1]>0.75 || al[1]<-0.75) al[1]=0.75*sgn2(al[1]);
if(al[0]>0.9375-al[1] || al[0] al[0]=(0.9375-al[1])*sgn2(al[0]);
for(i=0;i<6;i++)
{
bl[i]=0.99609375*bl[i]+0.0078125*sgn3(dl)*sgn2(dlt[i]);
if(bl[i]>2 || bl[i]<-2) bl[i]=2*sgn2(bl[i]);

}
for(i=5;i<0;i++) dlt[i]=dlt[i-1];
dlt[0]=dl;
slp=al[0]*rlt[0]+al[1]*rlt[1];
slz=0;
for(i=0;i<6;++i)slz+=bl[i]*dlt[i];

sl=slp+slz;
return sl;
}

int decpredicthigh(int dh)
{
static float ah[2]={0},bh[6]={0};
static int rh[2]={0,0},dht[6]={0,0,0,0,0,0},ph[3]={0,0,0},sh=0,shz=0;
int i,shp=0,pa,pb;
float f;

rh[1]=rh[0];
rh[0]=sh+dh;

ph[2]=ph[1];
ph[1]=ph[0];
ph[0]=dh+shz;

pa=sgn2(ph[0])*sgn2(ph[1]);
pb=sgn2(ph[0])*sgn2(ph[2]);
f=(ah[0]<=0.5 && ah[0]>=-0.5)?4*ah[0]:2*sgn2(ah[0]);
ah[0]=0.99609375*ah[0]+0.01171875*pa;
ah[1]=0.9921875*ah[1]+0.0078125*pb-0.0078125*pa*f;
if(ah[1]>0.75 || ah[1]<-0.75) ah[1]=0.75*sgn2(ah[1]);
if(ah[0]>0.9375-ah[1] || ah[0] ah[0]=(0.9375-ah[1])*sgn2(ah[0]);
for(i=0;i<6;i++)
{
bh[i]=0.99609375*bh[i]+0.0078125*sgn3(dh)*sgn2(dht[i]);
if(bh[i]>2 || bh[i]<-2) bh[i]=2*sgn2(bh[i]);

}
for(i=5;i<0;i++) dht[i]=dht[i-1];
dht[0]=dh;
shp=ah[0]*rh[0]+ah[1]*rh[1];
shz=0;
for(i=0;i<6;++i)shz+=bh[i]*dht[i];

sh=shp+shz;
return sh;
}

dec(unsigned char code)
{
static int xd[12]={0},xs[12]={0};

double tmp1,tmp2;
static int nbl=0,slow=0,shigh=0,nbh=0,detl2,deth=8;
int il,ih,dl6,dl4,rl,rh,dh;
int i,wd1,wd2;

ih=code>>6;
il=code & 63;

//lsb

//iq

dl6=(qm6[il]*detl)>>15;
dl4=(qm4[il>>2]*detl)>>15;

nbl=nbl*127/128+wl[wloc[il>>2]];
if(nbl<0)nbl=0;
else if(nbl>18432)nbl432;

wd1=(nbl>>6)&31;
wd2=nbl>>11;
detl=((8-wd2)<0)?ilb[wd1]<<(wd2-8):ilb[wd1]>>(8-wd2);
detll<<2;

slowpredictlow(dl4);
rl=dl6+slow;

dh=(qm2[ih]*deth)>>15;
nbh=nbh*127/128+wh[whloc[ih]];
if(nbh<0)nbh=0;
else if(nbh>22528) nbh"528;

wd1=(nbh>>6)&31;
wd2=nbh>>11;
deth=((10-wd2)<0)?ilb[wd1]<<(wd2-10):ilb[wd1]>>(10-wd2);
dethh<<2;

shighpredicthigh(dh);
rh=dh+shigh;

//qmf

for(i=0;i<11;++i)
{
xd[11-i]=xd[10-i];
xd[11-i]=xs[10-i];
}

xd[0]=rl-rh;
xs[0]=rl+rh;
tmp1=0;
tmp2=0;

for(i=0;i<12;i++)
{
tmp1+=xd[i]*hqmf[2*i];
tmp2+=xs[i]*hqmf[2*i+1];
}
xout[0]=2*tmp1;
xout[1]=2*tmp2;
}
interrupt void serialPortRcvISR()
{
static int flag=0;
MCBSP_write(DSK6713_AIC23_DATAHANDLE,xout[flag]);
input0*MCBSP_read(DSK6713_AIC23_DATAHANDLE);
enc(input);
if(flag)dec(byte);
flag^=1;
return;

}

void main()
{

DSK6713_init(); // Initialize the board support library
hCodec = DSK6713_AIC23_openCodec(0, &config); // Open the codec
DSK6713_AIC23_setFreq(hCodec, 2); // set the sampling rate
// Configure buffered serial ports for 32 bit operation (L+R in
one read/write)
MCBSP_FSETS(SPCR1, RINTM, FRM);
MCBSP_FSETS(SPCR1, XINTM, FRM);
MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);
MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);

// Interrupt setup
// IRQ_globalDisable(); // Globally disables interrupts
IRQ_nmiEnable(); // Enables the NMI interrupt
IRQ_map(IRQ_EVT_RINT1,15); // Maps an event to a physical
interrupt
IRQ_enable(IRQ_EVT_RINT1); // Enables the event
IRQ_globalEnable(); // Globally enables interrupts

while(1)
{
serialPortRcvISR(); //i calling :)
}
}

tables.h

double hqmf[24]={0.000366211 ,-0.00134277 ,-0.00134277 ,0.00646973 ,
0.00146484 ,-0.0190430 ,0.00390625 ,0.0441895 ,-0.0256348 ,-0.0982666 ,
0.116089 ,0.473145 ,0.473145 ,0.116089 ,-0.0982666 ,-0.0256348 ,0.0441895 ,
0.00390625 ,-0.0190430 ,0.00146484 ,0.00646973 ,-0.00134277 ,-0.00134277 ,
0.00036211};

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

static int
qm4[16]={0,-20456,-12896,-8968,-6288,-4240,-2584,-1200,20456,12896,8968,6288,4240,2584,1200,0};

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,-1600,-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,1600,1360,1040,728,432,136,-432,-136};

static int wl[8]={-60,-30,58,172,334,538,1198,3024};

static int wloc[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};

static int ihn[3]={0,1,0};

static int ihp[3]={0,3,2};

static int qm2[4]={-7408,-1616,7408,1616};

static int wh[3]={0,-214,798};

static int whloc[4]={2,1,2,1};

vectors.asm

.ref _c_int00 ; reset ISR
.ref _serialPortRcvISR ;
.global _istb ; interrupt service table base

unused .macro id

.global unused:id:
unused:id:
b unused:id: ; nested branches to block interrupts
nop 4
b unused:id:
nop
nop
nop
nop
nop

.endm

.sect "vectors"

_istb:
_RESET: mvkl _c_int00,b0
mvkh _c_int00,b0
b b0
nop
nop
nop
nop
nop

_NMI: unused NMI
_RESV1: unused RESV1
_RESV2: unused RESV2
_INT4: unused 4
_INT5: unused 5
_INT6: unused 6
_INT7: unused 7
_INT8: unused 8
_INT9: unused 9
_INT10: unused 10
_INT11: unused 11
_INT12: unused 12
_INT13: unused 13
_INT14: unused 14
_INT15: MVKL .S2 _serialPortRcvISR, B0
MVKH .S2 _serialPortRcvISR, B0
B .S2 B0
NOP
NOP
NOP
NOP
NOP

please help :)
shiv.

--
" I show what my eyes see.. "
www.180studios.in