📄 cod_ld8e.c
字号:
/* Version 1.1 Last modified: February 1998 */
/* -------------------------------------------------------------------- */
/* Coder_ld8e and Init_Coder_ld8e. */
/* */
/* (C) Original Copyright 1995, AT&T, France Telecom, NTT, */
/* Universite de Sherbrooke. */
/* All rights reserved. */
/* */
/* */
/* Modified to perform higher bit-rate extension of G729 at 11.8 kb/s */
/* Bit rate : 11.8 kb/s */
/* */
/* (C) Copyright 1997 : France Telecom, Universite de Sherbrooke. */
/* All rights reserved. */
/* */
/* -------------------------------------------------------------------- */
/*-----------------------------------------------------------------*
* Functions Coder_ld8e and Init_Coder_ld8e *
* ~~~~~~~~~~ ~~~~~~~~~~~~~~~ *
*-----------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include "typedef.h"
#include "basic_op.h"
#include "ld8k.h"
#include "ld8e.h"
#include "tab_ld8k.h"
#include "oper_32b.h"
static void update_exc_err(Word16 gain_pit, Word16 t0);
static Word16 test_err(Word16 t0, Word16 t0_frac);
/*-----------------------------------------------------------*
* Coder constant parameters (defined in "ld8k.h") *
*-----------------------------------------------------------*
* L_WINDOW : LPC analysis window size. *
* L_NEXT : Samples of next frame needed for autocor. *
* L_FRAME : Frame size. *
* L_SUBFR : Sub-frame size. *
* M : LPC order. *
* MP1 : LPC order+1 *
* L_TOTAL : Total size of speech buffer. *
* PIT_MIN : Minimum pitch lag. *
* PIT_MAX : Maximum pitch lag. *
* L_INTERPOL : Length of filter for interpolation *
*-----------------------------------------------------------*/
/*--------------------------------------------------------*
* Static memory allocation. *
*--------------------------------------------------------*/
/* Speech vector */
static Word16 old_speech[L_TOTAL];
static Word16 *speech, *p_window;
Word16 *new_speech; /* Global variable */
/* Weighted speech vector */
static Word16 old_wsp[L_FRAME+PIT_MAX];
static Word16 *wsp;
/* Excitation vector */
static Word16 old_exc[L_FRAME+PIT_MAX+L_INTERPOL];
static Word16 *exc;
/* Zero vector */
static Word16 ai_zero[L_SUBFR+M_BWDP1];
static Word16 *zero;
/* Lsp (Line spectral pairs) */
static Word16 lsp_old[M]={
30000, 26000, 21000, 15000, 8000, 0, -8000,-15000,-21000,-26000};
static Word16 lsp_old_q[M];
/* Filter's memory */
static Word16 mem_syn[M_BWD], mem_w0[M_BWD], mem_w[M_BWD];
static Word16 mem_err[M_BWD+L_SUBFR], *error;
static Word16 sharp;
/* to tame the coder */
static Word32 L_exc_err[4];
/* for the backward analysis */
static Word16 prev_filter[M_BWDP1]; /* Previous selected filter */
static Word32 rexp[M_BWDP1];
static Word16 synth[L_ANA_BWD];
static Word16 *synth_ptr;
static Word16 prev_mode ;
static Word16 signal[L_FRAME + M_BWD];
static Word16 *signal_ptr;
static Word16 gamma1[2], gamma2[2]; /* Weighting factor for the 2 subframes */
static Word16 A_t_bwd_mem[M_BWDP1];
static Word16 bwd_dominant, C_int; /* See file bwfw.c */
static Word16 glob_stat; /* Mesure of global stationnarity Q8 */
static Word16 stat_bwd; /* Nbre of consecutive backward frames */
static Word16 val_stat_bwd; /* Value associated with stat_bwd */
/* Last backward A(z) for case of unstable filter */
static Word16 old_A_bwd[M_BWDP1];
static Word16 old_rc_bwd[2];
/* Last forkward A(z) for case of unstable filter */
static Word16 old_A_fwd[MP1];
static Word16 old_rc_fwd[2];
static Word16 freq_prev[MA_NP][M]; /* Q13:previous LSP vector */
/*-----------------------------------------------------------------*
* Function Init_Coder_ld8e *
* ~~~~~~~~~~~~~~~ *
* *
* Init_Coder_ld8e(void); *
* *
* ->Initialization of variables for the coder section. *
* - initialize pointers to speech buffer *
* - initialize static pointers *
* - set static vectors to zero *
* *
*-----------------------------------------------------------------*/
void Init_Coder_ld8e(void)
{
int i;
/*----------------------------------------------------------------------*
* Initialize pointers to speech vector. *
* *
* *
* |--------------------|-------------|-------------|------------| *
* previous speech sf1 sf2 L_NEXT *
* *
* <---------------- Total speech vector (L_TOTAL) -----------> *
* <---------------- LPC analysis window (L_WINDOW) -----------> *
* | <-- present frame (L_FRAME) --> *
* old_speech | <-- new speech (L_FRAME) --> *
* p_window | | *
* speech | *
* new_speech *
*-----------------------------------------------------------------------*/
new_speech = old_speech + L_TOTAL - L_FRAME; /* New speech */
speech = new_speech - L_NEXT; /* Present frame */
p_window = old_speech + L_TOTAL - L_WINDOW; /* For LPC window */
/* Initialize static pointers */
wsp = old_wsp + PIT_MAX;
exc = old_exc + PIT_MAX + L_INTERPOL;
zero = ai_zero + M_BWDP1;
error = mem_err + M_BWD;
/* Static vectors to zero */
Set_zero(old_speech, L_TOTAL);
Set_zero(old_exc, PIT_MAX+L_INTERPOL);
Set_zero(old_wsp, PIT_MAX);
Set_zero(mem_syn, M_BWD);
Set_zero(mem_w, M_BWD);
Set_zero(mem_w0, M_BWD);
Set_zero(mem_err, M_BWD);
Set_zero(zero, L_SUBFR);
sharp = SHARPMIN;
/* Initialize lsp_old_q[] */
Copy(lsp_old, lsp_old_q, M);
Lsp_encw_resete(freq_prev);
for(i=0; i<4; i++) L_exc_err[i] = 0x00004000L; /* Q14 */
/* for the backward analysis */
Set_zero(synth, L_ANA_BWD); /*Q14 */
synth_ptr = synth + MEM_SYN_BWD;
prev_mode = 0;
bwd_dominant = 0; /* See file bwfw.c */
C_int = 4506; /* Filter interpolation parameter */
glob_stat = 10000; /* Mesure of global stationnarity Q8 */
stat_bwd = 0; /* Nbre of consecutive backward frames */
val_stat_bwd = 0; /* Value associated with stat_bwd */
Set_zero(signal, M_BWD);
for(i=0; i<M_BWDP1; i++) rexp[i] = 0L;
signal_ptr = &signal[M_BWD];
A_t_bwd_mem[0] = 4096;
for (i=1; i<M_BWDP1; i++) A_t_bwd_mem[i] = 0;
Set_zero(prev_filter, M_BWDP1);
prev_filter[0] = 4096;
Set_zero(old_A_bwd, M_BWDP1);
old_A_bwd[0]=4096;
Set_zero(old_rc_bwd, 2);
Set_zero(old_A_fwd, MP1);
old_A_fwd[0]=4096;
Set_zero(old_rc_fwd, 2);
return;
}
/*-----------------------------------------------------------------*
* Functions Coder_ld8e *
* ~~~~~~~~~~ *
* Coder_ld8e(Word16 ana[], Word16 rate); *
* *
* ->Main coder function. *
* *
* *
* Input: *
* *
* 80 speech data should have been copied to vector new_speech[].*
* This vector is global and is declared in this function. *
* rate : rate for the current frame *
* *
* Ouputs: *
* *
* ana[] ->analysis parameters. *
* *
*-----------------------------------------------------------------*/
void Coder_ld8e(
Word16 ana[], /* output : Analysis parameters */
Word16 rate /* input : rate selector/frame =0 8kbps,= 1 11.8 kbps*/
)
{
/* LPC analysis */
Word16 r_l_fwd[MP1], r_h_fwd[MP1]; /* Autocorrelations low and hi (forward) */
Word32 r_bwd[M_BWDP1]; /* Autocorrelations (backward) */
Word16 r_l_bwd[M_BWDP1]; /* Autocorrelations low (backward) */
Word16 r_h_bwd[M_BWDP1]; /* Autocorrelations high (backward) */
Word16 rc_fwd[M]; /* Reflection coefficients : forward analysis */
Word16 rc_bwd[M_BWD]; /* Reflection coefficients : backward analysis */
Word16 A_t_fwd[MP1*2]; /* A(z) forward unquantized for the 2 subframes */
Word16 A_t_fwd_q[MP1*2]; /* A(z) forward quantized for the 2 subframes */
Word16 A_t_bwd[2*M_BWDP1]; /* A(z) backward for the 2 subframes */
Word16 *Aq; /* A(z) "quantized" for the 2 subframes */
Word16 *Ap; /* A(z) "unquantized" for the 2 subframes */
Word16 *pAp, *pAq;
Word16 Ap1[M_BWDP1]; /* A(z) with spectral expansion */
Word16 Ap2[M_BWDP1]; /* A(z) with spectral expansion */
Word16 lsp_new[M], lsp_new_q[M]; /* LSPs at 2th subframe */
Word16 lsf_int[M]; /* Interpolated LSF 1st subframe. */
Word16 lsf_new[M];
Word16 mode; /* Backward / Forward Indication mode */
Word16 m_ap, m_aq, i_gamma;
Word16 code_lsp[2];
/* Other vectors */
Word16 h1[L_SUBFR]; /* Impulse response h1[] */
Word16 xn[L_SUBFR]; /* Target vector for pitch search */
Word16 xn2[L_SUBFR]; /* Target vector for codebook search */
Word16 code[L_SUBFR]; /* Fixed codebook excitation */
Word16 y1[L_SUBFR]; /* Filtered adaptive excitation */
Word16 y2[L_SUBFR]; /* Filtered fixed codebook excitation */
Word16 g_coeff[4]; /* Correlations between xn & y1 */
Word16 res2[L_SUBFR]; /* residual after long term prediction*/
Word16 g_coeff_cs[5];
Word16 exp_g_coeff_cs[5]; /* Correlations between xn, y1, & y2
<y1,y1>, -2<xn,y1>,
<y2,y2>, -2<xn,y2>, 2<y1,y2> */
/* Scalars */
Word16 i, j, k, i_subfr;
Word16 T_op, T0, T0_min, T0_max, T0_frac;
Word16 gain_pit, gain_code, index;
Word16 temp, pit_sharp;
Word16 sat_filter;
Word32 L_temp;
Word16 freq_cur[M];
/*------------------------------------------------------------------------*
* - Perform LPC analysis: *
* * autocorrelation + lag windowing *
* * Levinson-durbin algorithm to find a[] *
* * convert a[] to lsp[] *
* * quantize and code the LSPs *
* * find the interpolated LSPs and convert to a[] for the 2 *
* subframes (both quantized and unquantized) *
*------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -