Program: 107586
Project: 107586
Buggy source:
/** 
 * Updates CNG estimate, and applies the CNG when packet was lost.
 * @param psDec Decoder state.
 * @param psDecCtrl Decoder control.
 * @param signal Signal.
 * @param signal_offset offset of the valid data.
 * @param length Length of residual.
 */
static void SKP_Silk_CNG(SKP_Silk_decoder_state psDec,SKP_Silk_decoder_control psDecCtrl,short signal[],int signal_offset,int length){
  int i, subfr;
  int tmp_32, Gain_Q26, max_Gain_Q16;
  short[] LPC_buf=new short[Define.MAX_LPC_ORDER];
  short[] CNG_sig=new short[Define.MAX_FRAME_LENGTH];
  SKP_Silk_CNG_struct psCNG;
  psCNG=psDec.sCNG;
  if (psDec.fs_kHz != psCNG.fs_kHz) {
    SKP_Silk_CNG_Reset(psDec);
    psCNG.fs_kHz=psDec.fs_kHz;
  }
  if (psDec.lossCnt == 0 && psDec.vadFlag == Define.NO_VOICE_ACTIVITY) {
    for (i=0; i < psDec.LPC_order; i++) {
      psCNG.CNG_smth_NLSF_Q15[i]+=Macros.SKP_SMULWB(psDec.prevNLSF_Q15[i] - psCNG.CNG_smth_NLSF_Q15[i],Define.CNG_NLSF_SMTH_Q16);
    }
    max_Gain_Q16=0;
    subfr=0;
    for (i=0; i < Define.NB_SUBFR; i++) {
      if (psDecCtrl.Gains_Q16[i] > max_Gain_Q16) {
        max_Gain_Q16=psDecCtrl.Gains_Q16[i];
        subfr=i;
      }
    }
    System.arraycopy(psCNG.CNG_exc_buf_Q10,0,psCNG.CNG_exc_buf_Q10,psDec.subfr_length,(Define.NB_SUBFR - 1) * psDec.subfr_length);
    System.arraycopy(psDec.exc_Q10,subfr * psDec.subfr_length,psCNG.CNG_exc_buf_Q10,0,psDec.subfr_length);
    for (i=0; i < Define.NB_SUBFR; i++) {
      psCNG.CNG_smth_Gain_Q16+=Macros.SKP_SMULWB(psDecCtrl.Gains_Q16[i] - psCNG.CNG_smth_Gain_Q16,Define.CNG_GAIN_SMTH_Q16);
    }
  }
  if (psDec.lossCnt != 0) {
    int[] psCNG_rand_seed_ptr=new int[1];
    psCNG_rand_seed_ptr[0]=psCNG.rand_seed;
    SKP_Silk_CNG_exc(CNG_sig,0,psCNG.CNG_exc_buf_Q10,0,psCNG.CNG_smth_Gain_Q16,length,psCNG_rand_seed_ptr);
    psCNG.rand_seed=psCNG_rand_seed_ptr[0];
    NLSF2AStable.SKP_Silk_NLSF2A_stable(LPC_buf,psCNG.CNG_smth_NLSF_Q15,psDec.LPC_order);
    Gain_Q26=1 << 26;
    if (psDec.LPC_order == 16) {
      LPCSynthesisOrder16.SKP_Silk_LPC_synthesis_order16(CNG_sig,LPC_buf,Gain_Q26,psCNG.CNG_synth_state,CNG_sig,length);
    }
 else {
      LPCSynthesisFilter.SKP_Silk_LPC_synthesis_filter(CNG_sig,LPC_buf,Gain_Q26,psCNG.CNG_synth_state,CNG_sig,length,psDec.LPC_order);
    }
    for (i=0; i < length; i++) {
      tmp_32=signal[signal_offset + i] + CNG_sig[i];
      signal[signal_offset + i]=(short)SigProcFIX.SKP_SAT16(tmp_32);
    }
  }
 else {
    Arrays.fill(psCNG.CNG_synth_state,0,psDec.LPC_order,0);
  }
}

