?? cod_ld8a.c
字號:
/*
ITU-T G.729A Speech Coder ANSI-C Source Code
Version 1.1 Last modified: September 1996
Copyright (c) 1996,
AT&T, France Telecom, NTT, Universite de Sherbrooke
All rights reserved.
*/
/*-----------------------------------------------------------------*
* Functions Coder_ld8a and Init_Coder_ld8a *
* ~~~~~~~~~~ ~~~~~~~~~~~~~~~ *
* *
* Init_Coder_ld8a(void); *
* *
* ->Initialization of variables for the coder section. *
* *
* *
* Coder_ld8a(Word16 ana[]); *
* *
* ->Main coder function. *
* *
* *
* Input: *
* *
* 80 speech data should have beee copy to vector new_speech[]. *
* This vector is global and is declared in this function. *
* *
* Ouputs: *
* *
* ana[] ->analysis parameters. *
* *
*-----------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include "typedef.h"
#include "basic_op.h"
#include "ld8a.h"
/*-----------------------------------------------------------*
* Coder constant parameters (defined in "ld8a.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;
/* 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_w0[M], mem_w[M], mem_zero[M];
static Word16 sharp;
/*-----------------------------------------------------------------*
* Function Init_Coder_ld8a *
* ~~~~~~~~~~~~~~~ *
* *
* Init_Coder_ld8a(void); *
* *
* ->Initialization of variables for the coder section. *
* - initialize pointers to speech buffer *
* - initialize static pointers *
* - set static vectors to zero *
* *
*-----------------------------------------------------------------*/
void Init_Coder_ld8a(void)
{
/*----------------------------------------------------------------------*
* 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;
/* 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_w, M);
Set_zero(mem_w0, M);
Set_zero(mem_zero, M);
sharp = SHARPMIN;
/* Initialize lsp_old_q[] */
Copy(lsp_old, lsp_old_q, M);
Lsp_encw_reset();
Init_exc_err();
return;
}
/*-----------------------------------------------------------------*
* Functions Coder_ld8a *
* ~~~~~~~~~~ *
* Coder_ld8a(Word16 ana[]); *
* *
* ->Main coder function. *
* *
* *
* Input: *
* *
* 80 speech data should have beee copy to vector new_speech[]. *
* This vector is global and is declared in this function. *
* *
* Ouputs: *
* *
* ana[] ->analysis parameters. *
* *
*-----------------------------------------------------------------*/
void Coder_ld8a(
Word16 ana[] /* output : Analysis parameters */
)
{
/* LPC analysis */
Word16 Aq_t[(MP1)*2]; /* A(z) quantized for the 2 subframes */
Word16 Ap_t[(MP1)*2]; /* A(z/gamma) for the 2 subframes */
Word16 *Aq, *Ap; /* Pointer on Aq_t and Ap_t */
/* 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 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, taming;
Word32 L_temp;
/*------------------------------------------------------------------------*
* - 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) *
*------------------------------------------------------------------------*/
{
/* Temporary vectors */
Word16 r_l[MP1], r_h[MP1]; /* Autocorrelations low and hi */
Word16 rc[M]; /* Reflection coefficients. */
Word16 lsp_new[M], lsp_new_q[M]; /* LSPs at 2th subframe */
/* LP analysis */
Autocorr(p_window, M, r_h, r_l); /* Autocorrelations */
Lag_window(M, r_h, r_l); /* Lag windowing */
Levinson(r_h, r_l, Ap_t, rc); /* Levinson Durbin */
Az_lsp(Ap_t, lsp_new, lsp_old); /* From A(z) to lsp */
/* LSP quantization */
Qua_lsp(lsp_new, lsp_new_q, ana);
ana += 2; /* Advance analysis parameters pointer */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -