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


/* Copyright 2001,2002,2003 NAH6 
 * All Rights Reserved 
 * 
 * Parts Copyright DoD, Parts Copyright Starium 
 * 
 */ 
/*#include "filter.h" 
#include "main.h"	not needed with celpfilt.h */ 
#include "celpfilt.h" 
#include "adapt.h" 
#include "lp_anal.h" 
#include "bwexp.h" 
#include "analysis.h" 
#include "con_adap.h" 
#include "interp.h" 
#include "lsftopc.h" 
#include "mexcite.h" 
#include "setarray.h" 
#include "stoch.h" 
 
static void CreateSubFrame( 
float	FutureSpeech[F_LEN], 
float	PresentSpeech[F_LEN]); 
 
static void FindImpulseResponse( 
float	pc[ORDER+1], 
float	h[SF_LEN]); 
 
static void FindLPResidual( 
float	speech[SF_LEN], 
float	pc[ORDER+1], 
float	residual[RES_LEN]); 
 
static void UpdateEverything( 
float	OptExcVec[SF_LEN], 
float	Speech[SF_LEN], 
float	AdaptCB[ACB_SIZE], 
float	AdaptGain, 
float	AdaptDelay, 
float	pc[ORDER+1]); 
 
/************************************************************************** 
*                                                                         * 
* ROUTINE 
*		analysis 
* 
* FUNCTION 
*		CELP analysis 
* SYNOPSIS 
*		analysis(SpeechIn, parameters, frame_num) 
* 
*   formal 
* 
*                       data    I/O 
*       name            type    type    function 
*       ------------------------------------------------------------------- 
*	SpeechIn	float	 i	Frame of input speech 
*	parameters	TX_PARAM o	Frame of CELP parameters 
*	frame_num	int	 i	Frame number (for diagnostics) 
* 
************************************************************************** 
* 
* DESCRIPTION 
* 
*	This performs the analysis of the input speech and produces 
*	a set of parameters that are sent to the synthesizer for 
*	reconstruction. 
* 
************************************************************************** 
* 
* CALLED BY 
* 
*	celp.c 
* 
* CALLS 
* 
*	HPF_InSpeech LP_Analysis Interpolate CreateSubFrame  
* 
*	loop around: 
*	LSFtoPC FindLPResidual FindImpulseResponse AdaptiveAnalysis 
*	ModifiedExcitation StochasticAnalysis UpdateEverything 
* 
**************************************************************************/ 
void Analysis( 
float 	SpeechIn[F_LEN], 
TX_PARAM *parameters, 
int	frame_num) 
{ 
	float 		LSFint[NUM_SF][ORDER], pc[ORDER+1]; 
	int		sf; 
	float		LP_res[RES_LEN], Adaptive_res[RES_LEN]; 
	float		LPImpulseResponse[SF_LEN]; 
	float		PresentSpeech[F_LEN]; 
	float		scale; 
static 	float		AdaptiveCB[ACB_SIZE]; 
	float		OptimumExcitation[SF_LEN]; 
 
 
/*  High Pass Filter Input Speech */ 
	HPF_InSpeech(SpeechIn); 
 
/*  LP Analysis of Input speech */ 
	LP_Analysis(SpeechIn, parameters->lsf, frame_num); 
 
/*  Interpolate LSPs */ 
	Interpolate(parameters->lsf, LSFint, ANALYSIS, frame_num); 
 
/*  Create vector of "present" speech for codebook searches */ 
	CreateSubFrame(SpeechIn, PresentSpeech); 
 
/*  Loop through subframes to find codebook (adaptive and stochastic) indices */ 
	for (sf = 0; sf < NUM_SF; sf++) { 
 
/*  Convert quantized, interpolated LSFs to PCs */ 
	  LSFtoPC(LSFint[sf], pc, frame_num); 
 
/*  Find the residual from LP analysis using the quantized, interpolated LSFs */ 
	  FindLPResidual(&PresentSpeech[sf*SF_LEN], pc, LP_res); 
 
/*  Find Impulse Response response of PCs */ 
	  FindImpulseResponse(pc, LPImpulseResponse);  
 
/*  Use the LP residual to find the correct adaptive codebook index and gain */ 
 	  AdaptiveAnalysis(&PresentSpeech[sf*SF_LEN], pc, LPImpulseResponse, AdaptiveCB, 
		LP_res, ¶meters->AdaptiveDelay[sf],  
		¶meters->AdaptiveGain[sf], Adaptive_res); 
  
/*  Calculate the appropriate scaling for the Stochastic Analysis */ 
	  ModifiedExcitation(LP_res, Adaptive_res, &scale); 
 
/*  Calculate the correct stochastic codebook index and gain */   
  	  StochasticAnalysis(scale, LPImpulseResponse, Adaptive_res,   
		¶meters->StochasticIndex[sf],  
		¶meters->StochasticGain[sf], OptimumExcitation); 
 
/*  Update adaptive codebook and residual filters for next subframe */ 
	  UpdateEverything(OptimumExcitation, &PresentSpeech[sf*SF_LEN], AdaptiveCB, 
		parameters->AdaptiveGain[sf], parameters->AdaptiveDelay[sf], pc); 
	} 
 
} 
/* 
 
************************************************************************* 
*                                                                         * 
* ROUTINE 
*		CreateSubFrame 
* 
* FUNCTION 
*		Create subframe vector from past and current samples 
* SYNOPSIS 
*		CreateSubFrame(FutureSpeech, PresentSpeech) 
* 
*   formal 
* 
*                       data    I/O 
*       name            type    type    function 
*       ------------------------------------------------------------------- 
*	FutureSpeech	float	 i	Frame of future speech 
*	PresentSpeech	flaot	 o	Frame of present speech 
* 
**************************************************************************/ 
 
void CreateSubFrame( 
float	FutureSpeech[F_LEN], 
float	PresentSpeech[F_LEN]) 
{ 
static float	PastSpeech[F_LEN/2]; 
static int	first=TRUE; 
int		i; 
 
/*  Initialize past speech on first pass through */ 
	if (first)	{ 
	  first = FALSE; 
	  for(i=0;i