⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo.c

📁 DSP 基于 TMS320C6711 DSK 的功能演示程序
💻 C
字号:
/*
 *  Copyright 2001 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  U.S. Patent Nos. 5,283,900  5,392,448
 */
/* "@(#) XDAS 2.12 05-21-01 (__imports)" */
/*
 *  ======== demo.c ========
 *
 */

#include <std.h>

#include <clk.h>
#include <log.h>
#include <pip.h>
#include <swi.h>

#include <lec.h>  

#include <utl.h>

#include <demo.h>
#include <dss.h>


#include <g723dec.h>
#include <g723enc.h>




#define FRAMELEN    240
#define CODELEN     240

/* Host controllable parameters */
Int encodeEnable = FALSE;
Int cancelEnable = FALSE;
UTL_Load cancelLoad = {0, 0};
UTL_Load encodeLoad = {0, 0};
UTL_Load decodeLoad = {0, 0};

/* anonymous algorithm names */      

extern Far IG723DEC_Fxns G723DEC_IG723DEC;
extern Far IG723ENC_Fxns G723ENC_IG723ENC;    




extern Far ILEC_Fxns LEC_ILEC;

/* algorithm object handles (initialized in init()) */ 

static G723ENC_Handle encoder;
static G723DEC_Handle decoder; 




static LEC_Handle canceller;

/* The following external objects are defined in the config file audio.cdb */
extern far LOG_Obj trace;       /* application printf() log */   
  
extern far PIP_Obj lineIn, lineOut;         /* 8KHz PCM input/output FRAMELEN */
extern far PIP_Obj encoderIn;               /* 8KHz PCM input, FRAMELEN */
extern far PIP_Obj decoderIn;               /* coded samples, CODELEN */
extern far PIP_Obj farEnd;                  /* teed lineOut, FRAMELEN */

static Void init(Void);
static Void initDec(Void);
static Void initEnc(Void);
static Void initLec(Void);
static Void nullAlg(UTL_Load *load, Void *src, Void *dst, Int size);
static Void initGuiState(Void);


static Void packInPlace(XDAS_Int32 *in1, Int framelen);
static Void unpkInPlace(XDAS_Int16 *in1, Int framelen);


/*
 *  ======== main ========
 */
Void main()
{   
    DSS_init();         /* initialize the DSS driver */
        
    UTL_bind(&trace);   /* set trace output log */
    
    init();             /* initialize the application */

    LOG_printf(&trace, "Demo started.");

    /* fall into BIOS idle loop */
    return;                 
}

/*
 *  ======== cancel ========
 */
static Void cancel(PIP_Obj *in1, PIP_Obj *in2, PIP_Obj *out)
{
    Uns *src1, *src2, *dst;
    LgUns tBegin, tEnd;  
   
    UTL_assert(in1->readerNumFrames != 0 && in2->readerNumFrames != 0 && out->writerNumFrames != 0);

    /* get input data and allocate output buffer */
    PIP_get(in1);
    PIP_get(in2);
    PIP_alloc(out);

    UTL_assert(in1->readerSize == FRAMELEN && out->writerSize == FRAMELEN);
    
    /* cancel echo in src1 buffer and put result in dst */
    src1 = in1->readerAddr;     /* near-end input */
    src2 = in2->readerAddr;     /* far-end input */
    dst = out->writerAddr;      /* near-end cancelled result */


    packInPlace ((XDAS_Int32 *) src1, FRAMELEN);


    if (cancelEnable != FALSE) {
        tBegin = CLK_gethtime();    /* start timer */   

        /* zero out far-end since there's no echo on input */
        memset(src2, 0, FRAMELEN * sizeof(XDAS_Int16));

        LEC_apply(canceller, (XDAS_Int16 *)src2, (XDAS_Int16 *)src1,
                (XDAS_Int16 *)dst);
        
        tEnd = CLK_gethtime();      /* mark end of interval */

        STS_add(&echoCancellerExecTime, (tEnd - tBegin));
    }
    else {
        nullAlg(&cancelLoad, src1, dst, FRAMELEN * sizeof (XDAS_Int16));
    }
    
    /* output copied data and free input buffer */
    PIP_put(out);
    PIP_free(in1);
    PIP_free(in2);
}

