Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4f67b37 authored by Marco Nelissen's avatar Marco Nelissen Committed by Android (Google) Code Review
Browse files

Merge "Fix yet more overflows in amrwbenc" into nyc-dev

parents d4c4d224 5d453222
Loading
Loading
Loading
Loading
+30 −25
Original line number Diff line number Diff line
@@ -47,48 +47,53 @@ void Convolve (
        s = vo_mult32((*tmpX++), (*tmpH--));i--;
        while(i>0)
        {
            s += vo_mult32((*tmpX++), (*tmpH--));
            s += vo_mult32((*tmpX++), (*tmpH--));
            s += vo_mult32((*tmpX++), (*tmpH--));
            s += vo_mult32((*tmpX++), (*tmpH--));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            i -= 4;
        }
        y[n] = ((s<<1) + 0x8000)>>16;
        y[n] = voround(L_shl(s, 1));
        n++;

        tmpH = h+n;
        tmpX = x;
        i=n+1;
        s =  vo_mult32((*tmpX++), (*tmpH--));i--;
        s += vo_mult32((*tmpX++), (*tmpH--));i--;
        s =  vo_mult32((*tmpX++), (*tmpH--));
        i--;
        s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
        i--;

        while(i>0)
        {
            s += vo_mult32((*tmpX++), (*tmpH--));
            s += vo_mult32((*tmpX++), (*tmpH--));
            s += vo_mult32((*tmpX++), (*tmpH--));
            s += vo_mult32((*tmpX++), (*tmpH--));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            i -= 4;
        }
        y[n] = ((s<<1) + 0x8000)>>16;
        y[n] = voround(L_shl(s, 1));
        n++;

        tmpH = h+n;
        tmpX = x;
        i=n+1;
        s =  vo_mult32((*tmpX++), (*tmpH--));i--;
        s += vo_mult32((*tmpX++), (*tmpH--));i--;
        s += vo_mult32((*tmpX++), (*tmpH--));i--;
        s =  vo_mult32((*tmpX++), (*tmpH--));
        i--;
        s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
        i--;
        s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
        i--;

        while(i>0)
        {
            s += vo_mult32((*tmpX++), (*tmpH--));
            s += vo_mult32((*tmpX++), (*tmpH--));
            s += vo_mult32((*tmpX++), (*tmpH--));
            s += vo_mult32((*tmpX++), (*tmpH--));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            i -= 4;
        }
        y[n] = ((s<<1) + 0x8000)>>16;
        y[n] = voround(L_shl(s, 1));
        n++;

        s = 0;
@@ -97,13 +102,13 @@ void Convolve (
        i=n+1;
        while(i>0)
        {
            s += vo_mult32((*tmpX++), (*tmpH--));
            s += vo_mult32((*tmpX++), (*tmpH--));
            s += vo_mult32((*tmpX++), (*tmpH--));
            s += vo_mult32((*tmpX++), (*tmpH--));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
            i -= 4;
        }
        y[n] = ((s<<1) + 0x8000)>>16;
        y[n] = voround(L_shl(s, 1));
        n++;
    }
    return;
+33 −33
Original line number Diff line number Diff line
@@ -84,8 +84,8 @@ Word16 Pitch_fr4( /* (o) : pitch period.

    /* Find interval to compute normalized correlation */

    t_min = t0_min - L_INTERPOL1;
    t_max = t0_max + L_INTERPOL1;
    t_min = L_sub(t0_min, L_INTERPOL1);
    t_max = L_add(t0_max, L_INTERPOL1);
    corr = &corr_v[-t_min];
    /* Compute normalized correlation between target and filtered excitation */
#ifdef ASM_OPT               /* asm optimization branch */
@@ -188,15 +188,15 @@ static void Norm_Corr(
    L_tmp = 0;
    for (i = 0; i < 64; i+=4)
    {
        L_tmp += (xn[i] * xn[i]);
        L_tmp += (xn[i+1] * xn[i+1]);
        L_tmp += (xn[i+2] * xn[i+2]);
        L_tmp += (xn[i+3] * xn[i+3]);
        L_tmp = L_add(L_tmp, (xn[i] * xn[i]));
        L_tmp = L_add(L_tmp, (xn[i+1] * xn[i+1]));
        L_tmp = L_add(L_tmp, (xn[i+2] * xn[i+2]));
        L_tmp = L_add(L_tmp, (xn[i+3] * xn[i+3]));
    }

    L_tmp = (L_tmp << 1) + 1;
    L_tmp = L_add(L_shl(L_tmp, 1), 1);
    exp = norm_l(L_tmp);
    exp = (32 - exp);
    exp = L_sub(32, exp);
    //exp = exp + 2;                     /* energy of xn[] x 2 + rounded up     */
    scale = -(exp >> 1);           /* (1<<scale) < 1/sqrt(energy rounded) */

@@ -209,36 +209,36 @@ static void Norm_Corr(
        L_tmp1 = 0;
        for (i = 0; i < 64; i+=4)
        {
            L_tmp  += (xn[i] * excf[i]);
            L_tmp1 += (excf[i] * excf[i]);
            L_tmp  += (xn[i+1] * excf[i+1]);
            L_tmp1 += (excf[i+1] * excf[i+1]);
            L_tmp  += (xn[i+2] * excf[i+2]);
            L_tmp1 += (excf[i+2] * excf[i+2]);
            L_tmp  += (xn[i+3] * excf[i+3]);
            L_tmp1 += (excf[i+3] * excf[i+3]);
            L_tmp = L_add(L_tmp, (xn[i] * excf[i]));
            L_tmp1 = L_add(L_tmp1, (excf[i] * excf[i]));
            L_tmp = L_add(L_tmp, (xn[i+1] * excf[i+1]));
            L_tmp1 = L_add(L_tmp1, (excf[i+1] * excf[i+1]));
            L_tmp = L_add(L_tmp, (xn[i+2] * excf[i+2]));
            L_tmp1 = L_add(L_tmp1, (excf[i+2] * excf[i+2]));
            L_tmp = L_add(L_tmp, (xn[i+3] * excf[i+3]));
            L_tmp1 = L_add(L_tmp1, (excf[i+3] * excf[i+3]));
        }

        L_tmp = (L_tmp << 1) + 1;
        L_tmp1 = (L_tmp1 << 1) + 1;
        L_tmp = L_add(L_shl(L_tmp, 1), 1);
        L_tmp1 = L_add(L_shl(L_tmp1, 1), 1);

        exp = norm_l(L_tmp);
        L_tmp = (L_tmp << exp);
        exp_corr = (30 - exp);
        L_tmp = L_shl(L_tmp, exp);
        exp_corr = L_sub(30, exp);
        corr = extract_h(L_tmp);

        exp = norm_l(L_tmp1);
        L_tmp = (L_tmp1 << exp);
        exp_norm = (30 - exp);
        L_tmp = L_shl(L_tmp1, exp);
        exp_norm = L_sub(30, exp);

        Isqrt_n(&L_tmp, &exp_norm);
        norm = extract_h(L_tmp);

        /* Normalize correlation = correlation * (1/sqrt(energy)) */

        L_tmp = vo_L_mult(corr, norm);
        L_tmp = L_mult(corr, norm);

        L_tmp2 = exp_corr + exp_norm + scale;
        L_tmp2 = L_add(exp_corr, exp_norm + scale);
        if(L_tmp2 < 0)
        {
            L_tmp2 = -L_tmp2;
@@ -246,10 +246,10 @@ static void Norm_Corr(
        }
        else
        {
            L_tmp = L_tmp << L_tmp2;
            L_tmp = L_shl(L_tmp, L_tmp2);
        }

        corr_norm[t] = vo_round(L_tmp);
        corr_norm[t] = voround(L_tmp);
        /* modify the filtered excitation excf[] for the next iteration */

        if(t != t_max)
@@ -310,13 +310,13 @@ static Word16 Interpol_4( /* (o) : interpolated value */
    ptr = &(inter4_1[k][0]);

    L_sum  = vo_mult32(x[0], (*ptr++));
    L_sum += vo_mult32(x[1], (*ptr++));
    L_sum += vo_mult32(x[2], (*ptr++));
    L_sum += vo_mult32(x[3], (*ptr++));
    L_sum += vo_mult32(x[4], (*ptr++));
    L_sum += vo_mult32(x[5], (*ptr++));
    L_sum += vo_mult32(x[6], (*ptr++));
    L_sum += vo_mult32(x[7], (*ptr++));
    L_sum = L_add(L_sum, vo_mult32(x[1], (*ptr++)));
    L_sum = L_add(L_sum, vo_mult32(x[2], (*ptr++)));
    L_sum = L_add(L_sum, vo_mult32(x[3], (*ptr++)));
    L_sum = L_add(L_sum, vo_mult32(x[4], (*ptr++)));
    L_sum = L_add(L_sum, vo_mult32(x[5], (*ptr++)));
    L_sum = L_add(L_sum, vo_mult32(x[6], (*ptr++)));
    L_sum = L_add(L_sum, vo_mult32(x[7], (*ptr++)));

    sum = extract_h(L_add(L_shl2(L_sum, 2), 0x8000));
    return (sum);
+7 −7
Original line number Diff line number Diff line
@@ -810,10 +810,10 @@ void coder(
            vo_p2 = vo_p0-1;
            for (j = 1; j <= M/4; j++)
            {
                L_tmp -= *vo_p1++ * *vo_p2--;
                L_tmp -= *vo_p1++ * *vo_p2--;
                L_tmp -= *vo_p1++ * *vo_p2--;
                L_tmp -= *vo_p1++ * *vo_p2--;
                L_tmp = L_sub(L_tmp, *vo_p1++ * *vo_p2--);
                L_tmp = L_sub(L_tmp, *vo_p1++ * *vo_p2--);
                L_tmp = L_sub(L_tmp, *vo_p1++ * *vo_p2--);
                L_tmp = L_sub(L_tmp, *vo_p1++ * *vo_p2--);
            }
            *vo_p3++ = *vo_p0++ = vo_round((L_tmp <<4));
        }
@@ -1205,7 +1205,7 @@ void coder(
         *------------------------------------------------------*/

        /* y2 in Q9, gain_pit in Q14 */
        L_tmp = (gain_code * y2[L_SUBFR - 1])<<1;
        L_tmp = L_mult(gain_code, y2[L_SUBFR - 1]);
        L_tmp = L_shl(L_tmp, (5 + shift));
        L_tmp = L_negate(L_tmp);
        L_tmp += (xn[L_SUBFR - 1] * 16384)<<1;
@@ -1220,8 +1220,8 @@ void coder(
        {
            Word32 tmp;
            /* code in Q9, gain_pit in Q14 */
            L_tmp = (gain_code * code[i])<<1;
            L_tmp = (L_tmp << 5);
            L_tmp = L_mult(gain_code, code[i]);
            L_tmp = L_shl(L_tmp, 5);
            tmp = L_mult(exc[i + i_subfr], gain_pit); // (exc[i + i_subfr] * gain_pit)<<1
            L_tmp = L_add(L_tmp, tmp);
            L_tmp = L_shl2(L_tmp, 1);