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

📄 adapt.c

📁 手机加密通话软件
💻 C
📖 第 1 页 / 共 2 页
字号:
	  if (match[i] > emax)	{
	    *BestDelayPtr = i;
	    emax = match[*BestDelayPtr];
	  }
	}
}

/*

*************************************************************************
*                                                                         *
* ROUTINE
*		SelectDelay
*
* FUNCTION
*		Select shortest delay of 2, 3, or 4 submultiples
*		if its match is within 1 dB of MSPE to favor
		smooth "pitch"
* SYNOPSIS
*		SelectDelay(BestDelayPtr, SubMult, match, 
*		              MinDelayPtr, MaxDelayPtr)
*
*   formal
*
*                       data    I/O
*       name            type    type    function
*       -------------------------------------------------------------------
*	BestDelayPtr	int	i/o	Pointer to delay with top match score
*	SubMult		int	 i	Sumbmultiples array
*	match		float	 i	Match score array for each delay
*	MinDelayPtr	int	 i	Pointer to minimum delay to search
*	MaxDelayPtr	int	 i	Pointer to maximum delay to search
*
**************************************************************************/
void SelectDelay(
int 	*BestDelayPtr, 
int 	SubMult[256][4], 
float 	match[MAX_NUM_ADAPT], 
int 	MinDelayPtr, 
int 	MaxDelayPtr)
{
int	i;
int	SubMultPtr, BigPtr;
int	Best;

/*  Initialize */
	Best = *BestDelayPtr;

/*  For each submultiple (2, 3, & 4) */
	for(i=1; i<=SubMult[*BestDelayPtr][0]; i++)	{

/*  Find best neighborhood match for given submultiple */
	  BigPtr = SubMult[*BestDelayPtr][i];
	  for(SubMultPtr = max(SubMult[*BestDelayPtr][i]-8, MinDelayPtr);
		SubMultPtr <= min(SubMult[*BestDelayPtr][i]+8, MaxDelayPtr); 
		SubMultPtr++)	{
	    if(match[SubMultPtr] > match[BigPtr])
	      BigPtr = SubMultPtr;
	  }

/*  Select submultiple match if within 1 dB MSPE match */
	  if(match[BigPtr] >= (0.88*match[*BestDelayPtr]))
	    Best = BigPtr;

	}

	*BestDelayPtr = Best;
}

/*

*************************************************************************
*                                                                         *
* ROUTINE
*		Neighborhood
*
* FUNCTION
*		Search BestDelayPtr's neighboring delays (to be used with 
*		earlier stages of searching).  Find gain and match 
*		score for neighboring delays and find best neighborhood 
*		match (could use end-point correction on unity spaced delays)
* SYNOPSIS
*		Neighborhood(lp_imp, residual, match, MinDelayPtr, MaxDelayPtr
				DelayTable, AdaptCB, BestDelayPtr, gain)
*
*   formal
*
*                       data    I/O
*       name            type    type    function
*       -------------------------------------------------------------------
*	lp_imp		float	 i	LP impulse response
*	residual	float	 i	Residual from LPC analysis
*	match		float	 i	Adaptive Codebook match score array
*	MinDelayPtr	int	 i	Pointer to minimum delay to search
*	MaxDelayPtr	int	 i	Pointer to maximum delay to search
*	DelayTable	float	 i	Table of integer and fractional delays
*	AdaptCB		float	 i	Adaptive codebook
*	BestDelayPtr	int	 o	Pointer to best delay
*	gain		float	 o	Adaptive Codebook gain array
*
**************************************************************************/
void Neighborhood(
float 	lp_imp[SF_LEN], 
float 	residual[RES_LEN], 
float 	match[MAX_NUM_ADAPT], 
int 	MinDelayPtr, 
int 	MaxDelayPtr, 
float	DelayTable[],
float 	AdaptCB[MAX_ABUF_LEN], 
int 	*BestDelayPtr, 
float 	gain[MAX_NUM_ADAPT])
{
int	i;
int	BigPtr;
int	IntDelay;
float	FracDelay;
float	AdaptCBShift[MAX_A_LEN];

	BigPtr = *BestDelayPtr;

	for(i=max(*BestDelayPtr - NeighborhoodRange, MinDelayPtr); 
		i<=min(*BestDelayPtr + NeighborhoodRange, MaxDelayPtr); i++){
	  if (i != *BestDelayPtr)	{
	    IntDelay = (int)(DelayTable[i]);
	    FracDelay = DelayTable[i] - IntDelay;
	    if(fabs(FracDelay) < .0001)	
/*	      CalcACBParms(&AdaptCB[START - IntDelay-1], SF_LEN, lp_imp, 
		TRUE, IntDelay, LEN_TRUNC_H, residual, &match[i], &gain[i]);
*/;
	    else	{
	      delay(AdaptCB, B_PTR, START, SF_LEN, FracDelay, IntDelay, -4, 3, 
		5,  &AdaptCBShift[0]);
	      CalcACBParms(AdaptCBShift, SF_LEN, lp_imp, TRUE, 69, 
		LEN_TRUNC_H, residual, &match[i], &gain[i]);
	    }
	    if (match[i] > match[*BestDelayPtr])
	      BigPtr = i;
	  }
	}
	
	*BestDelayPtr = BigPtr;
}