/*
 *  ======== decode ========
 */
static Void decode(PIP_Obj *in, PIP_Obj *out, PIP_Obj *echo)
{
    Uns *src, *dst;
    LgUns tBegin, tEnd;
    
    UTL_assert(in->readerNumFrames != 0 && out->writerNumFrames != 0
        && echo->writerNumFrames != 0);

    /* get input data and allocate output buffer */
    PIP_get(in);
    PIP_alloc(out);
    PIP_alloc(echo);

    UTL_assert(in->readerSize <= out->writerSize && out->writerSize == FRAMELEN);

    /* decode encoded frame of input data to output frame */
    src = in->readerAddr;
    dst = out->writerAddr;
    if (encodeEnable != FALSE) {
        tBegin = CLK_gethtime();    /* record time */   


        G723DEC_apply(decoder, (XDAS_Int8 *)src, (XDAS_Int16 *)dst);




        tEnd = CLK_gethtime();
        STS_add(&decoderExecTime, (tEnd - tBegin));
    }
    else {
        nullAlg(&decodeLoad, src, dst, FRAMELEN * sizeof (XDAS_Int16));
    }

    /* copy decoders output data (far-end input) to echo canceller */
    src = out->writerAddr;
    dst = echo->writerAddr;
    memcpy(dst, src, FRAMELEN * sizeof(XDAS_Int16));


    unpkInPlace((XDAS_Int16 *)src, FRAMELEN);


    /* output data buffers and free input buffer */
    PIP_put(out);
    PIP_put(echo);
    PIP_free(in);
}

/*
 *  ======== encode ========
 */
static Void encode(PIP_Obj *in, PIP_Obj *out)
{
    Uns *src, *dst;
    LgUns tBegin, tEnd;
    
    UTL_assert(in->readerNumFrames != 0 && out->writerNumFrames != 0);

    /* get input data and allocate output buffer */
    PIP_get(in);
    PIP_alloc(out);

    UTL_assert(in->readerSize >= out->writerSize && out->writerSize == CODELEN);

    /* encode input data and put result in output buffer */
    src = in->readerAddr;
    dst = out->writerAddr;
    if (encodeEnable != FALSE) {      
        tBegin = CLK_gethtime();    /* record time */   

        G723ENC_apply(encoder, (XDAS_Int16 *)src, (XDAS_Int8 *)dst);



        tEnd = CLK_gethtime();
        STS_add(&encoderExecTime, (tEnd - tBegin));
    }
    else {
        nullAlg(&encodeLoad, src, dst, CODELEN * sizeof (XDAS_Int16));
    }

    /* output copied data and free input buffer */
    PIP_put(out);
    PIP_free(in);
}

/*
 *  ======== init ========
 *  Create and initialize all DAIS algorithm objects
 */
static Void init(Void)
{
    initLec();

 
    initEnc();
    initDec();
            

    initGuiState();
}

/*
 *  ======== initDec ========
 *  Create and initialize decoder objects
 */
static Void initDec(Void)
{        

    G723DEC_Params decParams = G723DEC_PARAMS;
    Int insMemorySize;
    
    /* get alg. instance data memory usage and report to host */
    insMemorySize = getInstanceMemorySize((IALG_Fxns *) &G723DEC_IG723DEC,
        (IALG_Params *)&decParams);                               

    STS_add(&decoderDataSize, insMemorySize); 
    
     /* create and initialize decoder object */
    decoder = G723DEC_create(&G723DEC_IG723DEC, &decParams);

    UTL_assert(decoder != NULL);



}

/*
 *  ======== initEnc ========
 *  Create and initialize encoder objects
 */
static Void initEnc(Void)
{

    G723ENC_Params encParams = G723ENC_PARAMS;
    Int insMemorySize;

    /* get alg. instance data memory usage and report to host */
    insMemorySize = getInstanceMemorySize((IALG_Fxns *) &G723ENC_IG723ENC,
        (IALG_Params *)&encParams);                               

    LOG_printf(&trace, "Encoder: G.723 data section is %d MAUs\n", insMemorySize);
    STS_add(&encoderDataSize, insMemorySize); 
    
    /* create and initialize encoder object */
    encoder = G723ENC_create(&G723ENC_IG723ENC, &encParams);

    UTL_assert(encoder != NULL);  



}

/*
 *  ======== initLec ========
 *  Create and initialize echo canceller objects
 */
static Void initLec(Void)
{
    LEC_Params lecParams = LEC_PARAMS;
    Int insMemorySize;
    
    /* get alg. instance data memory usage and report to host */
    insMemorySize = getInstanceMemorySize((IALG_Fxns *) &LEC_ILEC,
        (IALG_Params *)&lecParams);                               

    LOG_printf(&trace, "LEC: G.165 data section is %d MAUs\n", insMemorySize);
    STS_add(&echoCancellerDataSize, insMemorySize); 

    /* create and initialize echo canceller instance object */
    lecParams.frameLen = FRAMELEN;         
    canceller = LEC_create(&LEC_ILEC, &lecParams);

    UTL_assert(canceller != NULL);
        
    /* prime the feedback pipe for the echo canceller */
    UTL_assert(farEnd.writerNumFrames != 0);
    PIP_alloc(&farEnd);
    UTL_assert(FRAMELEN <= farEnd.writerSize);
    memset(farEnd.writerAddr, 0, FRAMELEN * sizeof (XDAS_Int16));
    PIP_put(&farEnd);
}

/*
 *  ======== initGuiState ========
 */    
Void initGuiState(Void)
{       
    extern  ChannelObject channel[];
    Int   m;

    channel[0].lec = canceller;
    channel[0].enc = encoder;
    channel[0].dec = decoder;   
    channel[1].lec = canceller;
    channel[1].enc = encoder;
    channel[1].dec = decoder;   
        
    /* initialize options regs/structure to zero */
    hostUpdate = 0;

    /* disable all channel specific options */

    for (m=1;m < DEMO_MAX_CHANNELS;m++) {
        channel[m].selections = 0;
    }                                                  

}                                                       

/*
 *  ======== nullAlg ========
 */
static Void nullAlg(UTL_Load *load, Void *src, Void *dst, Int size)
{
    memcpy(dst, src, size);     /* copy source to destination */
    UTL_load(load, load);       /* simulate a load on the CPU */
}

/*
 *  ======== cancelFxn ========
 */
Void cancelFxn(Void)
{
    cancel(&lineIn, &farEnd, &encoderIn);
}

/*
 *  ======== encoderFxn ========
 */
Void encoderFxn(Void)
{
    encode(&encoderIn, &decoderIn);
}

/*
 *  ======== decoderFxn ========
 */
Void decoderFxn(Void)
{
    decode(&decoderIn, &lineOut, &farEnd);
}


/*
 *  ======== packInPlace ========
 */
static Void packInPlace(XDAS_Int32 *in1, Int framelen)
{
    Int i;

    for (i=0; i<framelen; i++) {
        ((XDAS_Int16 *)in1)[i] = (XDAS_Int16)in1[i];
    }
}


/*
 *  ======== unpkInPlace ========
 */
static Void unpkInPlace(XDAS_Int16 *in1, Int framelen)
{
    Int i;

    for (i=framelen-1; i>=0; i--) {
        ((XDAS_Int32 *)in1)[i] = in1[i] & 0xfffe;       /* mask for AD535 */
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -