Commit 969fe984 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Converted ivas_post_proc() call stack from ivas_stereo_switching_dec

[x] ivas_post_proc() call stack is converted to fixed point.
[x] The converted function is integrated in synchro_synthesis()
present in ivas_stereo_switching_dec.c. Integration at ivas_core_dec()
and ivas_mct_dec() is yet to be done.
parent e5f64dac
Loading
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -582,6 +582,16 @@ ivas_error ivas_cpe_dec_fx(
    const Word16 nb_bits_metadata, /* i  : number of metadata bits         */
    Word16 *q_output               /* i/o : Q of output synthesis signal         */
);

void ivas_post_proc_fx(
    SCE_DEC_HANDLE hSCE,               /* i/o: SCE decoder structure              */
    CPE_DEC_HANDLE hCPE,               /* i/o: CPE decoder structure              */
    const Word16 n,                    /* i  : channel number                     */
    Word32 synth[],                    /* i/o: output synthesis signal            */
    Word32 *output[CPE_CHANNELS],      /* i/o: output synthesis signal            */
    const Word16 output_frame,         /* i  : output frame length                */
    const Word16 sba_dirac_stereo_flag /* i  : signal stereo output for SBA DirAC */
);
#endif

//ivas_lfe_dec_fx.c
+221 −0
Original line number Diff line number Diff line
@@ -474,6 +474,227 @@ Word16 E_LPC_lev_dur_stab(const Word16 Rh[], const Word16 Rl[], Word16 A[],
    return(flag);
}


Word16 E_LPC_lev_dur_fx(const Word16 Rh[], const Word16 Rl[], Word32 A[],
  Word32 epsP[], const Word16 order
  , Word32 *mem
)
{
  return(E_LPC_lev_dur_stab_fx(Rh, Rl, A, epsP, order, mem, 32750)); /* 0.99945 in Q15 */
}

Word16 E_LPC_lev_dur_stab_fx(const Word16 Rh[], const Word16 Rl[], Word32 A[],
  Word32 epsP[], const Word16 order,
  Word32 *mem, Word16 k_max
)
{
  Word16 i, j, k;
  Word16 hi, lo;
  Word16 Kh, Kl;                 /* reflection coefficient; hi and lo           */
  Word16 alp_h, alp_l, alp_exp;  /* Prediction gain; hi lo and exponent         */
  Word32 t0, t1, t2;             /* temporary variables                         */
  Word16 flag;
  Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1];   /* LPC coef. in double prec. */
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
  Flag Overflow = 0;
