www.pudn.com > g729_audio_encode.rar > qua_lsp.c
/*
ITU-T G.729 Speech Coder with Annex B ANSI-C Source Code
Version 1.3 Last modified: August 1997
Copyright (c) 1996,
AT&T, France Telecom, NTT, Universite de Sherbrooke, Lucent Technologies,
Rockwell International
All rights reserved.
*/
/*-------------------------------------------------------------------*
* Function Qua_lsp: *
* ~~~~~~~~ *
*-------------------------------------------------------------------*/
#include "typedef.h"
#include "basic_op.h"
#include "ld8k.h"
#include "tab_ld8k.h"
void Qua_lsp(
Word16 lsp[], /* (i) Q15 : Unquantized LSP */
Word16 lsp_q[], /* (o) Q15 : Quantized LSP */
Word16 ana[] /* (o) : indexes */
)
{
Word16 lsf[M], lsf_q[M]; /* domain 0.0<= lsf normalized : weighting coefficients */
Get_wegt( flsp_in, wegt );
Relspwed( flsp_in, wegt, lspq_out, lspcb1, lspcb2, fg,
freq_prev, fg_sum, fg_sum_inv, code);
}
void Relspwed(
Word16 lsp[], /* (i) Q13 : unquantized LSP parameters */
Word16 wegt[], /* (i) norm: weighting coefficients */
Word16 lspq[], /* (o) Q13 : quantized LSP parameters */
Word16 lspcb1[][M], /* (i) Q13 : first stage LSP codebook */
Word16 lspcb2[][M], /* (i) Q13 : Second stage LSP codebook */
Word16 fg[MODE][MA_NP][M], /* (i) Q15 : MA prediction coefficients */
Word16 freq_prev[MA_NP][M], /* (i) Q13 : previous LSP vector */
Word16 fg_sum[MODE][M], /* (i) Q15 : present MA prediction coef.*/
Word16 fg_sum_inv[MODE][M], /* (i) Q12 : inverse coef. */
Word16 code_ana[] /* (o) : codes of the selected LSP */
)
{
Word16 mode, j;
Word16 index, mode_index;
Word16 cand[MODE], cand_cur;
Word16 tindex1[MODE], tindex2[MODE];
Word32 L_tdist[MODE]; /* Q26 */
Word16 rbuf[M]; /* Q13 */
Word16 buf[M]; /* Q13 */
for(mode = 0; modenorm : M weighting coefficients */
)
{
Word16 i;
Word16 tmp;
Word32 L_acc;
Word16 sft;
Word16 buf[M]; /* in Q13 */
buf[0] = sub( flsp[1], (PI04+8192) ); /* 8192:1.0(Q13) */
for ( i = 1 ; i < M-1 ; i++ ) {
tmp = sub( flsp[i+1], flsp[i-1] );
buf[i] = sub( tmp, 8192 );
}
buf[M-1] = sub( (PI92-8192), flsp[M-2] );
/* */
for ( i = 0 ; i < M ; i++ ) {
if ( buf[i] > 0 ){
wegt[i] = 2048; /* 2048:1.0(Q11) */
}
else {
L_acc = L_mult( buf[i], buf[i] ); /* L_acc in Q27 */
tmp = extract_h( L_shl( L_acc, 2 ) ); /* tmp in Q13 */
L_acc = L_mult( tmp, CONST10 ); /* L_acc in Q25 */
tmp = extract_h( L_shl( L_acc, 2 ) ); /* tmp in Q11 */
wegt[i] = add( tmp, 2048 ); /* wegt in Q11 */
}
}
/* */
L_acc = L_mult( wegt[4], CONST12 ); /* L_acc in Q26 */
wegt[4] = extract_h( L_shl( L_acc, 1 ) ); /* wegt in Q11 */
L_acc = L_mult( wegt[5], CONST12 ); /* L_acc in Q26 */
wegt[5] = extract_h( L_shl( L_acc, 1 ) ); /* wegt in Q11 */
/* wegt: Q11 -> normalized */
tmp = 0;
for ( i = 0; i < M; i++ ) {
if ( sub(wegt[i], tmp) > 0 ) {
tmp = wegt[i];
}
}
sft = norm_s(tmp);
for ( i = 0; i < M; i++ ) {
wegt[i] = shl(wegt[i], sft); /* wegt in Q(11+sft) */
}
return;
}
void Get_freq_prev(Word16 x[MA_NP][M])
{
Word16 i;
for (i=0; i