www.pudn.com > p_voice.rar > BWFWFUNC.C


/* 
   ITU-T G.729 Annex C+ - Reference C code for floating point 
                         implementation of G.729 Annex C+ 
                         (integration of Annexes B, D and E) 
                          Version 2.1 of October 1999 
*/ 
/* 
 File : BWFWFUNC.C 
 */ 
 
#include  
#include  
 
#include "typedef.h" 
#include "ld8k.h" 
#include "ld8cp.h" 
#include "tabld8cp.h" 
 
 
/* -------------------------------------------------------------------- */ 
/*                          TST_BWD_DOMINANT                            */ 
/* -------------------------------------------------------------------- */ 
/* Test if backward mode is dominant :                                  */ 
/* Nbre of Backward frames > 4 * Nbre of Forward frames                 */ 
/* It is used for the choice of the perceptual weighting filter         */ 
/* Backward dominant : music or stationnary background noise :          */ 
/*         Quantized filter (30 coef.) + strong weighting               */ 
/* No backward dominant => Non Stationnary signal (mainly speech) :     */ 
/*         Unquantized filter (10 coef.) + normal weighting             */ 
/* -------------------------------------------------------------------- */ 
static int  count_bwd2 = 0, count_fwd2 = 0; 
 
void tst_bwd_dominant( 
int *bwd_dominant, /* O   Dominant backward mode indication */ 
int mode)          /* I   Selected LPC mode */ 
{ 
         
    int tmp, count_all; 
         
    if (mode == 0) count_fwd2++; 
    else count_bwd2++; 
         
    count_all = count_bwd2 + count_fwd2; 
         
    if (count_all == 100) { 
        count_all = count_all >> 1; 
        count_bwd2 = count_bwd2 >> 1; 
        count_fwd2 = count_fwd2 >> 1; 
    } 
         
    *bwd_dominant = 0; 
    if (count_all >= 10) { 
        tmp = count_fwd2 << 2; 
        if (count_bwd2 > tmp) *bwd_dominant = 1; 
    } 
         
    return; 
} 
 
 
 
 
void int_bwd(FLOAT *a_bwd, /* I/O   LPC backward filter */ 
FLOAT *prev_filter, /* I previous frame filter */ 
FLOAT *C_int     /* I/O interpolation coefficient */ 
            )        
{ 
         
    int i; 
    FLOAT tmp1, tmp2; 
    FLOAT *pa_bwd; 
    FLOAT C_int_loc; 
         
    pa_bwd = a_bwd + M_BWDP1; 
         
    /* Calculate the interpolated filters  */ 
    /* ----------------------------------  */ 
    C_int_loc = *C_int - (F)0.1; 
    if( C_int_loc < 0) C_int_loc = 0; 
         
    for (i=0; i= (F)4.) { 
        if(energy > (F)2147483647.) energy = (F)93.1814; 
        else { 
            k = (INT32)energy; 
            Ltmp = -(1L << (n-4)); 
            k &= Ltmp; 
            tmp = (FLOAT)k; 
            energy = (F)10. * (FLOAT)log10(tmp); 
        } 
    } 
    else energy = (F)0.005; 
         
    return(energy); 
} 
/* ----------------------------------------------------------------------- */ 
/*                                                                         */ 
/*                              HYBRID WINDOW                              */ 
/*                              (as in G728)                               */ 
/*                                                                         */ 
/*               1st part (0..35) is sine(i*c) where c = 0.047783          */ 
/*               2nd part (36....) is b*exp((i-35)*log(a))                 */ 
/*               where b=sine(35*c)                                        */ 
/*               and a=0.9928337491 is such as a^^40 = 0.75                */ 
/*               a^^(2*L_FRAME) = 0.75^^4 = 0.31640625                     */ 
/*                                                                         */ 
/* ------------------------------------------------------------------------ */ 
 
/*------------------------------------------------------------------------------*/ 
/* Compute the autocorrelation of speech using hybrid window    (as in G.728)   */ 
/*------------------------------------------------------------------------------*/ 
void autocorr_hyb_window( 
    FLOAT  *x,         /* (in)     synthetized speech signal */ 
    FLOAT  *r_bwd,       /* (out)    Autocorrelations    */ 
    FLOAT *rexp        /* (in/out) */ 
) 
{ 
    FLOAT  tmp; 
    int  i, n, k; 
    FLOAT w_s[L_ANA_BWD]; 
         
    for (n=L_ANA_BWD_M1, k=0; n>=0; n--, k++) w_s[n] = x[n] * hw[k]; 
         
    for (i=0; i<=M_BWD; i++) { 
        tmp = 0; 
        for (n=M_BWD; n