⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qgain795.c

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 C
📖 第 1 页 / 共 2 页
字号:
             =         t[1]   +              t[2]    +          t[3]        dist = d1 + d2;          d1 = (1.0 - alp) * InnEn * (gcu - gc[i])^2 = t[4]               -------------------    ---          d2 =        alp  * (ResEn - 2.0 * sqrt(ResEn*ExEn) + ExEn);                      ---     -----   ---        -----             =        alp  * (sqrt(ExEn) - sqrt(ResEn))^2                      ---                  -----------             =               (sqrt(aExEn) - sqrt(alp*ResEn))^2                                            ---------------             =               (sqrt(aExEn) -       t[0]     )^2                                                  ----     */    /*     * calculate scalings of the constant terms     */    gain_code = shl (*gain_cod, sub (10, exp_gcode0)); /* Q1  -> Q11 (-ec0) */    g2_pitch = mult (gain_pit, gain_pit);              /* Q14 -> Q13        */    /* 0 < alpha <= 0.5 => 0.5 <= 1-alpha < 1, i.e one_alpha is normalized  */    one_alpha = add (sub (32767, alpha), 1); /* 32768 - alpha */    /*  alpha <= 0.5 -> mult. by 2 to keep precision; compensate in exponent */    tmp = extract_h (L_shl (L_mult (alpha, frac_en[1]), 1));    /* directly store in 32 bit variable because no further mult. required */    L_t1 = L_mult (tmp, g2_pitch);                    move16 ();    exp_coeff[1] = sub (exp_en[1], 15);               move16 ();    tmp = extract_h (L_shl (L_mult (alpha, frac_en[2]), 1));    coeff[2] = mult (tmp, gain_pit);                  move16 ();    exp = sub (exp_gcode0, 10);    exp_coeff[2] = add (exp_en[2], exp);              move16 ();    /* alpha <= 0.5 -> mult. by 2 to keep precision; compensate in exponent */    coeff[3] = extract_h (L_shl (L_mult (alpha, frac_en[3]), 1));    exp = sub (shl (exp_gcode0, 1), 7);    exp_coeff[3] = add (exp_en[3], exp);              move16 ();    coeff[4] = mult (one_alpha, frac_en[3]);          move16 ();    exp_coeff[4] = add (exp_coeff[3], 1);             move16 ();    L_tmp = L_mult (alpha, frac_en[0]);    /* sqrt_l returns normalized value and 2*exponent       -> result = val >> (exp/2)       exp_coeff holds 2*exponent for c[0]            */    /* directly store in 32 bit variable because no further mult. required */    L_t0 = sqrt_l_exp (L_tmp, &exp); /* normalization included in sqrt_l_exp */                                     move32 (); /* function result */    exp = add (exp, 47);    exp_coeff[0] = sub (exp_en[0], exp);              move16 ();    /*     * Determine the maximum exponent occuring in the distance calculation     * and adjust all fractions accordingly (including a safety margin)     *     */    /* find max(e[1..4],e[0]+31) */    e_max = add (exp_coeff[0], 31);    for (i = 1; i <= 4; i++)    {        test ();        if (sub (exp_coeff[i], e_max) > 0)        {            e_max = exp_coeff[i];                     move16 ();        }    }    /* scale c[1]         (requires no further multiplication) */    tmp = sub (e_max, exp_coeff[1]);    L_t1 = L_shr(L_t1, tmp);    /* scale c[2..4] (used in Mpy_32_16 in the quantizer loop) */    for (i = 2; i <= 4; i++)    {        tmp = sub (e_max, exp_coeff[i]);        L_tmp = L_deposit_h(coeff[i]);        L_tmp = L_shr(L_tmp, tmp);        L_Extract(L_tmp, &coeff[i], &coeff_lo[i]);    }    /* scale c[0]         (requires no further multiplication) */    exp = sub (e_max, 31);             /* new exponent */    tmp = sub (exp, exp_coeff[0]);    L_t0 = L_shr (L_t0, shr (tmp, 1));    /* perform correction by 1/sqrt(2) if exponent difference is odd */    test (); logic16 ();    if ((tmp & 0x1) != 0)    {        L_Extract(L_t0, &coeff[0], &coeff_lo[0]);        L_t0 = Mpy_32_16(coeff[0], coeff_lo[0],                         23170);                    /* 23170 Q15 = 1/sqrt(2)*/    }    /* search the quantizer table for the lowest value       of the search criterion                           */    dist_min = MAX_32; move32 ();    index = 0;         move16 ();    p = &qua_gain_code[0]; move16 ();    for (i = 0; i < NB_QUA_CODE; i++)    {        g_code = *p++;        move16 (); /* this is g_fac (Q11)  */        p++;                             /* skip log2(g_fac)     */        p++;                             /* skip 20*log10(g_fac) */        g_code = mult (g_code, gcode0);        /* only continue if    gc[i]            < 2.0*gc           which is equiv. to  g_code (Q10-ec0) < gain_code (Q11-ec0) */        test ();        if (sub (g_code, gain_code) >= 0)            break;        L_tmp = L_mult (g_code, g_code);        L_Extract (L_tmp, &g2_code_h, &g2_code_l);        tmp = sub (g_code, gain_cod_unq);        L_tmp = L_mult (tmp, tmp);        L_Extract (L_tmp, &d2_code_h, &d2_code_l);        /* t2, t3, t4 */        L_tmp = Mac_32_16 (L_t1, coeff[2], coeff_lo[2], g_code);        L_tmp = Mac_32(L_tmp,    coeff[3], coeff_lo[3], g2_code_h, g2_code_l);        L_tmp = sqrt_l_exp (L_tmp, &exp);        L_tmp = L_shr (L_tmp, shr (exp, 1));        /* d2 */        tmp = round (L_sub (L_tmp, L_t0));        L_tmp = L_mult (tmp, tmp);        /* dist */        L_tmp = Mac_32(L_tmp, coeff[4], coeff_lo[4], d2_code_h, d2_code_l);        /* store table index if distance measure for this            index is lower than the minimum seen so far   */        test ();        if (L_sub (L_tmp, dist_min) < (Word32) 0)        {            dist_min = L_tmp;                move16 ();            index = i;                       move16 ();        }    }    /*------------------------------------------------------------------*     *  read quantized gains and new values for MA predictor memories   *     *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   *     *------------------------------------------------------------------*/    /* Read the quantized gains */    p = &qua_gain_code[add (add (index, index), index)]; move16 ();    g_code = *p++;            move16();    *qua_ener_MR122 = *p++;   move16();    *qua_ener = *p;           move16();    /*------------------------------------------------------------------*     *  calculate final fixed codebook gain:                            *     *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                            *     *                                                                  *     *   gc = gc0 * g                                                   *     *------------------------------------------------------------------*/    L_tmp = L_mult(g_code, gcode0);    L_tmp = L_shr(L_tmp, sub(9, exp_gcode0));    *gain_cod = extract_h(L_tmp);    return index;}/**********************************************************************************                         PUBLIC PROGRAM CODE*********************************************************************************//************************************************************************* * * FUNCTION:  MR795_gain_quant * * PURPOSE:   pitch and codebook quantization for MR795 * *************************************************************************/voidMR795_gain_quant(    GainAdaptState *adapt_st, /* i/o: gain adapter state structure       */    Word16 res[],             /* i  : LP residual,                  Q0   */    Word16 exc[],             /* i  : LTP excitation (unfiltered),  Q0   */    Word16 code[],            /* i  : CB innovation (unfiltered),   Q13  */    Word16 frac_coeff[],      /* i  : coefficients (5),             Q15  */    Word16 exp_coeff[],       /* i  : energy coefficients (5),      Q0   */                              /*      coefficients from calc_filt_ener() */    Word16 exp_code_en,       /* i  : innovation energy (exponent), Q0   */    Word16 frac_code_en,      /* i  : innovation energy (fraction), Q15  */    Word16 exp_gcode0,        /* i  : predicted CB gain (exponent), Q0   */    Word16 frac_gcode0,       /* i  : predicted CB gain (fraction), Q15  */    Word16 L_subfr,           /* i  : Subframe length                    */    Word16 cod_gain_frac,     /* i  : opt. codebook gain (fraction),Q15  */    Word16 cod_gain_exp,      /* i  : opt. codebook gain (exponent), Q0  */    Word16 gp_limit,          /* i  : pitch gain limit                   */    Word16 *gain_pit,         /* i/o: Pitch gain,                   Q14  */    Word16 *gain_cod,         /* o  : Code gain,                    Q1   */    Word16 *qua_ener_MR122,   /* o  : quantized energy error,       Q10  */                              /*      (for MR122 MA predictor update)    */    Word16 *qua_ener,         /* o  : quantized energy error,       Q10  */                              /*      (for other MA predictor update)    */    Word16 **anap             /* o  : Index of quantization              */                              /*      (first gain pitch, then code pitch)*/){    Word16 frac_en[4];    Word16 exp_en[4];    Word16 ltpg, alpha, gcode0;    Word16 g_pitch_cand[3];      /* pitch gain candidates   Q14 */    Word16 g_pitch_cind[3];      /* pitch gain indices      Q0  */    Word16 gain_pit_index;    Word16 gain_cod_index;    Word16 exp;    Word16 gain_cod_unq;         /* code gain (unq.) Q(10-exp_gcode0)  */    /* get list of candidate quantized pitch gain values     * and corresponding quantization indices     */    gain_pit_index = q_gain_pitch (MR795, gp_limit, gain_pit,                                   g_pitch_cand, g_pitch_cind);                      move16 (); /* function result */    /*-------------------------------------------------------------------*     *  predicted codebook gain                                          *     *  ~~~~~~~~~~~~~~~~~~~~~~~                                          *     *  gc0     = 2^exp_gcode0 + 2^frac_gcode0                           *     *                                                                   *     *  gcode0 (Q14) = 2^14*2^frac_gcode0 = gc0 * 2^(14-exp_gcode0)      *     *-------------------------------------------------------------------*/    gcode0 = extract_l(Pow2(14, frac_gcode0));          /* Q14 */    /* pre-quantization of codebook gain     * (using three pitch gain candidates);     * result: best guess of pitch gain and code gain     */    MR795_gain_code_quant3(        exp_gcode0, gcode0, g_pitch_cand, g_pitch_cind,        frac_coeff, exp_coeff,        gain_pit, &gain_pit_index, gain_cod, &gain_cod_index,        qua_ener_MR122, qua_ener);    /* calculation of energy coefficients and LTP coding gain */    calc_unfilt_energies(res, exc, code, *gain_pit, L_subfr,                         frac_en, exp_en, &ltpg);    /* run gain adaptor, calculate alpha factor to balance LTP/CB gain     * (this includes the gain adaptor update)     * Note: ltpg = 0 if frac_en[0] == 0, so the update is OK in that case     */    gain_adapt(adapt_st, ltpg, *gain_cod, &alpha);    /* if this is a very low energy signal (threshold: see     * calc_unfilt_energies) or alpha <= 0 then don't run the modified quantizer     */    test (); move16 (); test ();    if (frac_en[0] != 0 && alpha > 0)    {        /* innovation energy <cod cod> was already computed in gc_pred() */        /* (this overwrites the LtpResEn which is no longer needed)      */        frac_en[3] = frac_code_en;          move16 ();        exp_en[3] = exp_code_en;            move16 ();                /* store optimum codebook gain in Q(10-exp_gcode0) */        exp = add (sub (cod_gain_exp, exp_gcode0), 10);        gain_cod_unq = shl (cod_gain_frac, exp);                /* run quantization with modified criterion */        gain_cod_index = MR795_gain_code_quant_mod(            *gain_pit, exp_gcode0, gcode0,            frac_en, exp_en, alpha, gain_cod_unq,            gain_cod, qua_ener_MR122, qua_ener); move16 (); /* function result */    }    *(*anap)++ = gain_pit_index;        move16 ();    *(*anap)++ = gain_cod_index;        move16 ();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -