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

📄 codeparm.c

📁 手机加密通话软件
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright 2001,2002,2003 NAH6
 * All Rights Reserved
 *
 * Parts Copyright DoD, Parts Copyright Starium
 *
 */
#include "main.h"
#include "smooth.h"
#include "acb_code.h"
#include "codeparm.h"
#include "error.h"
#include "scb_code.h"
#include "code_lsf.h"

#define	NPARAMS	10+(4*4)+3

/*int BitAllocs[NPARAMS] = {
/*	3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 	/* For LSFs */
/*	8, 6, 8, 6,			/* For ACB Delay */
/*	5, 5, 5, 5, 			/* For ACB Gain */
/*	9, 9, 9, 9, 			/* For SCB Index */
/*	5, 5, 5, 5, 			/* For SCB Gain */
/*	1,				/* For Bishnu Bit */
/*	1				/* For Sync Bit */
/*};
*/

/*  FS1016 compatible bit allocations */
int BitAllocs[NPARAMS] = {
	3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 	/* For LSFs */
	8, 5, 9, 5,			/* For first subframe parameters */
	6, 5, 9, 5,			/* For second subframe parameters */
	8, 5, 9, 5, 			/* For third subframe parameters */
	6, 5, 9, 5,			/* For fourth subframe parameters */
	1,				/* For Bishnu Bit */
	4,				/* For Hamming bits */
	1				/* For Sync Bit */
};

static void Encode(
TX_PARAM	parameters, 
TX_BITS		*bits);

static void Decode(
TX_BITS		bits,
int		Assurance,
int		FrameNum,
int		SmoothFlag,
TX_PARAM	*parameters) ;

static void Pack(
int		NParams,
int		Params[],
int		BitAllocs[], 
int		*NumPacked,
int		Channel[]);

static void Unpack(
int		NParams,
int		BitAllocs[],
int		Channel[],
int		*NumUnpacked,
int		Params[]);

static void ACBDelayEncode(
float	Udelay, 
int	*Qdelay);

static void ACBDelayDecode(
int	Qdelay, 
float	*Udelay);

static int FS1016Encode(
TX_BITS	InStruct,
int	OutArray[]);

static int FS1016Decode(
int	InArray[],
TX_BITS	*OutStruct);


	

/**************************************************************************
*                                                                         *
* ROUTINE
*		EncodeParameters
*
* FUNCTION
*		Encode and Pack CELP parameters
* SYNOPSIS
*		EncodeParameters(parameters, bit_len, error_parms, edac, 
*					frame_num, channel)
*
*   formal
*
*                       data    I/O
*       name            type    type    function
*       -------------------------------------------------------------------
*	parameters	TX_PARAM i	Frame of CELP parameters
*	bit_len		int	 i	Number of bits to encode
*	error_parms	char	 i	Name of error parameter file
*	edac		int	 i	EDAC flag
*	frame_num	int	 i	Frame number
*	channel		int	 o	Frame of bits from analysis
*
**************************************************************************/

#include "bitperm.h"

void EncodeParameters(
TX_PARAM 	parameters,
int		bit_len,
char		error_parms[],
int		edac,
int		frame_num,
int		**PermChannel)
{
TX_BITS		bits;
int		BitChannel[CELP_BITS];
int		NumPacked;
int		FSParms[NPARAMS];
int		i;
static int	first = TRUE;
int		*pointer;


/*  Convert TX parameters to fixed point values that can be transmitted */
	Encode(parameters, &bits);

/*  Put these parameters into FS 1016 compatible form */
	if (FS1016Encode(bits, FSParms) != NPARAMS)
	  printf("*** Problem Encoding to FS1016 ***\n");

/*  Pack these values into a binary stream */
	Pack(NPARAMS, FSParms, BitAllocs, &NumPacked, BitChannel);

/*  Perform error protection coding */
	  ErrorEncode(BitChannel, /*bit_len, error_parms,*/ edac/*, frame_num*/);

/*  Permute the stream if no EDAC */
	if(first)	{
	  *PermChannel = (int *)calloc(bit_len, sizeof(int));
	  first = FALSE;
	}
	pointer = *PermChannel;
	for (i=0; i<CELP_BITS; i++)	{
	  *(pointer++) = BitChannel[BitPermute[i]-1];
	}

}


/*

*************************************************************************
*                                                                         *
* ROUTINE
*		DecodeParameters
*
* FUNCTION
*		Decode and Unpack CELP parameters
* SYNOPSIS
*		DecodeParameters(bits, num_bits, error_parms, edac, 
			FrameNum, SmoothFlag, parameters)
*
*   formal
*
*                       data    I/O
*       name            type    type    function
*       -------------------------------------------------------------------
*	channel		int	 i	Frame of bits from channel
*	num_bits	int	 i	Number of bits in channel
*	error_parms	char	 i	Name of error parameter file
*	edac		int	 i	EDAC flag
*	FrameNum	int	 i	Frame Number
*	SmoothFlag	int	 i	User's smoothing preference
*	parameters	TX_PARAM o	Frame of CELP parameters
*
**************************************************************************/

void DecodeParameters(
int		channel[],
int		num_bits,
char		error_parms[],
int		edac,
int		FrameNum,
int		SmoothFlag,
TX_PARAM 	*parameters)
{
TX_BITS		bits;
int		BitChannel[CELP_BITS];
int		NumUnpacked;
int		FSParms[NPARAMS];
int		i;
int		Assurance;

/*  Unpermute the stream  */
	for(i=0;i<CELP_BITS;i++)	{
	  BitChannel[BitPermute[i]-1] = channel[i];
	}

/*  Check for errors and correct */
	ErrorDecode(BitChannel, /*num_bits, error_parms,*/ edac, &Assurance);

/*  Unpack the corrected binary stream */
	Unpack(NPARAMS, BitAllocs, BitChannel, &NumUnpacked, FSParms);

/*  Translate from FS1016 compatible mode */
	if (FS1016Decode(FSParms, &bits) != NPARAMS)
	  printf("*** Problem Decoding from FS1016 ***\n");

/*  Decode RX bits into parameters to be synthesized */
	Decode(bits, Assurance, FrameNum, SmoothFlag, parameters);

}

/*

*************************************************************************
*                                                                         *
* ROUTINE
*		Encode
*
* FUNCTION
*		Encode CELP parameters
* SYNOPSIS
*		Encode(parameters, bits)
*
*   formal
*
*                       data    I/O
*       name            type    type    function
*       -------------------------------------------------------------------
*	parameters	TX_PARAM i	Frame of CELP parameters
*	bits		TX_BITS	 o	Frame of bits from analysis
*
**************************************************************************/

void Encode(
TX_PARAM	parameters, 
TX_BITS		*bits)
{
int 		sf;
static int	sync=0;
float		qlsf[ORDER];

/*  Convert LSFs to int representation */
	QuanLSF(parameters.lsf, qlsf, bits->lsf);

	for(sf=0; sf < NUM_SF; sf++)	{
/*  Convert ACB gain to int representation */
	  ACBGainEncode(parameters.AdaptiveGain[sf], &bits->AdaptiveGain[sf]);

/*  Convert ACB delay to int representation */
	  ACBDelayEncode(parameters.AdaptiveDelay[sf], 
		&bits->AdaptiveDelay[sf]);

/*  Convert SCB gain to int representation */
	  SCBGainEncode(parameters.StochasticGain[sf], &bits->StochasticGain[sf]);

/*  Convert SCB index to int representation */
	  bits->StochasticIndex[sf] = parameters.StochasticIndex[sf]-1;
	}

/*  Encode Bishnu bit */
	bits->Bishnu = 0;

/*  Encode sync bit */
	bits->Sync = sync;

/*  Update sync bit */
	sync = (sync == 0) ? 1 : 0;
	

}


/*

*************************************************************************
*                                                                         *
* ROUTINE
*		Decode
*
* FUNCTION
*		Decode CELP parameters
* SYNOPSIS
*		Decode(bits, Assurance, FrameNum, SmoothFlag, parameters)
*
*   formal
*
*                       data    I/O
*       name            type    type    function
*       -------------------------------------------------------------------
*	bits		TX_BITS	 i	Frame of bits from analysis
*	Assurance	int	 i	Assurance value from EDAC
*	FrameNum	int	 i	Frame number
*	SmoothFlag	int	 i	User's smoothing preference
*	parameters	TX_PARAM o	Frame of CELP parameters
*
**************************************************************************/

float ACBGainTable[32] = 
{
  -0.993, -0.831, -0.693, -0.555, -0.414, -0.229,    0.0,  0.139,
   0.255,  0.368,  0.457,  0.531,  0.601,  0.653,  0.702,  0.745,
   0.780,  0.816,  0.850,  0.881,  0.915,  0.948,  0.983,  1.020, 
   1.062,  1.117,  1.193,  1.289,  1.394,  1.540,  1.765,  1.991
};
 
void Decode(
TX_BITS		bits,
int		Assurance,
int		FrameNum,
int		SmoothFlag,
TX_PARAM	*parameters) 
{
int	sf;

/*  Convert LSFs from int representation */
	UnquanLSF(bits.lsf, ORDER, parameters->lsf);

	for(sf=0; sf<NUM_SF; sf++)	{
/*  Convert ACB gain from int representation */
	  ACBGainDecode(bits.AdaptiveGain[sf], &parameters->AdaptiveGain[sf]);

/*  Convert ACB delay from int representation */
	  ACBDelayDecode(bits.AdaptiveDelay[sf], &parameters->AdaptiveDelay[sf]);

/*  Convert SCB gain from int representation */
	  SCBGainDecode(bits.StochasticGain[sf], &parameters->StochasticGain[sf]);

/*  Convert SCB index from int representation */
	  parameters->StochasticIndex[sf] = bits.StochasticIndex[sf]+1;

/*  Smooth if necessary and user reqests it */
	  if (SmoothFlag)	{
	    Smooth(Assurance, FrameNum, sf, parameters);
	  }


	}

⌨️ 快捷键说明

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