www.pudn.com > CryptoPhone-src-031122.zip > stoch.c


/* Copyright 2001,2002,2003 NAH6 
 * All Rights Reserved 
 * 
 * Parts Copyright DoD, Parts Copyright Starium 
 * 
 */ 
#include "main.h" 
#include "StochCB.h" 
#include "conv_cor.h" 
#include "scb_code.h" 
#include "stoch.h" 
 
 
static void CalcStochGain( 
float	LPCImpResp[SF_LEN], 
float	Residual[RES_LEN], 
int	*cbindex, 
float	*StochGain, 
int	*codeword); 
 
/************************************************************************** 
*                                                                         * 
* ROUTINE 
*		StochasticAnalysis 
* 
* FUNCTION 
*               Find optimal MSPE excitation code word 
* SYNOPSIS 
*		StochasticAnalysis(scale, LPCImpResp, Residual,  
*			StochasticIndex, StochasticGain, OptExc) 
* 
*   formal 
* 
*                       data    I/O 
*       name            type    type    function 
*       ------------------------------------------------------------------- 
*	scale		float	 i	Mixed excitation scaling factor 
*	LPCImpResp	float	 i	LPC Impulse response 
*	Residual	float	 i	Residual from adaptive analysis 
*	StochasticIndex	int	 o	Stochastic codebook index 
*	StochasticGain	int	 o	Stochastic codebook gain 
*	OptExc		float	 o	Optimum excitation vector 
* 
************************************************************************** 
*	 
* DESCRIPTION 
* 
*  Code book search is performed by closed-loop analysis using conventional 
*  minimum squared prediction error (MSPE) criteria of the perceptually 
*  weighted error signal.  The code book is overlaped to allow recursive 
*  computational savings in routine ConvCor: 
* 
*	index	code book 
*		+-----------------------+ 
*	1	| 2M-1         2(M-1)+L | 
*	2	| 2(M-2)+1     2(M-2)+L | 
*	:	| :            :	| 
*	N-1	| .            .	| 
*	N	| .            .	| 
*	:	| 3            62	| 
*	:	| 1            60	| 
*		+-----------------------+ 
* 
*	where: M = maximum code book size 
*	       N = actual code book search size (any value between 1 & M) 
*	       L = code word length 
* 
*	each code word is:  2(M-index)+1 -> 2(M-index)+L 
*  	 
***************************************************************************/ 
void StochasticAnalysis( 
float	scale, 
float	LPCImpResp[SF_LEN], 
float	Residual[RES_LEN], 
int	*StochasticIndex, 
float	*StochasticGain, 
float	OptExc[SF_LEN]) 
{ 
int	i; 
int	gindex; 
int	codeword; 
 
/*  Calculate gain for each codeword, search for best codeword */ 
	CalcStochGain(LPCImpResp, Residual, StochasticIndex, StochasticGain, 
		&codeword); 
 
/*  Apply constrained excitation factor */ 
	*StochasticGain *= scale; 
 
/*  Quantize gain */ 
	*StochasticGain = SCBGainEncode(*StochasticGain, &gindex); 
 
/*  Scale selected code word vector into excitation array */ 
	for(i=0; i= emax)	{ 
	    emax = err; 
	    *cbindex = i+1; 
	    *StochGain = gain; 
	  } 
	} 
 
/*  Calculate pointer to best code word */ 
	*codeword = 2*(MAX_STOCH_CB_SIZE - *cbindex); 
 
}