/*

*************************************************************************
*                                                                         
* ROUTINE
*		CalcIntAdaptParms
*
* FUNCTION
*		Calculate gain and match score for integer adaptive delays
* SYNOPSIS
*		CalcIntAdaptParms(AdaptCB, pc_imp, MinDelayPtr, MaxDelayPtr, *			DelayTable, residual, gain, match)
*
*   formal
*
*                       data    I/O
*       name            type    type    function
*       -------------------------------------------------------------------
*	AdaptCB		float	 i	Adaptive Codebook
*	pc_imp		float	 i	Impulse response of PCs
*	MinDelayPtr	int	 i	Pointer to minimum delay to search
*	MaxDelayPtr	int	 i	Pointer to maximum delay to search
*	DelayTable	float	 i	Adaptive delay coding table
*	residual	float	 i	Residual from LPC analysis
*	gain		float	 o	Gain array
*	match		float	 o	Match score array
*
**************************************************************************
*
*	Uses end-point correction on unity spaced delays
*
**************************************************************************/
void CalcIntAdaptParms(
float	AdaptCB[MAX_ABUF_LEN],
float	pc_imp[SF_LEN],
int	MinDelayPtr,
int	MaxDelayPtr,
float	DelayTable[MAX_NUM_ADAPT],
float	residual[RES_LEN],
float	gain[MAX_NUM_ADAPT],
float	match[MAX_NUM_ADAPT])
{
int	first = TRUE;
int	IntDelay;
float	FracDelay;
int	i;


	for(i=MinDelayPtr;i<=MaxDelayPtr;i++)	{
	  IntDelay = (int)(DelayTable[i]);
	  FracDelay = DelayTable[i] - IntDelay;
	  if (fabs(FracDelay) < .0001)	{
	    CalcACBParms(&AdaptCB[START - IntDelay-1], SF_LEN, pc_imp,
		first,IntDelay, LEN_TRUNC_H, &residual[0], &match[i], &gain[i]);
	    first = FALSE;
	  }
	  else
	    match[i] = 0.0;
	}

}
/*

*************************************************************************
*                                                                         *
* ROUTINE
*		CalcFracAdaptParms
*
* FUNCTION
*		Calculate gain and match score for fractional adaptive delays
* SYNOPSIS
*		CalcFracAdaptParms(AdaptCB, pc_imp, MinDelayPtr, MaxDelayPtr, 
*			DelayTable, residual, gain, match)
*
*   formal
*
*                       data    I/O
*       name            type    type    function
*       -------------------------------------------------------------------
*	AdaptCB		float	 i	Adaptive Codebook
*	pc_imp		float	 i	Impulse response of PCs
*	MinDelayPtr	int	 i	Minimum delay pointer to search
*	MaxDelayPtr	int	 i	Maximum delay pointer to search
*	DelayTable	float	 i	Adaptive delay coding table
*	residual	float	 i	Residual from LPC analysis
*	gain		float	 o	Gain array
*	match		float	 o	Match score array
*
**************************************************************************
*
*	Uses end-point correction on unity spaced delays
*
**************************************************************************/
void CalcFracAdaptParms(
float	AdaptCB[MAX_ABUF_LEN],
float	pc_imp[SF_LEN],
int	MinDelayPtr,
int	MaxDelayPtr,
float	DelayTable[MAX_NUM_ADAPT],
float	residual[RES_LEN],
float	gain[MAX_NUM_ADAPT],
float	match[MAX_NUM_ADAPT])
{
int	IntDelay;
double	FracDelay;
int	i;
float	AdaptCBShift[MAX_A_LEN];


	for(i=MinDelayPtr;i<=MaxDelayPtr;i++)	{
	  IntDelay = (int)(DelayTable[i]);
	  FracDelay = DelayTable[i] - IntDelay;
	  if (fabs(FracDelay) >= .0001)	{
	    delay(AdaptCB, B_PTR, START, SF_LEN, FracDelay, IntDelay, -4, 3, 5, 
			AdaptCBShift);
	    CalcACBParms(AdaptCBShift, SF_LEN, pc_imp, 1, 69, LEN_TRUNC_H, 
			residual, &match[i], &gain[i]);
	  }
	}

}
/*

*************************************************************************
*                                                                         *
* ROUTINE
*		FindAdaptResidual
*
* FUNCTION
*		Find residual after adaptive analysis
* SYNOPSIS
*		FindAdaptResidual(speech, AdaptCB, pc, AdaptGain, AdaptDelay, 
*			residual)
*
*   formal
*
*                       data    I/O
*       name            type    type    function
*       -------------------------------------------------------------------
*	speech		float	 i	Subframe of input speech
*	AdaptCB		float	 i	Adaptive Codebook vector
*	pc		float	 i	Subframe of interpolated predictor
*					coefficients
*	AdaptGain	float 	 i	Adaptive codebook gain
*	AdaptDelay	float	 i	Adaptive codebook delay
*	residual	float	 o	Adaptive residual
*
**************************************************************************/

void FindAdaptResidual(
float	speech[SF_LEN],
float	AdaptCB[MAX_ABUF_LEN],
float	pc[ORDER+1],
float	AdaptGain,
float	AdaptDelay,
float	residual[RES_LEN])
{
int	i;
float	pcexp[ORDER+1];

/*  Initialize residual */
	SetArray(RES_LEN, 0.0, residual);

/*  Adaptive Codebook Synthesis */
	ConstructAdaptCW(residual, SF_LEN, AdaptCB, ACB_SIZE, AdaptGain, 
		AdaptDelay, "long");

/*  LP Filter */
	do_pfilt_dynamic(&Adapt_ResP, pc, residual);

/*  Calculate Residual */
	for(i=0;i<RES_LEN;i++)	{
	  residual[i] = speech[i] - residual[i];
	}

/*  Perceptual Weighting of residual */
	do_zfilt_dynamic(&Adapt_ResZ, pc, residual);
	BWExpand(GAMMA, pc, pcexp);
	do_pfilt_dynamic(&Adapt_ResP2, pcexp, residual);


}

⌨️ 快捷键说明

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