#endif


  BASOP_SATURATE_WARNING_OFF_EVS
    if (epsP != NULL)
    {
      epsP[0] = L_Comp(Rh[0], Rl[0]);
      move32();
    }

  flag = 0;
  move16();

  /* K = A[1] = -R[1] / R[0] */
  t1 = L_Comp(Rh[1], Rl[1]);             /* R[1] in Q31      */
  t2 = L_abs(t1);                        /* abs R[1]         */
  t0 = L_deposit_l(0);
  IF(Rh[0] != 0)
  {
    t0 = Div_32_opt(t2, Rh[0], Rl[0]);     /* R[1]/R[0] in Q31 */
    /* Cause a difference in MODE1 due to different implementation of div32*/
  }
  if (t1 > 0)
  {
    t0 = L_negate(t0);                 /* -R[1]/R[0]       */
  }
  Kl = L_Extract_lc(t0, &Kh);            /* K in DPF         */
  t0 = L_shr(t0, 4);                     /* A[1] in Q27      */
  L_Extract(t0, &Ah[1], &Al[1]);         /* A[1] in DPF      */

  /* Alpha = R[0] * (1-K**2) */
  t0 = Sqr_32(Kh, Kl);                   /* K*K      in Q31 */
  t0 = L_abs(t0);                        /* Some case <0 !! */
  t0 = L_sub((Word32)0x7fffffffL, t0);  /* 1 - K*K  in Q31 */
  lo = L_Extract_lc(t0, &hi);            /* DPF format      */
  t0 = Mpy_32(Rh[0], Rl[0], hi, lo);     /* Alpha in Q31    */
  if (epsP != NULL)
  {
    epsP[1] = t0;
    move32();
  }

  /* Normalize Alpha */
  alp_exp = norm_l(t0);
  t0 = L_shl(t0, alp_exp);
  alp_l = L_Extract_lc(t0, &alp_h);
  /* DPF format */

  /*--------------------------------------*
   * ITERATIONS  I=2 to m
   *--------------------------------------*/

  FOR(i = 2; i <= order; i++)
  {
    /* t0 = SUM(R[j]*A[i-j], j=1, i-1) + R[i] */
    t0 = L_deposit_l(0);
    FOR(j = 1; j < i; j++)
    {
      t0 = Mac_32(t0, Rh[j], Rl[j], Ah[i - j], Al[i - j]);
    }

#ifdef BASOP_NOGLOB
    t0 = L_shl_o(t0, 4, &Overflow);                 /* result in Q27 -> convert to Q31 */
#else /* BASOP_NOGLOB */
    t0 = L_shl(t0, 4);                 /* result in Q27 -> convert to Q31 */
#endif /* BASOP_NOGLOB */
        /* No overflow possible            */

        /* Compose and add R[i] in Q3 */
#ifdef BASOP_NOGLOB
    t0 = L_mac_o(t0, Rl[i], 1, &Overflow);
    t0 = L_msu_o(t0, Rh[i], -32768, &Overflow);
#else /* BASOP_NOGLOB */
    t0 = L_mac(t0, Rl[i], 1);
    t0 = L_msu(t0, Rh[i], -32768);
#endif /* BASOP_NOGLOB */

    /* K = -t0 / Alpha */
    t1 = L_abs(t0);
    t2 = L_deposit_l(0);
    IF(alp_h != 0)
    {
      t2 = Div_32_opt(t1, alp_h, alp_l); /* abs(t0)/Alpha                   */
      /* Cause a difference in MODE1 due to different implementation of div32*/
    }

    if (t0 > 0)
    {
      t2 = L_negate(t2);             /* K =-t0/Alpha                    */
    }
#ifdef BASOP_NOGLOB
    t2 = L_shl_o(t2, alp_exp, &Overflow);           /* denormalize; compare to Alpha   */
#else /* BASOP_NOGLOB */
    t2 = L_shl(t2, alp_exp);           /* denormalize; compare to Alpha   */
#endif /* BASOP_NOGLOB */
    test();
    if ((mem != NULL) && ((GT_16(abs_s(extract_h(t2)), k_max))))
    {
      flag = 1;
      move16();/* Test for unstable filter. If unstable keep old A(z) */
    }
    if ((mem != NULL) && ((LT_32(L_abs(t2), 5))))
    {
      flag = 1;
      move16(); /*R matrix not reliable (R saturated for many coeff), keep old A(z) */
    }
    Kl = L_Extract_lc(t2, &Kh);        /* K in DPF                        */

    /*------------------------------------------*
     *  Compute new LPC coeff. -> An[i]
     *  An[j]= A[j] + K*A[i-j]     , j=1 to i-1
     *  An[i]= K
     *------------------------------------------*/

    k = mult_r(i, 16384);
    FOR(j = 1; j < k; j++)
    {
      /* Do two Iterations Together to Allow Direct Update of Ah & Al */
      t0 = Mac_32(L_Comp(Ah[j], Al[j]), Kh, Kl, Ah[i - j], Al[i - j]);
      t1 = Mac_32(L_Comp(Ah[i - j], Al[i - j]), Kh, Kl, Ah[j], Al[j]);
      L_Extract(t0, &Ah[j], &Al[j]);
      L_Extract(t1, &Ah[i - j], &Al[i - j]);
    }
    IF(s_and(i, 1) == 0)
    {
      t0 = Mac_32(L_Comp(Ah[j], Al[j]), Kh, Kl, Ah[i - j], Al[i - j]);
      L_Extract(t0, &Ah[j], &Al[j]);
    }
    t2 = L_shr(t2, 4);                    /* t2 = K in Q31 ->convert to Q27 */
    L_Extract(t2, &Ah[i], &Al[i]);        /* An[i] in Q27                   */

    /* Alpha = Alpha * (1-K**2) */
#ifdef BASOP_NOGLOB
    t1 = L_mult_o(Kh, Kh, &Overflow);                  /* K*K      in Q31 */
#else /* BASOP_NOGLOB */
    t1 = L_mult(Kh, Kh);                  /* K*K      in Q31 */
#endif /* BASOP_NOGLOB */
    t0 = L_mac(t1, mult(Kh, Kl), 2);
    t0 = L_abs(t0);                       /* Some case <0 !! */
    t0 = L_sub((Word32)0x7fffffffL, t0); /* 1 - K*K  in Q31 */
    lo = L_Extract_lc(t0, &hi);           /* DPF format      */
    t0 = Mpy_32(alp_h, alp_l, hi, lo);    /* Alpha in Q31    */


    /* store denormalized alpha in epsP */
    t1 = L_shr(t0, alp_exp);
    if (epsP != NULL)
    {
      epsP[i] = t1;
      move32();
    }

    /* Normalize Alpha */
    j = norm_l(t0);
    t0 = L_shl(t0, j);
    alp_l = L_Extract_lc(t0, &alp_h);/* DPF format */
    alp_exp = add(alp_exp, j);            /* Add normalization to alp_exp */
  }

  /* Adaptive scaling */
  t1 = L_deposit_l(0);
  FOR(i = 1; i <= order; i++)
  {
    t0 = L_Comp(Ah[i], Al[i]);
    t1 = L_max(t1, L_abs(t0));
  }
  k = s_min(norm_l(t1), 3);
  A[0] = L_shl(2048, k + 16);
  move16();
  FOR(i = 1; i <= order; i++)
  {
    t0 = L_Comp(Ah[i], Al[i]);
#ifdef BASOP_NOGLOB
    A[i] = L_shl_o(t0, k, &Overflow);
#else
    A[i] = L_shl(t0, k));
