📄 thrdecode.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)" */
/*
* ======== thrDecode.c ========
*
* Static and dynamic initialization of thread Decode,
* 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 "thrDecode.h" /* definition of thrDecode 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.
*/
ThrDecode thrDecode = {
/* algorithm handle(s) (to be initialized in runtime) */
NULL, /* algG726DEC */
/* input pipe(s) */
&pipRxUart, /* pipIn */
/* output pipe(s) */
&pipTxCodec, /* pipOut */
/* buffer(s) */
bufAudioproc, /* bufInterm */
/* everything else private for the thread */
};
/*
* Dynamic part of thread initialization
*/
/*
* ========= thrDecodeInit ========
* Initialization of data structures for the thread(s), called from
* appThreads.c:thrInit() at init time.
*
* Here we create one instance of G726DEC algorithm. Then We create
* parameters for algorithm instance by using the default
* parameters and modifying fields that are different.
*/
Void thrDecodeInit( Void )
{
/* declaration of g726 decoder parameter structures */
G726DEC_Params g726decParams;
/*
* Set the parameters structure to the default, i.e.
* the one used in i<alg>.c, and modify fields that are different.
*/
g726decParams = G726DEC_PARAMS; /* default parameters */
g726decParams.frameLen = FRAMELEN; /* size in samples */
g726decParams.mode = IG726_LINEAR; /* linear mode */
/* create instance, confirm creation success, show memory usage */
thrDecode.algG726DEC = G726DEC_create( &G726DEC_IG726DEC, &g726decParams );
UTL_assert( thrDecode.algG726DEC != NULL );
UTL_showAlgMem( thrDecode.algG726DEC );
}
/*
* Runtime thread code, invoked by the appropriate SWI object
* every time the object is posted
*/
Void thrDecodeRun()
{
Sample *src, *dst;
Int size, i; /* in samples */
/*
* Check if the codec output pipe is completly empty, if so, allocate
* one buffer of silence to the codec to prime the codec output.
*/
if (PIP_getWriterNumFrames(thrDecode.pipOut) == 2) {
PIP_alloc ( thrDecode.pipOut );
memset(PIP_getWriterAddr (thrDecode.pipOut),
0 ,PIP_getWriterSize (thrDecode.pipOut));
PIP_put ( thrDecode.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( thrDecode.pipIn ) > 0 );
UTL_assert( PIP_getWriterNumFrames( thrDecode.pipOut ) > 0 );
/* get the full buffer from the input pipe */
PIP_get( thrDecode.pipIn );
src = PIP_getReaderAddr( thrDecode.pipIn );
/* get the size in samples (the function below returns it in words) */
size = sizeInSamples( PIP_getReaderSize( thrDecode.pipIn ) );
/* get the empty buffer from the out-pipe */
PIP_alloc( thrDecode.pipOut );
dst = PIP_getWriterAddr( thrDecode.pipOut );
/* unpack received buffer to an intermediate buffer before processing it */
for (i = 0; i < size * 4; i = i + 4) {
thrDecode.bufInterm[i] = *src & 0x03;
thrDecode.bufInterm[i+1] = (*src >> 2) & 0x03;
thrDecode.bufInterm[i+2] = (*src >> 4) & 0x03;
thrDecode.bufInterm[i+3] = (*src >> 6) & 0x03;
src++;
}
/* apply G726 decoder algorithm on the intermediate buffer */
G726DEC_apply(thrDecode.algG726DEC,
(XDAS_Int8 *)thrDecode.bufInterm, (XDAS_Int16 *)dst );
/* Record the amount of actual data being sent */
PIP_setWriterSize( thrDecode.pipOut, sizeInWords( size * 4 ) );
/* Free the receive buffer, put the transmit buffer */
PIP_free( thrDecode.pipIn );
PIP_put ( thrDecode.pipOut );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -