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

📄 thraudioproc.c

📁 dm642上的h264源码
💻 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.
 *  
 */
/* "@(#) ReferenceFrameworks 2.10.00.11 04-30-03 (swat-d15)" */
/*
 *  ======== thrAudioproc.c ========
 *
 *  Static and dynamic initialization of thread Audioproc,
 *  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 "thrAudioproc.h"   /* definition o
//#pragma DATA_SECTION(byteAudio,  ".AUDIOf thrAudioproc objects */
#include "g72x.h"   		/* definition of g.721 functions*/


//static unsigned short byteAudio[MAX_BUFFER_NUM][20];//FRAMELEN/4=20,压缩率为4倍;
AUDIOBUFFER AudioEncBuf[2];
AUDIOBUFFER AudioDecBuf[2];
/*
 *  Static part of thread initialization
 */
struct g72x_state state_en;
struct g72x_state state_de;


int sizeAudio,codBufNum,decBufNum;
unsigned short deNum,deCnt;       /* in samples */

extern unsigned short codNum;
extern unsigned short *pAudioEncBuf;
extern unsigned short *pAudioDecBuf;//解码空闲区指针
/* 
 *  Initialization of the thread resources structure:
 *  NULL for algorithm handles, addresses of appropriate 
 *  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.
 */
ThrAudioproc thrAudioproc[ NUMCHANNELS ] = {
    { /* channel #0 */
          
        /* input pipe(s) */
        &pipRx,                /* pipIn */

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

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

/* 
 *  FIR filter coefficients: each channel runs a different instance of
 *  the FIR algorithm, and we initialize each instance with a different
 *  filter, i.e. with a different set of coefficients. In this example,
 *  channel #0 is a low-pass filter, and channel #1 is a hi-pass filter.
 */

/*
 *  Dynamic part of thread initialization
 */

/*
 *  ========= thrAudioprocInit ========
 *  Initialization of data structures for the thread(s), called from 
 *  appThreads.c:thrInit() at init time.
 *
 *  Here we create one instance of FIR algorithm per channel and
 *  one instance of VOL algorithm per channel. In a loop, we create
 *  parameters for algorithm instance for each channel by using the 
 *  default parameters and modifying fields that are different.
 *  (If the parameters are the same across channels, they can be
 *  created outside of the loop.)
 */
Void thrAudioprocInit( Void ) 
{
    
   g72x_init_state(&state_en);
   g72x_init_state(&state_de);
   memset(&AudioEncBuf[0].byteAudio[0][0],0x00,sizeof(AudioEncBuf));
   memset(&AudioDecBuf[0].byteAudio[0][0],0x00,sizeof(AudioDecBuf));
   pAudioEncBuf=&AudioEncBuf[0].byteAudio[0][0];
   pAudioDecBuf=&AudioDecBuf[0].byteAudio[0][0];
   codBufNum=0;
   decBufNum=0;
   codNum=0;
   deNum=0;
   deCnt=0;
   sizeAudio=80;
   
     
}    

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

/*
 *  ========= thrAudioprocRun ========
 *  The "body" of the swiAudioproc0, swiAudioproc1,... threads.
 *
 *  The single argument of this function is the channel number:
 *  0, 1, 2 etc. up to NUM_CHANNELS - 1. All the SWI objects
 *  that invoke this function pass the channel number as the
 *  argument. 
 *
 *  Based on the channel number, the thread -- the procedure --
 *  decides which thread resource object to access.
 */
Void thrAudioEncode( Arg aChan )
{
    Sample *src;
    Int     chan;
    Int i;
    //unsigned short byteCode[20];

    /*
     *  cast 'Arg' types to 'Int'. This is required on 55x large data model
     *  since Arg is not the same size as Int and Ptr in that model.
     *  On all other devices (54x, 55x small, 6x) ArgToInt is a simple cast
     */
    chan = ArgToInt( aChan );

    /*
     *  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( thrAudioproc[chan].pipIn  ) > 0 );

    /* get the full buffer from the input pipe */
    PIP_get( thrAudioproc[chan].pipIn );
    src = (Sample *)PIP_getReaderAddr( thrAudioproc[chan].pipIn );
    /* get the size in samples (the function below returns it in words) */
    sizeAudio = sizeInSamples(PIP_getReaderSize( thrAudioproc[chan].pipIn )  );
    //sizeAudio =80;
    
#if 1
	//encode and pack
    for(i=0;i<sizeAudio;i++)
    {
		src[i]=g721_encoder(src[i],&state_en);
	//dst[i]=g721_decoder(code,&state_de);
	}
	if(codNum==0)
	{
		pAudioEncBuf=&AudioEncBuf[codBufNum].byteAudio[0][0];
		codBufNum=(codBufNum==0)?1:0;
	}
	pack_output(src,&AudioEncBuf[codBufNum].byteAudio[codNum][0],sizeAudio);
	AudioEncBuf[codBufNum].frameNum[0] =codNum;
	codNum=NEXT_BUFFER_NUM(codNum);
	//SWI_andn(&swiAudioproc1,0x0001);
#endif	
	
    /* Free the receive buffer, put the transmit buffer */
    PIP_free( thrAudioproc[chan].pipIn  );
	
}
	
Void thrAudioDecode( Arg aChan )
{
	Sample  *dst;
    Int     chan;
    Int i;
    Int j;
    
    /*
     *  cast 'Arg' types to 'Int'. This is required on 55x large data model
     *  since Arg is not the same size as Int and Ptr in that model.
     *  On all other devices (54x, 55x small, 6x) ArgToInt is a simple cast
     */
    chan = ArgToInt( aChan );

    /*
     *  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_getWriterNumFrames( thrAudioproc[chan].pipOut ) > 0 );

    /* get the empty buffer from the out-pipe */
    PIP_alloc( thrAudioproc[chan].pipOut );
    dst = (Sample *)PIP_getWriterAddr( thrAudioproc[chan].pipOut );	
	//decode and unpack
#if 1	 
	unpack_input(&AudioDecBuf[decBufNum].byteAudio[deNum][0],dst,80);
	deNum++;	
	if(deNum>deCnt)
	{
		pAudioDecBuf=&AudioDecBuf[decBufNum].byteAudio[0][0];
		memset(pAudioDecBuf,0x00,0x150);
		decBufNum=(decBufNum==0)?1:0;
		deCnt=AudioDecBuf[decBufNum].frameNum[0];
		deNum=0;	
	} 

    for(i=0;i<80;i++)
    {
		dst[i]=g721_decoder(dst[i],&state_de);
	}
	/* For mono codecs, clear last bit in each sample from destination buffer */
	#ifdef APPMONOCODEC
	for (i = 0; i <80; i++) 
	{
		dst[i] = dst[i] & 0xfffe;
	}
	#endif
	
#endif	
    /* Record the amount of actual data being sent */
    PIP_setWriterSize( thrAudioproc[chan].pipOut, sizeInWords(sizeAudio) );
    PIP_put ( thrAudioproc[chan].pipOut );
}



⌨️ 快捷键说明

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