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

📄 demo.c

📁 使用在dsp TI DSK6711中 很多controller 的例子
💻 C
字号:
/*

 *  Copyright 2003 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.

 *

 *  @(#) XDAS 2.51.00 11-29-2003 (xdas-2.50.00.9)

 */

/*

 *  ======== 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>



#ifdef _62_

#include <g723dec.h>

#include <g723enc.h>

#endif



#ifdef _54_

#include <g726dec.h>

#include <g726enc.h>

#endif



#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 */      

#ifdef _62_

extern Far IG723DEC_Fxns G723DEC_IG723DEC;

extern Far IG723ENC_Fxns G723ENC_IG723ENC;    

#endif



#ifdef _54_

extern Far IG726DEC_Fxns G726DEC_IG726DEC;

extern Far IG726ENC_Fxns G726ENC_IG726ENC;    

#endif



extern Far ILEC_Fxns LEC_ILEC;



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

#ifdef _62_

static G723ENC_Handle encoder;

static G723DEC_Handle decoder; 

#endif



#ifdef _54_

G726ENC_Handle encoder;

G726DEC_Handle decoder; 

#endif



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 primeOutput(Void);



#ifdef _62_

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

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

#endif

/*

 *  ======== main ========

 */

Void main()

{   

    DSS_init();         /* initialize the DSS driver */

        

    UTL_bind(&trace);   /* set trace output log */

    

    init();             /* initialize the application */



    primeOutput();      /* Prime output with 2 silences */



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



#ifdef _62_ 

    packInPlace ((XDAS_Int32 *) src1, FRAMELEN);

#endif



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



#ifdef _62_        

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

#endif



#ifdef _54_

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

#endif    



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



#ifdef _62_

    unpkInPlace((XDAS_Int16 *)src, FRAMELEN);

#endif



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

#ifdef _62_          

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

#endif



#ifdef _54_

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

#endif    

        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)

{        

#ifdef _62_

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

#endif /* _62_ */



#ifdef _54_

    G726DEC_Params decParams = G726DEC_PARAMS;

    Int insMemorySize; 

        

    /* get alg. instance data memory usage and report to host */

    insMemorySize = getInstanceMemorySize((IALG_Fxns *) &G726DEC_IG726DEC,

        (IALG_Params *)&decParams);                               



    LOG_printf(&trace, "Decoder: G.726 data section is %d MAUs\n", insMemorySize);

    STS_add(&decoderDataSize, insMemorySize); 



    decParams.frameLen = FRAMELEN;

    decParams.rate = G726DEC_24KBPS;

    decParams.mode = G726DEC_LINEAR;

    

    decoder = G726DEC_create(&G726DEC_IG726DEC, &decParams);



    UTL_assert(decoder != NULL);

#endif /* _54_ */ 

}



/*

 *  ======== initEnc ========

 *  Create and initialize encoder objects

 */

static Void initEnc(Void)

{

#ifdef _62_

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

#endif /* _62_ */



#ifdef _54_

    G726ENC_Params encParams = G726ENC_PARAMS;

    Int insMemorySize = 1;

    

    /* get alg. instance data memory usage and report to host */

    insMemorySize = getInstanceMemorySize((IALG_Fxns *) &G726ENC_IG726ENC,

        (IALG_Params *)&encParams);                               



    LOG_printf(&trace, "Encoder: G.726 data section is %d MAUs\n", insMemorySize);

    STS_add(&encoderDataSize, insMemorySize); 



    encParams.frameLen = FRAMELEN;

    encParams.rate = G726ENC_24KBPS;

    encParams.mode = G726ENC_LINEAR;

    

    encoder = G726ENC_create(&G726ENC_IG726ENC, &encParams); 



    UTL_assert(encoder != NULL);  

#endif /* _54_ */

}



/*

 *  ======== 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);

}



#ifdef _62_

/*

 *  ======== 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 */

    }

}

#endif



/* 

 * These macros are used to work-around a problem with 'notifyWriter'

 * calls when priming the output, similar to PLIO_txStart() in RF3

 * which employs the same technique

 */

#define getNotifyWriterFxn(pip)         ((pip)->notifyWriter.fxn)

#define setNotifyWriterFxn(pip, notify) ((pip)->notifyWriter.fxn = (notify))



/*

 *  ======== primeOutput ========

 *  This function primes the output with 2 silences to ensure

 *  that processing can take up to one buffer-worth of time 

 *  without missing any real time deadlines (see the Application

 *  Priming section in spra787 for more details)

 */

static Void primeOutput(Void)

{ 

    Int size;

    Uns *buf;

    Int i;

    Fxn         notifySave;



    /*

     * Work-around notifyWriter problem at startup.

     * Without this work-around, the PIP_alloc() calls below cause

     * notifyWriter to be called and the application to have incorrect

     * view of the PIP state (application thinks an empty output frame

     * is available when no frame is actually available).

     */

    notifySave = getNotifyWriterFxn(&DSS_txPipe);

    setNotifyWriterFxn(&DSS_txPipe, (Fxn)FXN_F_nop);

        

    for (i = 0; i < 2; i++)

    {

        PIP_alloc(&DSS_txPipe);

        buf = PIP_getWriterAddr(&DSS_txPipe);

        size = PIP_getWriterSize(&DSS_txPipe);

        memset(buf, 0, size * sizeof (Uns));

        PIP_setWriterSize(&DSS_txPipe, size);

        PIP_put(&DSS_txPipe);

    }



    /* restore notifyWriter function to its' configured state */

    setNotifyWriterFxn(&DSS_txPipe, notifySave);

}



⌨️ 快捷键说明

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