bw_lpc(k1, st->interp_qlpc, awk1, st->lpcSize); bw_lpc(k2, st->interp_qlpc, awk2, st->lpcSize); bw_lpc(k3, st->interp_qlpc, awk3, st->lpcSize);
bw_lpc(GAMMA_SCALING*k1, st->interp_qlpc, awk1, st->lpcSize); bw_lpc(GAMMA_SCALING*k2, st->interp_qlpc, awk2, st->lpcSize); bw_lpc(GAMMA_SCALING*k3, st->interp_qlpc, awk3, st->lpcSize);
int sb_decode(void *state, SpeexBits *bits, short *out){   int i, sub;   SBDecState *st;   int wideband;   int ret;   char *stack;   spx_word32_t *low_pi_gain;   spx_sig_t *low_exc, *low_innov;   spx_coef_t *awk1, *awk2, *awk3;   int dtx;   SpeexSBMode *mode;   st = (SBDecState*)state;   stack=st->stack;   mode = (SpeexSBMode*)(st->mode->mode);   {      short *low;      low = PUSH(stack, st->frame_size, short);            /* Decode the low-band */      ret = speex_decode(st->st_low, bits, low);            for (i=0;i<st->frame_size;i++)         st->x0d[i] = low[i]*SIG_SCALING;   }   speex_decoder_ctl(st->st_low, SPEEX_GET_DTX_STATUS, &dtx);   /* If error decoding the narrowband part, propagate error */   if (ret!=0)   {      return ret;   }   if (!bits)   {      sb_decode_lost(st, out, dtx, stack);      return 0;   }   if (st->encode_submode)   {      /*Check "wideband bit"*/      if (speex_bits_remaining(bits)>0)         wideband = speex_bits_peek(bits);      else         wideband = 0;      if (wideband)      {         /*Regular wideband frame, read the submode*/         wideband = speex_bits_unpack_unsigned(bits, 1);         st->submodeID = speex_bits_unpack_unsigned(bits, SB_SUBMODE_BITS);      } else      {         /*Was a narrowband frame, set "null submode"*/         st->submodeID = 0;      }      if (st->submodeID != 0 && st->submodes[st->submodeID] == NULL)      {         speex_warning("Invalid mode encountered: corrupted stream?");         return -2;      }   }   /* If null mode (no transmission), just set a couple things to zero*/   if (st->submodes[st->submodeID] == NULL)   {      if (dtx)      {         sb_decode_lost(st, out, 1, stack);         return 0;      }      for (i=0;i<st->frame_size;i++)         st->exc[i]=VERY_SMALL;      st->first=1;      /* Final signal synthesis from excitation */      iir_mem2(st->exc, st->interp_qlpc, st->high, st->frame_size, st->lpcSize, st->mem_sp);      fir_mem_up(st->x0d, h0, st->y0, st->full_frame_size, QMF_ORDER, st->g0_mem, stack);      fir_mem_up(st->high, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem, stack);      mix_and_saturate(st->y0, st->y1, out, st->full_frame_size);      return 0;   }   for (i=0;i<st->frame_size;i++)      st->exc[i]=0;   low_pi_gain = PUSH(stack, st->nbSubframes, spx_word32_t);   low_exc = PUSH(stack, st->frame_size, spx_sig_t);   low_innov = PUSH(stack, st->frame_size, spx_sig_t);   speex_decoder_ctl(st->st_low, SPEEX_GET_PI_GAIN, low_pi_gain);   speex_decoder_ctl(st->st_low, SPEEX_GET_EXC, low_exc);   speex_decoder_ctl(st->st_low, SPEEX_GET_INNOV, low_innov);   SUBMODE(lsp_unquant)(st->qlsp, st->lpcSize, bits);      if (st->first)   {      for (i=0;i<st->lpcSize;i++)         st->old_qlsp[i] = st->qlsp[i];   }      awk1=PUSH(stack, st->lpcSize+1, spx_coef_t);   awk2=PUSH(stack, st->lpcSize+1, spx_coef_t);   awk3=PUSH(stack, st->lpcSize+1, spx_coef_t);   for (sub=0;sub<st->nbSubframes;sub++)   {      spx_sig_t *exc, *sp;      spx_word16_t filter_ratio;      spx_word16_t el=0;      int offset;      spx_word32_t rl=0,rh=0;            offset = st->subframeSize*sub;      sp=st->high+offset;      exc=st->exc+offset;            /* LSP interpolation */      lsp_interpolate(st->old_qlsp, st->qlsp, st->interp_qlsp, st->lpcSize, sub, st->nbSubframes);      lsp_enforce_margin(st->interp_qlsp, st->lpcSize, LSP_MARGIN);      /* LSP to LPC */      lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, stack);      if (st->lpc_enh_enabled)      {         float r=.9;                  float k1,k2,k3;         k1=SUBMODE(lpc_enh_k1);         k2=SUBMODE(lpc_enh_k2);         k3=(1-(1-r*k1)/(1-r*k2))/r;         k3=k1-k2;         if (!st->lpc_enh_enabled)         {            k1=k2;            k3=0;         }         bw_lpc(k1, st->interp_qlpc, awk1, st->lpcSize);         bw_lpc(k2, st->interp_qlpc, awk2, st->lpcSize);         bw_lpc(k3, st->interp_qlpc, awk3, st->lpcSize);         /*fprintf (stderr, "%f %f %f\n", k1, k2, k3);*/      }      /* Calculate reponse ratio between the low and high filter in the middle         of the band (4000 Hz) */               st->pi_gain[sub]=LPC_SCALING;         rh = LPC_SCALING;         for (i=1;i<=st->lpcSize;i+=2)         {            rh += st->interp_qlpc[i+1] - st->interp_qlpc[i];            st->pi_gain[sub] += st->interp_qlpc[i] + st->interp_qlpc[i+1];         }         rl = low_pi_gain[sub];#ifdef FIXED_POINT         filter_ratio=DIV32_16(SHL(rl+82,2),SHR(82+rh,5));#else         filter_ratio=(rl+.01)/(rh+.01);#endif            for (i=0;i<st->subframeSize;i++)         exc[i]=0;      if (!SUBMODE(innovation_unquant))      {         float g;         int quant;         quant = speex_bits_unpack_unsigned(bits, 5);         g= exp(((float)quant-10)/8.0);         #ifdef FIXED_POINT         g /= filter_ratio/128.;#else         g /= filter_ratio;#endif         /* High-band excitation using the low-band excitation and a gain */         for (i=0;i<st->subframeSize;i++)            exc[i]=mode->folding_gain*g*low_innov[offset+i];         /*speex_rand_vec(mode->folding_gain*g*sqrt(el/st->subframeSize), exc, st->subframeSize);*/      } else {         spx_word16_t gc;         spx_word32_t scale;         int qgc = speex_bits_unpack_unsigned(bits, 4);         el = compute_rms(low_exc+offset, st->subframeSize);#ifdef FIXED_POINT         gc = MULT16_32_Q15(28626,gc_quant_bound[qgc]);#else         gc = exp((1/3.7)*qgc-0.15556);#endif         if (st->subframeSize==80)            gc *= 1.4142;         scale = SHL(MULT16_16(DIV32_16(SHL(gc,SIG_SHIFT-4),filter_ratio),(1+el)),4);         SUBMODE(innovation_unquant)(exc, SUBMODE(innovation_params), st->subframeSize,                                 bits, stack);         signal_mul(exc,exc,scale,st->subframeSize);         if (SUBMODE(double_codebook)) {            char *tmp_stack=stack;            spx_sig_t *innov2 = PUSH(tmp_stack, st->subframeSize, spx_sig_t);            for (i=0;i<st->subframeSize;i++)               innov2[i]=0;            SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize,                                 bits, tmp_stack);            for (i=0;i<st->subframeSize;i++)               innov2[i]*=scale/(float)SIG_SCALING*(1/2.5);            for (i=0;i<st->subframeSize;i++)               exc[i] += innov2[i];         }      }      for (i=0;i<st->subframeSize;i++)         sp[i]=exc[i];      if (st->lpc_enh_enabled)      {         /* Use enhanced LPC filter */         filter_mem2(sp, awk2, awk1, sp, st->subframeSize, st->lpcSize,                      st->mem_sp+st->lpcSize);         filter_mem2(sp, awk3, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,                      st->mem_sp);      } else {         /* Use regular filter */         for (i=0;i<st->lpcSize;i++)            st->mem_sp[st->lpcSize+i] = 0;         iir_mem2(sp, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,                      st->mem_sp);      }      /*iir_mem2(exc, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, st->mem_sp);*/   }   fir_mem_up(st->x0d, h0, st->y0, st->full_frame_size, QMF_ORDER, st->g0_mem, stack);   fir_mem_up(st->high, h1, st->y1, st->full_frame_size, QMF_ORDER, st->g1_mem, stack);   mix_and_saturate(st->y0, st->y1, out, st->full_frame_size);   for (i=0;i<st->lpcSize;i++)      st->old_qlsp[i] = st->qlsp[i];   st->first=0;   return 0;}