Fixed version (ground truth):
/** 
 * Updates CNG estimate, and applies the CNG when packet was lost.
 * @param psDec Decoder state.
 * @param psDecCtrl Decoder control.
 * @param signal Signal.
 * @param signal_offset offset of the valid data.
 * @param length Length of residual.
 */
static void SKP_Silk_CNG(SKP_Silk_decoder_state psDec,SKP_Silk_decoder_control psDecCtrl,short signal[],int signal_offset,int length){
  int i, subfr;
  int tmp_32, Gain_Q26, max_Gain_Q16;
  short[] LPC_buf=new short[MAX_LPC_ORDER];
  short[] CNG_sig=new short[MAX_FRAME_LENGTH];
  SKP_Silk_CNG_struct psCNG;
  psCNG=psDec.sCNG;
  if (psDec.fs_kHz != psCNG.fs_kHz) {
    SKP_Silk_CNG_Reset(psDec);
    psCNG.fs_kHz=psDec.fs_kHz;
  }
  if (psDec.lossCnt == 0 && psDec.vadFlag == NO_VOICE_ACTIVITY) {
    for (i=0; i < psDec.LPC_order; i++) {
      psCNG.CNG_smth_NLSF_Q15[i]+=SKP_SMULWB(psDec.prevNLSF_Q15[i] - psCNG.CNG_smth_NLSF_Q15[i],CNG_NLSF_SMTH_Q16);
    }
    max_Gain_Q16=0;
    subfr=0;
    for (i=0; i < NB_SUBFR; i++) {
      if (psDecCtrl.Gains_Q16[i] > max_Gain_Q16) {
        max_Gain_Q16=psDecCtrl.Gains_Q16[i];
        subfr=i;
      }
    }
    System.arraycopy(psCNG.CNG_exc_buf_Q10,0,psCNG.CNG_exc_buf_Q10,psDec.subfr_length,(NB_SUBFR - 1) * psDec.subfr_length);
    System.arraycopy(psDec.exc_Q10,subfr * psDec.subfr_length,psCNG.CNG_exc_buf_Q10,0,psDec.subfr_length);
    for (i=0; i < NB_SUBFR; i++) {
      psCNG.CNG_smth_Gain_Q16+=SKP_SMULWB(psDecCtrl.Gains_Q16[i] - psCNG.CNG_smth_Gain_Q16,CNG_GAIN_SMTH_Q16);
    }
  }
  if (psDec.lossCnt != 0) {
    int[] psCNG_rand_seed_ptr=new int[1];
    psCNG_rand_seed_ptr[0]=psCNG.rand_seed;
    SKP_Silk_CNG_exc(CNG_sig,0,psCNG.CNG_exc_buf_Q10,0,psCNG.CNG_smth_Gain_Q16,length,psCNG_rand_seed_ptr);
    psCNG.rand_seed=psCNG_rand_seed_ptr[0];
    NLSF2AStable.SKP_Silk_NLSF2A_stable(LPC_buf,psCNG.CNG_smth_NLSF_Q15,psDec.LPC_order);
    Gain_Q26=1 << 26;
    if (psDec.LPC_order == 16) {
      LPCSynthesisOrder16.SKP_Silk_LPC_synthesis_order16(CNG_sig,LPC_buf,Gain_Q26,psCNG.CNG_synth_state,CNG_sig,length);
    }
 else {
      LPCSynthesisFilter.SKP_Silk_LPC_synthesis_filter(CNG_sig,LPC_buf,Gain_Q26,psCNG.CNG_synth_state,CNG_sig,length,psDec.LPC_order);
    }
    for (i=0; i < length; i++) {
      tmp_32=signal[signal_offset + i] + CNG_sig[i];
      signal[signal_offset + i]=(short)SigProcFIX.SKP_SAT16(tmp_32);
    }
  }
 else {
    Arrays.fill(psCNG.CNG_synth_state,0,psDec.LPC_order,0);
  }
}