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


/* Copyright 2001,2002,2003 NAH6 
 * All Rights Reserved 
 * 
 * Parts Copyright DoD, Parts Copyright Starium 
 * 
 */ 
          /*LINTLIBRARY*/ 
          /*PROTOLIB1*/ 
#include  
#include  
#include "main.h" 
#include "lsftable.h" 
#include "code_lsf.h" 
 
int	BITS[10] = {3, 4, 4, 4, 4, 3, 3, 3, 3, 3}; 
 
#define FSCALE	8000.0 
#ifdef NEW_LSF_CODE 
#define MIN_LSF_DIST	39 
#else 
#define MIN_LSF_DIST	0 
#endif 
 
static void AssignLSFFreqs( 
int	findex[ORDER], 
float	qlsp[ORDER]); 
 
static void CalcLSFFreq( 
float	lsp[ORDER], 
int	frequency, 
float	lsf[ORDER]); 
 
static void CheckMono( 
int	table[LSFTABLE_LENGTH][LSFTABLE_WIDTH], 
int	index[], 
int	num, 
float	lsf[], 
int	level, 
float	*errorup, 
float	*errordn, 
int	*nonmono); 
 
static void CorrectNonMono( 
float	errorup, 
float	errordn, 
int	findex[], 
int	where, 
int	level); 
 
static void InitLSFQuant( 
int	table[LSFTABLE_LENGTH][LSFTABLE_WIDTH], 
int	lsf[], 
int	level, 
int	lsfnum); 
 
static void QuantizeLSF( 
float 	input, 
int	level[], 
int 	nlevel, 
int	*findex); 
 
/************************************************************************** 
*                                                                         * 
* ROUTINE 
*		QuanLSF 
* 
* FUNCTION 
*		Quantize line spectral frequencies 
* SYNOPSIS 
*		QuanLSF(lsf, qlsf, freq_index) 
* 
*   formal 
* 
*                       data    I/O 
*       name            type    type    function 
*       ------------------------------------------------------------------- 
*	lsf		float	 i	Unquantized LSFs 
*	qlsf		float 	 o	Quantized LSFs 
*	freq_index	int	 o	Indexes into frequency array 
* 
**************************************************************************/ 
void QuanLSF( 
float	lsf[ORDER], 
float	qlsf[ORDER], 
int	freq_index[ORDER]) 
{ 
float	freqs[ORDER]; 
int	i, level; 
int	LSFInit[16]; 
float	errorup, errordn; 
int	nonmonotonic=FALSE; 
 
 
/*  Calculate frequencies for LSPs */ 
	CalcLSFFreq(lsf, 8000, freqs); 
 
/*  For each LSF */ 
	for(i=0;i0) 
	    CheckMono(LSFTable, freq_index, i, freqs, level, &errorup, &errordn, &nonmonotonic); 
 
/*  Correct if nonmonotonic */ 
	  if (nonmonotonic) 
	    CorrectNonMono(errorup, errordn, freq_index, i, level); 
 
	} 
 
/*  Quantize LSF frequencies using indices found above */ 
	AssignLSFFreqs(freq_index, qlsf); 
 
} 
 
/* 
 
************************************************************************* 
*                                                                         * 
* ROUTINE 
*		CalcLSFFreq 
* 
* FUNCTION 
*		Calculate LSFs from LSPs using input frequency 
* SYNOPSIS 
*		CalcLSFFreq(lsp, frequency, lsf) 
* 
*   formal 
* 
*                       data    I/O 
*       name            type    type    function 
*       ------------------------------------------------------------------- 
*	lsp		float	  i	Frame of input line spectral pairs 
*	frequency	int	  i	Sampling frequency 
*	lsf		float	  o	Frame of output line spectral frequencies 
* 
**************************************************************************/ 
 
void CalcLSFFreq( 
float	lsf[ORDER], 
int	frequency, 
float	freqs[ORDER]) 
{ 
int	i; 
 
/*  Calculate LSF based on sampling frequency */ 
	for(i=0;i 
			LSFTable[where-2][findex[where-2]]) 	{ 
	      findex[where-1] = max(findex[where-1]-1, 0); 
	    } 
	    else	{ 
	      findex[where] = min(findex[where]+1, level); 
 
	      while(LSFTable[where][findex[where]] - MIN_LSF_DIST <  
			LSFTable[where-1][findex[where-1]])	{ 
	        findex[where] = min(findex[where]+1, level); 
	      } 
	    } 
		     
	  } 
	} 
} 
 
 
/* 
 
************************************************************************* 
*                                                                         * 
* ROUTINE 
*		AssignLSFFreqs 
* 
* FUNCTION 
*		Correct index for minimum error if nonmonotonic 
* SYNOPSIS 
*		AssignLSFFreqs(findex, qlsp) 
* 
*   formal 
* 
*                       data    I/O 
*       name            type    type    function 
*       ------------------------------------------------------------------- 
*	findex		int	 i	Frequency index into LSF Table 
*	qlsp		int	 o	Quantized line spectral parameter 
* 
**************************************************************************/ 
 
 
void AssignLSFFreqs( 
int	findex[ORDER], 
float	qlsp[ORDER]) 
{ 
int	i; 
 
/* Quantize LSF frequencies using indices passed in */ 
	for(i=0;i