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

📄 threncode.c

📁 g.726编解码源程序
💻 C
字号:
/*
 *  Copyright 2002 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.
 *  
 */
/* "@(#) RF3_UART_G726 1.00.00 07-18-02 (swat-c03)" */
/*
 *  ======== thrEncode.c ========
 *
 *  Static and dynamic initialization of thread Encode,
 *  and its runtime procedure
 */
#include <std.h>
#include <pip.h>

#include <utl.h>                /* debug/diagnostics utility functions */

#include "appResources.h"       /* application-wide common info */
#include "appThreads.h"         /* thread-wide common info */
#include "thrEncode.h"          /* definition of thrEncode objects */

/*
 *  Static part of thread initialization
 */

/* 
 *  Initialization of the thread resources structure:
 *  NULL for algorithm handles, addresses of appropriate 
 *  CDB-defined pipe objects for input and output pipes,
 *  NULL for globally visible temporary pointers to pipe frames,
 *  addresses of intermediate buffers for this thread,
 *  and everything else thread-specific.
 */
ThrEncode thrEncode = {
        /* algorithm handle(s) (to be initialized in runtime) */
        NULL,                       /* algG726ENC */
    
        /* input pipe(s) */
        &pipRxCodec,                /* pipIn */

        /* output pipe(s) */
        &pipTxUart,                 /* pipOut */

        /* buffer(s) */
        bufAudioproc,               /* bufInterm */
    
        /* everything else private for the thread */
};

/*
 *  Dynamic part of thread initialization
 */

/*
 *  ========= thrEncodeInit ========
 *  Initialization of data structures for the thread(s), called from 
 *  appThreads.c:thrInit() at init time.
 *
 *  Here we create one instance of G726ENC algorithm. Then We create
 *  parameters for algorithm instance by using the default
 *  parameters and modifying fields that are different.
 */
Void thrEncodeInit( Void ) 
{
    /* declaration of g726 encoder parameter structures */
    G726ENC_Params g726encParams;

    /* 
     *  Set the parameters structure to the default, i.e. 
     *  the one used in i<alg>.c, and modify fields that are different.
     */
    g726encParams = G726ENC_PARAMS;        /* default parameters */
    g726encParams.frameLen  = FRAMELEN;    /* size in samples */
    g726encParams.mode = IG726_LINEAR;     /* linear mode */

    /* create instance, confirm creation success, show memory usage */
    thrEncode.algG726ENC = G726ENC_create( &G726ENC_IG726ENC, &g726encParams );
    UTL_assert( thrEncode.algG726ENC != NULL );
    UTL_showAlgMem( thrEncode.algG726ENC );
}    

/*
 *  Runtime thread code, invoked by the appropriate SWI object
 *  every time the object is posted
 */

Void thrEncodeRun() 
{
    Sample *src, *dst;
    Int     size, i;       /* in samples */

    /*
     *  put the frame containing the previous buffer now, to start
     *  outputing it through the UART
     */
    PIP_put( thrEncode.pipOut );
    
    /*
     *  Check that the preconditions are met, that is the in-pipe 
     *  has a ready-to-consume buffer of data and the out-pipe 
     *  has a free buffer, in other words that this thread has
     *  not been posted in error.
     */
    UTL_assert( PIP_getReaderNumFrames( thrEncode.pipIn  ) > 0 );
    UTL_assert( PIP_getWriterNumFrames( thrEncode.pipOut ) > 0 );

    /* get the full buffer from the input pipe */
    PIP_get( thrEncode.pipIn );
    src = PIP_getReaderAddr( thrEncode.pipIn );
    /* get the size in samples (the function below returns it in words) */
    size = sizeInSamples( PIP_getReaderSize( thrEncode.pipIn ) );

    /* get the empty buffer from the out-pipe */
    PIP_alloc( thrEncode.pipOut );
    dst = PIP_getWriterAddr( thrEncode.pipOut );

    /* Encode the signal in the src. buffer and store result in the Interim buf */
    G726ENC_apply( thrEncode.algG726ENC,
               (XDAS_Int16 *)src, (XDAS_Int8 *)(thrEncode.bufInterm));

    /* pack the interim buffer before transmitting it to reduce the data flow */
    for (i = 0; i < size; i=i+4) {
        *dst++ =  (Sample) ((thrEncode.bufInterm[i] & 0x03) +
                  ((thrEncode.bufInterm[i+1] & 0x03) << 2) +
                  ((thrEncode.bufInterm[i+2] & 0x03) << 4) +
                  ((thrEncode.bufInterm[i+3] & 0x03) << 6));
    }

    
    /* Record the amount of actual data being sent */
    PIP_setWriterSize( thrEncode.pipOut, sizeInWords( size / 4) );

    /* Free the receive buffer, put the transmit buffer */
    PIP_free( thrEncode.pipIn  );
}


⌨️ 快捷键说明

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