#endif
  }

  BASOP_SATURATE_WARNING_ON_EVS
    IF(mem != NULL)
  {
    /* Enforce stable LPC filter  - parcorr[0] and parcorr[1] are not LPC coeffiecients */
    IF(flag)
    {
      Copy32(mem, A, order + 1);
    }
    ELSE /* If stable LPC filter, store into memories */
    {
        Copy32(A, mem, order + 1);
    }
  }


  return(flag);
}


/*
 * E_LPC_a_add_tilt
 *
+24 −0
Original line number Diff line number Diff line
@@ -961,6 +961,16 @@ Word16 E_LPC_lev_dur(const Word16 Rh[], const Word16 Rl[], Word16 A[],
Word16 E_LPC_lev_dur_stab(const Word16 Rh[], const Word16 Rl[], Word16 A[],
	Word32 epsP[], const Word16 order, Word16 *parcorr, Word16 k_max
);

Word16 E_LPC_lev_dur_fx(const Word16 Rh[], const Word16 Rl[], Word32 A[],
  Word32 epsP[], const Word16 order
  , Word32 *mem
);
Word16 E_LPC_lev_dur_stab_fx(const Word16 Rh[], const Word16 Rl[], Word32 A[],
  Word32 epsP[], const Word16 order,
  Word32 *mem, Word16 k_max
);

void E_LPC_a_add_tilt(const Word16 *a, Word16 *ap, Word16 gamma, Word16 m);
void E_LPC_int_lpc_tcx(const Word16 lsp_old[],    /* i   : LSPs from past frame (1Q14)             */
	const Word16 lsp_new[],    /* i   : LSPs from present frame (1Q14)          */
@@ -2095,6 +2105,10 @@ void Syn_filt_s(
void E_UTIL_synthesis(const Word16 shift, const Word16 a[], const Word16 x[], Word16 y[],
  const Word16 lg, Word16 mem[], const Word16 update, const Word16 m);

void E_UTIL_synthesis_fx(const Word16 shift, const Word32 a[], const Word32 x[], Word32 y[],
  const Word16 lg, Word32 mem[], const Word16 update, const Word16 m
);

void synth_mem_updt2(
  const Word16 L_frame,        /* i  : frame length                            */
  const Word16 last_L_frame,   /* i  : frame length                            */
@@ -4875,6 +4889,16 @@ void tcx_ltp_post(
  Word16* tcx_buf
);

void tcx_ltp_post32(
  Decoder_State* st,
  TCX_LTP_DEC_HANDLE hTcxLtpDec,
  Word16 core,
  Word16 output_frame,
  Word16 delay,
  Word32* sig,
  Word32* tcx_buf
);

//gs_inact_switching_fx.c
void Inac_swtch_ematch_fx(
  Word16 exc2[],               /* i/o: CELP/GSC excitation buffer       Q_exc*/
+132 −0
Original line number Diff line number Diff line
@@ -60,6 +60,50 @@ static Word32 syn_kern_24(Word32 L_tmp, const Word16 a[], const Word16 y[])
    return  syn_kern_8(L_tmp, a+16, y-16);
}


static Word32 syn_kern_2_fx(Word32 L_tmp, const Word32 a[], const Word32 y[])
{
  L_tmp = Msub_32_32_r(L_tmp, y[-1], a[1]);
  return  Msub_32_32_r(L_tmp, y[-2], a[2]);
}

static Word32 syn_kern_4_fx(Word32 L_tmp, const Word32 a[], const Word32 y[])
{
  L_tmp = syn_kern_2_fx(L_tmp, a, y);
  return  syn_kern_2_fx(L_tmp, a + 2, y - 2);
}

static Word32 syn_kern_6_fx(Word32 L_tmp, const Word32 a[], const Word32 y[])
{
  L_tmp = syn_kern_4_fx(L_tmp, a, y);
  return  syn_kern_2_fx(L_tmp, a + 4, y - 4);
}

static Word32 syn_kern_8_fx(Word32 L_tmp, const Word32 a[], const Word32 y[])
{
  L_tmp = syn_kern_4_fx(L_tmp, a, y);
  return  syn_kern_4_fx(L_tmp, a + 4, y - 4);
}

static Word32 syn_kern_10_fx(Word32 L_tmp, const Word32 a[], const Word32 y[])
{
  L_tmp = syn_kern_8_fx(L_tmp, a, y);
  return  syn_kern_2_fx(L_tmp, a + 8, y - 8);
}

Word32 syn_kern_16_fx(Word32 L_tmp, const Word32 a[], const Word32 y[])
{
  L_tmp = syn_kern_8_fx(L_tmp, a, y);
  return  syn_kern_8_fx(L_tmp, a + 8, y - 8);
}

static Word32 syn_kern_24_fx(Word32 L_tmp, const Word32 a[], const Word32 y[])
{
  L_tmp = syn_kern_16_fx(L_tmp, a, y);
  return  syn_kern_8_fx(L_tmp, a + 16, y - 16);
}


/*------------------------------------------------------------------*
 * Syn_filt_s_lc:
 *
@@ -259,6 +303,94 @@ void E_UTIL_synthesis(const Word16 shift, const Word16 a[], const Word16 x[], Wo
}


void E_UTIL_synthesis_fx(const Word16 shift, const Word32 a[], const Word32 x[], Word32 y[],
  const Word16 lg, Word32 mem[], const Word16 update, const Word16 m
)
{
  Word16 i, j;
  Word32 a0;
  Word32 L_tmp;
  Word16 q;
  Word32(*syn_kern)(Word32 L_tmp, const Word32 a[], const Word32 y[]) = NULL;
  Flag Overflow = 0;

  if (EQ_16(m, 6))
  {
    syn_kern = syn_kern_6_fx;
  }
  if (EQ_16(m, 10))
  {
    syn_kern = syn_kern_10_fx;
  }
  if (EQ_16(m, 16))
  {
    syn_kern = syn_kern_16_fx;
  }
  if (EQ_16(m, 24))
  {
    syn_kern = syn_kern_24_fx;
  }
  assert(syn_kern != NULL);
  q = add(norm_l(a[0]), 1);



  /*-----------------------------------------------------------------------*
   * Set Memory Pointer at End for Backward Access
   *-----------------------------------------------------------------------*/
  mem += m;                           /*move32();*/

  a0 = L_shr_o(a[0], shift, &Overflow); /* input / 2^shift */

    /*-----------------------------------------------------------------------*
     * Do the filtering
     *-----------------------------------------------------------------------*/
     /* Filtering Only from Input + Memory */
  L_tmp = syn_kern(Mpy_32_32(a0, *x++), a, mem);
  L_tmp = L_shl_o(L_tmp, q, &Overflow);
  *y++ = L_tmp;

  /* Filtering from Input + Mix of Memory & Output Signal Past */
  FOR(i = 1; i < m; i++)
  {
    L_tmp = Mpy_32_32(a0, *x++);
    /* Process Output Signal Past */
    FOR(j = 1; j <= i; j++)
    {
      L_tmp = Msub_32_32_r(L_tmp, a[j], y[-j]);
    }
    /* Process Memory */
    FOR(; j <= m; j++)
    {
      L_tmp = Msub_32_32_r(L_tmp, a[j], mem[i - j]);
    }
    L_tmp = L_shl_o(L_tmp, q, &Overflow);
    *y++ = L_tmp;
  }

  /* Filtering from Input + Output Signal Past */
  FOR(; i < lg; i++)
  {
    L_tmp = syn_kern(Mpy_32_32(a0, *x++), a, y);
    L_tmp = L_shl_o(L_tmp, q, &Overflow);
    *y++ = L_tmp;
  }

  /*-----------------------------------------------------------------------*
   * Update memory if required
   *-----------------------------------------------------------------------*/
  IF(update != 0)
  {
    FOR(i = 0; i < m; i++)
    {
      *--mem = *--y;
      move32();
    }
  }

  return;
}


/*-------------------------------------------------------------------*
 * synth_mem_updt2()
+1174 −13

File changed.

Preview size limit exceeded, changes collapsed.

Loading