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

📄 exports.c

📁 G723 算法
💻 C
字号:
#include "exports.h"


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <assert.h>

#include "typedef.h"
#include "basop.h"
#include "cst_lbc.h"
#include "tab_lbc.h"
#include "lbccodec.h"
#include "coder.h"
#include "decod.h"
#include "exc_lbc.h"
#include "util_lbc.h"
#include "cod_cng.h"
#include "dec_cng.h"
#include "vad.h"
#include "tame.h"
#include "lsp.h"
#include "lpc.h"
#include "util_cng.h"

DECSTATDEF  DecStat  ;
CODCNGDEF CodCng;
CODSTATDEF  CodStat  ;
DECCNGDEF DecCng;
VADSTATDEF  VadStat ;

/* Global variables */
enum  Wmode    WrkMode = Both ;
enum  Crate    WrkRate = Rate63 ;

int   PackedFrameSize[2] = {
   24 ,
   20
   } ;

Flag    UseHp = True ;
Flag    UsePf = True ;
Flag    UseVx = False ;
Flag    UsePr = True ;

#define false 0

void G723_InitEncode () 
{
	
	Init_Coder( ) ;
    //Init_Decod( ) ;

	/*
    // Init Comfort Noise Functions
    if( UseVx ) {
        Init_Vad();
        Init_Cod_Cng( );
    }
	*/

    Init_Dec_Cng( ); // necessary ? 

}



int  G723_Encode (unsigned char* pData,int nDataLen , unsigned char* pEncodedData , int nEncodedDataLen ) 
{
	int nCount ; 
	int i; 

	if (pData ==NULL || nDataLen ==0 || pEncodedData ==NULL || nEncodedDataLen == 0 ) 
	{
		assert(false) ; 
		return -1 ; 
	}
	if (nDataLen % G723_RAW_DATA_LEN  != 0 ) 
	{
		assert(false) ; 
		return -1 ; 
	}
	nCount = nDataLen / G723_RAW_DATA_LEN ; 
	assert(nCount != 0 ) ; 
	if (nEncodedDataLen < G723_ENCODED_DATA_LEN * nCount ) 
	{
		assert(false); 
		return -(G723_ENCODED_DATA_LEN * nCount ); 
	}

	/*
	if(Ratp != NULL) {
	fread((char *)&Rate_Rd, sizeof(char), 1, Ratp);// isn't run . 
	WrkRate = (enum Crate)Rate_Rd;
	}
	if ( WrkRate == Rate53) reset_max_time();
	*/

	for (i = 0 ; i !=nCount ; ++i ) 
	{			
		Coder ( (Word16*) ( pData + i * G723_RAW_DATA_LEN  ) , pEncodedData + i * G723_ENCODED_DATA_LEN ) ; 
	}
	return G723_ENCODED_DATA_LEN * nCount; 
}

void  G723_InitDecode ()  
{
		 Init_Decod( ) ;

	/*
    // Init Comfort Noise Functions
    if( UseVx ) {
        Init_Vad();
        Init_Cod_Cng( );
    }
	*/

	 Init_Dec_Cng( ); // 

	 	 


}

int  G723_Decode (unsigned char** pData ,int nDataLen , unsigned char* pDecodedData,int nDecodedDataLen ) 
{
	int nNeedSize ; 
	unsigned char* pNext ; 
	unsigned char* pNextEncodedData  ; 

	if (pData ==NULL || *pData ==NULL || nDataLen == 0 || pDecodedData ==NULL || nDecodedDataLen == 0 ) 
	{
		assert(false) ; 
		return -1 ; 
	}

	nNeedSize = 0 ;     	
	pNext = *pData ; 
	pNextEncodedData = pDecodedData ; 

	for (;pNext < *pData+nDataLen ; ) 
	{
		Word16  Info = *pNext & (Word16)0x0003 ;
		int     Size ;    
		char aLine[G723_ENCODED_DATA_LEN ] ; 
		Word16 Crc ; 

		/* Check frame type and rate informations */
		switch(Info) {

			/* Active frame, high rate */
		case 0 : {
			Size  = 23;
			break;
				 }

				 /* Active frame, low rate */
		case 1 : {
			Size  = 19;
			break;
				 }

				 /* Sid Frame */
		case 2 : {
			Size  = 3;
			break;
				 }

				 /* untransmitted */
		default : {
			return(0);
				  }
		}
		nNeedSize += G723_RAW_DATA_LEN ;

		if ( pNext +Size + 1 > *pData + nDataLen ) 
		{
			//assert(false) ; 
			*pData = pNext ; 
			// return -1 ;  // the original audio data is damanged  , 
			return nNeedSize-G723_RAW_DATA_LEN ; 
		}
		if ( pNextEncodedData + G723_RAW_DATA_LEN > pDecodedData + nDecodedDataLen ) 
		{
			assert(false) ; 
			*pData = pNext ; 
			return -nNeedSize ; 
		}		 	
		memset (aLine , 0 , sizeof(aLine )) ; 
		memcpy (aLine , pNext , Size + 1 ) ;
		pNext +=Size+1 ; 

		//if ( Fep == NULL )
			Crc = (Word16) 0 ;
			/*
		else
			fread( (char *)&Crc, sizeof(Word16), 1, Fep ) ; //isn't run
			*/
		Decod( (Word16*) pNextEncodedData , aLine, Crc ) ;
		
		pNextEncodedData +=G723_RAW_DATA_LEN ; 
	}

	*pData = pNext ; 
	return nNeedSize ; 

}

#include "basop.c"
#include "tab_lbc.c"
#include "coder.c"
#include "decod.c"
#include "exc_lbc.c"
#include "util_lbc.c"
#include "cod_cng.c"
#include "dec_cng.c"
#include "vad.c"
#include "tame.c"
#include "lsp.c"
#include "lpc.c"
#include "util_cng.c"

⌨️ 快捷键说明

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