static void *gain_create(obs_data_t *settings, obs_source_t *filter)
{
	struct gain_data *gf = bzalloc(sizeof(*gf));
	gf->context = filter;
	gain_update(gf, settings);
	return gf;
}
Beispiel #2
0
void dec_gain_6k(
    int index,             /* input : quantizer index              */
    FLOAT code[],          /* input : fixed code book vector       */
    int l_subfr,           /* input : subframe size                */
    int bfi,               /* input : bad frame indicator good = 0 */
    FLOAT *gain_pit,       /* output: quantized acb gain           */
    FLOAT *gain_code       /* output: quantized fcb gain           */
)
{
    int    index1,index2;
    FLOAT  gcode0, g_code;
    
    /*----------------- Test erasure ---------------*/
    if (bfi != 0)
    {
        *gain_pit *= (F)0.9;
        if(*gain_pit > (F)0.9) *gain_pit=(F)0.9;
        *gain_code *= (F)0.98;
        
        /*----------------------------------------------*
        * update table of past quantized energies      *
        *                              (frame erasure) *
        *----------------------------------------------*/
        gain_update_erasure(past_qua_en);
        return;
    }
    
    /*-------------- Decode pitch gain ---------------*/
    index1 = imap1_6k[index>>NCODE2_B_6K] ;
    index2 = imap2_6k[index & (NCODE2_6K-1)] ;
    *gain_pit = gbk1_6k[index1][0]+gbk2_6k[index2][0] ;
    
    /*-------------- Decode codebook gain ---------------*/
    /*---------------------------------------------------*
    *-  energy due to innovation                       -*
    *-  predicted energy                               -*
    *-  predicted codebook gain => gcode0[exp_gcode0]  -*
    *---------------------------------------------------*/
    gain_predict( past_qua_en, code, l_subfr, &gcode0);
    
    /*-----------------------------------------------------------------*
    * *gain_code = (gbk1_6k[indice1][1]+gbk2_6k[indice2][1]) * gcode0;      *
    *-----------------------------------------------------------------*/
    g_code = gbk1_6k[index1][1]+gbk2_6k[index2][1];
    *gain_code =  g_code * gcode0;
    
    /*----------------------------------------------*
    * update table of past quantized energies      *
    *----------------------------------------------*/
    if(g_code < (F)0.2) g_code = (F)0.2;
    gain_update( past_qua_en, g_code);
    
    return;
}
Beispiel #3
0
/*----------------------------------------------------------------------------
* dec_gain - decode the adaptive and fixed codebook gains
*----------------------------------------------------------------------------
*/
void dec_gaine(
    int index,             /* input : quantizer index              */
    FLOAT code[],          /* input : fixed code book vector       */
    int l_subfr,           /* input : subframe size                */
    int bfi,               /* input : bad frame indicator good = 0 */
    FLOAT *gain_pit,       /* output: quantized acb gain           */
    FLOAT *gain_code,      /* output: quantized fcb gain           */
    int rate,              /* (i)   : number of bits per frame             */
    FLOAT gain_pit_mem,
    FLOAT gain_cod_mem,
    FLOAT  *c_muting,
    int count_bfi,
    int stationnary
)
{

    
    int    index1,index2;
    FLOAT  gcode0, g_code;
    
    /*----------------- Test erasure ---------------*/
    if (bfi != 0)  {
        if(rate == G729E) {
            if (count_bfi < 2) {
                if (stationnary) *gain_pit = (F)1.;
                else *gain_pit = (F)0.95;
                *gain_code = gain_cod_mem;
            }
            else {
                *gain_pit  = gain_pit_mem * (*c_muting);
                *gain_code = gain_cod_mem * (*c_muting);
                if (stationnary) {
                    if (count_bfi > 10) *c_muting *= (F)0.995;
                }
                else *c_muting *= (F)0.98;
                
            }
        }
        else {
            *gain_pit *= (F)0.9;
            if(*gain_pit > (F)0.9) *gain_pit=(F)0.9;
            *gain_code *= (F)0.98;
        }
        
        /*----------------------------------------------*
        * update table of past quantized energies      *
        *                              (frame erasure) *
        *----------------------------------------------*/
        gain_update_erasure(past_qua_en);
        
        return;
    }
    
    /*-------------- Decode pitch gain ---------------*/
    index1 = imap1[index>>NCODE2_B] ;
    index2 = imap2[index & (NCODE2-1)] ;
    *gain_pit = gbk1[index1][0]+gbk2[index2][0] ;
    
    /*-------------- Decode codebook gain ---------------*/
    /*---------------------------------------------------*
    *-  energy due to innovation                       -*
    *-  predicted energy                               -*
    *-  predicted codebook gain => gcode0[exp_gcode0]  -*
    *---------------------------------------------------*/
    gain_predict( past_qua_en, code, l_subfr, &gcode0);

    /*-----------------------------------------------------------------*
    * *gain_code = (gbk1[indice1][1]+gbk2[indice2][1]) * gcode0;      *
    *-----------------------------------------------------------------*/
    g_code = gbk1[index1][1]+gbk2[index2][1];
    *gain_code =  g_code * gcode0;
    
    /*----------------------------------------------*
    * update table of past quantized energies      *
    *----------------------------------------------*/
    gain_update( past_qua_en, g_code);
    
    return;
}
Beispiel #4
0
/*----------------------------------------------------------------------------
 * qua_gain - Quantization of pitch and codebook gains
 *----------------------------------------------------------------------------
 */
int qua_gain(struct gain_state_t * state,
						/* output: quantizer index                   */
  GFLOAT code[],         /* input : fixed codebook vector             */
  GFLOAT *g_coeff,       /* input : correlation factors               */
  int l_subfr,          /* input : fcb vector length                 */
  GFLOAT *gain_pit,      /* output: quantized acb gain                */
  GFLOAT *gain_code,     /* output: quantized fcb gain                */
  int tameflag          /* input : flag set to 1 if taming is needed */
)
{
 /*
 * MA prediction is performed on the innovation energy (in dB with mean      *
 * removed).                                                                 *
 * An initial predicted gain, g_0, is first determined and the correction    *
 * factor     alpha = gain / g_0    is quantized.                            *
 * The pitch gain and the correction factor are vector quantized and the     *
 * mean-squared weighted error criterion is used in the quantizer search.    *
 *   CS Codebook , fast pre-selection version                                *
 */
   int    i,j, index1=0, index2=0;
   int    cand1,cand2 ;
   GFLOAT  gcode0 ;
   GFLOAT  dist, dist_min, g_pitch, g_code;
   GFLOAT  best_gain[2],tmp;

  /*---------------------------------------------------*
   *-  energy due to innovation                       -*
   *-  predicted energy                               -*
   *-  predicted codebook gain => gcode0[exp_gcode0]  -*
   *---------------------------------------------------*/

   gain_predict( state->past_qua_en, code, l_subfr, &gcode0);

   /*-- pre-selection --*/
   tmp = (F)-1./((F)4.*g_coeff[0]*g_coeff[2]-g_coeff[4]*g_coeff[4]) ;
   best_gain[0] = ((F)2.*g_coeff[2]*g_coeff[1]-g_coeff[3]*g_coeff[4])*tmp ;
   best_gain[1] = ((F)2.*g_coeff[0]*g_coeff[3]-g_coeff[1]*g_coeff[4])*tmp ;

   if (tameflag == 1){
     if(best_gain[0]> GPCLIP2) best_gain[0] = GPCLIP2;
   }
  /*----------------------------------------------*
   *   - presearch for gain codebook -            *
   *----------------------------------------------*/

   gbk_presel(best_gain,&cand1,&cand2,gcode0) ;

   /*-- selection --*/
   dist_min = FLT_MAX_G729;
   if(tameflag == 1) {
       for (i=0;i<NCAN1;i++){
          for(j=0;j<NCAN2;j++){
             g_pitch=gbk1[cand1+i][0]+gbk2[cand2+j][0];
             if(g_pitch < GP0999) {
                 g_code=gcode0*(gbk1[cand1+i][1]+gbk2[cand2+j][1]);
                 dist = g_pitch*g_pitch * g_coeff[0]
                       + g_pitch         * g_coeff[1]
                       + g_code*g_code   * g_coeff[2]
                       + g_code          * g_coeff[3]
                       + g_pitch*g_code  * g_coeff[4] ;
                     if (dist < dist_min){
                        dist_min = dist;
                        index1 = cand1+i ;
                        index2 = cand2+j ;
                     }
                }
          }
        }
    }
    else {
       for (i=0;i<NCAN1;i++){
          for(j=0;j<NCAN2;j++){
             g_pitch=gbk1[cand1+i][0]+gbk2[cand2+j][0];
             g_code=gcode0*(gbk1[cand1+i][1]+gbk2[cand2+j][1]);
             dist = g_pitch*g_pitch * g_coeff[0]
                   + g_pitch         * g_coeff[1]
                   + g_code*g_code   * g_coeff[2]
                   + g_code          * g_coeff[3]
                   + g_pitch*g_code  * g_coeff[4] ;
             if (dist < dist_min){
                dist_min = dist;
                index1 = cand1+i ;
                index2 = cand2+j ;
             }
          }
        }
    }
   *gain_pit  = gbk1[index1][0]+gbk2[index2][0] ;
   g_code = gbk1[index1][1]+gbk2[index2][1];
   *gain_code =  g_code * gcode0;
  /*----------------------------------------------*
   * update table of past quantized energies      *
   *----------------------------------------------*/
   gain_update( state->past_qua_en, g_code);

   return (map1[index1]*NCODE2+map2[index2]);
}