if (snr>5 && (rand()%10==0))
if (snr>9 && (rand()%10==0))
void encode(EncState *st, float *in, FrameBits *bits){   int i, sub, roots;   float error;   /* Copy new data in input buffer */   memmove(st->inBuf, st->inBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(float));   for (i=0;i<st->frameSize;i++)      st->inBuf[st->bufSize-st->frameSize+i] = in[i];   memmove(st->excBuf, st->excBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(float));   memmove(st->swBuf, st->swBuf+st->frameSize, (st->bufSize-st->frameSize)*sizeof(float));   /* Window for analysis */   for (i=0;i<st->windowSize;i++)      st->buf2[i] = st->frame[i] * st->window[i];   /* Compute auto-correlation */   autocorr(st->buf2, st->autocorr, st->lpcSize+1, st->windowSize);   st->autocorr[0] += 1;        /* prevents NANs */   st->autocorr[0] *= st->lpc_floor; /* Noise floor in auto-correlation domain */   /* Lag windowing: equivalent to filtering in the power-spectrum domain */   for (i=0;i<st->lpcSize+1;i++)      st->autocorr[i] *= st->lagWindow[i];   /* Levinson-Durbin */   error = wld(st->lpc+1, st->autocorr, st->rc, st->lpcSize);   st->lpc[0]=1;   /* LPC to LSPs (x-domain) transform */   roots=lpc_to_lsp (st->lpc, st->lpcSize, st->lsp, 6, 0.01, st->stack);   if (roots!=st->lpcSize)   {      fprintf (stderr, "roots!=st->lpcSize (found only %d roots)\n", roots);      exit(1);   }   /* x-domain to angle domain*/   for (i=0;i<st->lpcSize;i++)      st->lsp[i] = acos(st->lsp[i]);      /* LSP Quantization */   st->lsp_quant(st->lsp, st->qlsp, st->lpcSize, bits);   /*for (i=0;i<st->lpcSize;i++)     st->qlsp[i]=st->lsp[i];*/   /*printf ("LSP ");   for (i=0;i<st->lpcSize;i++)      printf ("%f ", st->lsp[i]);   printf ("\n");   printf ("QLSP ");   for (i=0;i<st->lpcSize;i++)      printf ("%f ", st->qlsp[i]);   printf ("\n");   return;*/   /* Special case for first frame */   if (st->first)   {      for (i=0;i<st->lpcSize;i++)         st->old_lsp[i] = st->lsp[i];      for (i=0;i<st->lpcSize;i++)         st->old_qlsp[i] = st->qlsp[i];   }   /* Loop on sub-frames */   for (sub=0;sub<st->nbSubframes;sub++)   {      float esig, enoise, snr, tmp;      int   offset;      float *sp, *sw, *res, *exc, *target, *mem;            /* Offset relative to start of frame */      offset = st->subframeSize*sub;      /* Original signal */      sp=st->frame+offset;      /* Excitation */      exc=st->exc+offset;      /* Weighted signal */      sw=st->sw+offset;      /* Filter response */      res = PUSH(st->stack, st->subframeSize);      /* Target signal */      target = PUSH(st->stack, st->subframeSize);      mem = PUSH(st->stack, st->lpcSize);      /* LSP interpolation (quantized and unquantized) */      tmp = (.5 + sub)/st->nbSubframes;      for (i=0;i<st->lpcSize;i++)         st->interp_lsp[i] = (1-tmp)*st->old_lsp[i] + tmp*st->lsp[i];      for (i=0;i<st->lpcSize;i++)         st->interp_qlsp[i] = (1-tmp)*st->old_qlsp[i] + tmp*st->qlsp[i];      /* Compute interpolated LPCs (quantized and unquantized) */      for (i=0;i<st->lpcSize;i++)         st->interp_lsp[i] = cos(st->interp_lsp[i]);      lsp_to_lpc(st->interp_lsp, st->interp_lpc, st->lpcSize,st->stack);      for (i=0;i<st->lpcSize;i++)         st->interp_qlsp[i] = cos(st->interp_qlsp[i]);      lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, st->stack);      /* Compute bandwidth-expanded (unquantized) LPCs for perceptual weighting */      bw_lpc(st->gamma1, st->interp_lpc, st->bw_lpc1, st->lpcSize);      bw_lpc(st->gamma2, st->interp_lpc, st->bw_lpc2, st->lpcSize);            /* Reset excitation */      for (i=0;i<st->subframeSize;i++)         exc[i]=0;      /* Compute zero response of A(z/g1) / ( A(z/g2) * Aq(z) ) */      for (i=0;i<st->lpcSize;i++)         mem[i]=st->mem_sp[i];      syn_filt_mem(exc, st->interp_qlpc, exc, st->subframeSize, st->lpcSize, mem);      for (i=0;i<st->lpcSize;i++)         mem[i]=st->mem_sp[i];      residue_mem(exc, st->bw_lpc1, res, st->subframeSize, st->lpcSize, mem);      for (i=0;i<st->lpcSize;i++)         mem[i]=st->mem_sw[i];      syn_filt_mem(res, st->bw_lpc2, res, st->subframeSize, st->lpcSize, mem);      /* Compute weighted signal */      for (i=0;i<st->lpcSize;i++)         mem[i]=st->mem_sp[i];      residue_mem(sp, st->bw_lpc1, sw, st->subframeSize, st->lpcSize, mem);      for (i=0;i<st->lpcSize;i++)         mem[i]=st->mem_sw[i];      syn_filt_mem(sw, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, mem);            esig=0;      for (i=0;i<st->subframeSize;i++)         esig+=sw[i]*sw[i];            /* Compute target signal */      for (i=0;i<st->subframeSize;i++)         target[i]=sw[i]-res[i];      for (i=0;i<st->subframeSize;i++)         exc[i]=0;      /* Long-term prediction */      st->ltp_quant(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,                    exc, st->ltp_params, st->min_pitch, st->max_pitch,                     st->lpcSize, st->subframeSize, bits, st->stack);      /* Update target for adaptive codebook contribution */      residue_zero(exc, st->bw_lpc1, res, st->subframeSize, st->lpcSize);      syn_filt_zero(res, st->interp_qlpc, res, st->subframeSize, st->lpcSize);      syn_filt_zero(res, st->bw_lpc2, res, st->subframeSize, st->lpcSize);      for (i=0;i<st->subframeSize;i++)        target[i]-=res[i];      /* Compute noise energy and SNR */      enoise=0;      for (i=0;i<st->subframeSize;i++)         enoise += target[i]*target[i];      snr = 10*log10((esig+1)/(enoise+1));      printf ("pitch SNR = %f\n", snr);#if 0 /*If set to 1, compute "real innovation" i.e. cheat to get perfect reconstruction*/      syn_filt_zero(target, st->bw_lpc1, res, st->subframeSize, st->lpcSize);      residue_zero(res, st->interp_qlpc, st->buf2, st->subframeSize, st->lpcSize);      residue_zero(st->buf2, st->bw_lpc2, st->buf2, st->subframeSize, st->lpcSize);      if (snr>5 && (rand()%10==0))      {         printf ("exc ");         for (i=0;i<st->subframeSize;i++)         {            if (i && i%8==0)               printf ("\nexc ");            printf ("%f ", st->buf2[i]);         }         printf ("\n");      }      for (i=0;i<st->subframeSize;i++)         exc[i]+=st->buf2[i];#else      /* Perform a split-codebook search */      st->innovation_quant(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,                           st->innovation_params, st->lpcSize,                           st->subframeSize, exc, bits, st->stack);#endif      /* Compute weighted noise energy and SNR */      enoise=0;      for (i=0;i<st->subframeSize;i++)         enoise += target[i]*target[i];      snr = 10*log10((esig+1)/(enoise+1));      printf ("seg SNR = %f\n", snr);      /*Keep the previous memory*/      for (i=0;i<st->lpcSize;i++)         mem[i]=st->mem_sp[i];      /* Final signal synthesis from excitation */      syn_filt_mem(exc, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, st->mem_sp);      /* Compute weighted signal again, from synthesized speech (not sure it's the right thing) */      residue_mem(sp, st->bw_lpc1, sw, st->subframeSize, st->lpcSize, mem);      syn_filt_mem(sw, st->bw_lpc2, sw, st->subframeSize, st->lpcSize, st->mem_sw);      POP(st->stack);      POP(st->stack);      POP(st->stack);   }   /* Store the LSPs for interpolation in the next frame */   for (i=0;i<st->lpcSize;i++)      st->old_lsp[i] = st->lsp[i];   for (i=0;i<st->lpcSize;i++)      st->old_qlsp[i] = st->qlsp[i];   /* The next frame will not be the first (Duh!) */   st->first = 0;   /* Replace input by synthesized speech */   for (i=0;i<st->frameSize;i++)     in[i]=st->frame[i];}