case SPEEX_GET_LOOKAHEAD: speex_encoder_ctl(st->st_low, SPEEX_GET_LOOKAHEAD, ptr); (*(int*)ptr) = 2*(*(int*)ptr) + QMF_ORDER - 1; break;
int sb_encoder_ctl(void *state, int request, void *ptr){   SBEncState *st;   st=(SBEncState*)state;   switch(request)   {   case SPEEX_GET_FRAME_SIZE:      (*(int*)ptr) = st->full_frame_size;      break;   case SPEEX_SET_HIGH_MODE:      st->submodeSelect = st->submodeID = (*(int*)ptr);      break;   case SPEEX_SET_LOW_MODE:      speex_encoder_ctl(st->st_low, SPEEX_SET_LOW_MODE, ptr);      break;   case SPEEX_SET_DTX:      speex_encoder_ctl(st->st_low, SPEEX_SET_DTX, ptr);      break;   case SPEEX_GET_DTX:      speex_encoder_ctl(st->st_low, SPEEX_GET_DTX, ptr);      break;   case SPEEX_GET_LOW_MODE:      speex_encoder_ctl(st->st_low, SPEEX_GET_LOW_MODE, ptr);      break;   case SPEEX_SET_MODE:      speex_encoder_ctl(st, SPEEX_SET_QUALITY, ptr);      break;   case SPEEX_SET_VBR:      st->vbr_enabled = (*(int*)ptr);      speex_encoder_ctl(st->st_low, SPEEX_SET_VBR, ptr);      break;   case SPEEX_GET_VBR:      (*(int*)ptr) = st->vbr_enabled;      break;   case SPEEX_SET_VAD:      st->vad_enabled = (*(int*)ptr);      speex_encoder_ctl(st->st_low, SPEEX_SET_VAD, ptr);      break;   case SPEEX_GET_VAD:      (*(int*)ptr) = st->vad_enabled;      break;   case SPEEX_SET_VBR_QUALITY:      {         int q;         float qual = (*(float*)ptr)+.6;         st->vbr_quality = (*(float*)ptr);         if (qual>10)            qual=10;         q=(int)floor(.5+*(float*)ptr);         if (q>10)            q=10;         speex_encoder_ctl(st->st_low, SPEEX_SET_VBR_QUALITY, &qual);         speex_encoder_ctl(state, SPEEX_SET_QUALITY, &q);         break;      }   case SPEEX_SET_ABR:      st->abr_enabled = (*(int*)ptr);      st->vbr_enabled = 1;      speex_encoder_ctl(st->st_low, SPEEX_SET_VBR, &st->vbr_enabled);      {         int i=10, rate, target;         float vbr_qual;         target = (*(int*)ptr);         while (i>=0)         {            speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i);            speex_encoder_ctl(st, SPEEX_GET_BITRATE, &rate);            if (rate <= target)               break;            i--;         }         vbr_qual=i;         if (vbr_qual<0)            vbr_qual=0;         speex_encoder_ctl(st, SPEEX_SET_VBR_QUALITY, &vbr_qual);         st->abr_count=0;         st->abr_drift=0;         st->abr_drift2=0;      }            break;   case SPEEX_GET_ABR:      (*(int*)ptr) = st->abr_enabled;      break;   case SPEEX_SET_QUALITY:      {         int nb_qual;         int quality = (*(int*)ptr);         if (quality < 0)            quality = 0;         if (quality > 10)            quality = 10;         st->submodeSelect = st->submodeID = ((SpeexSBMode*)(st->mode->mode))->quality_map[quality];         nb_qual = ((SpeexSBMode*)(st->mode->mode))->low_quality_map[quality];         speex_encoder_ctl(st->st_low, SPEEX_SET_MODE, &nb_qual);      }      break;   case SPEEX_SET_COMPLEXITY:      speex_encoder_ctl(st->st_low, SPEEX_SET_COMPLEXITY, ptr);      st->complexity = (*(int*)ptr);      if (st->complexity<1)         st->complexity=1;      break;   case SPEEX_GET_COMPLEXITY:      (*(int*)ptr) = st->complexity;      break;   case SPEEX_SET_BITRATE:      {         int i=10, rate, target;         target = (*(int*)ptr);         while (i>=0)         {            speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i);            speex_encoder_ctl(st, SPEEX_GET_BITRATE, &rate);            if (rate <= target)               break;            i--;         }      }      break;   case SPEEX_GET_BITRATE:      speex_encoder_ctl(st->st_low, request, ptr);      /*fprintf (stderr, "before: %d\n", (*(int*)ptr));*/      if (st->submodes[st->submodeID])         (*(int*)ptr) += st->sampling_rate*SUBMODE(bits_per_frame)/st->full_frame_size;      else         (*(int*)ptr) += st->sampling_rate*(SB_SUBMODE_BITS+1)/st->full_frame_size;      /*fprintf (stderr, "after: %d\n", (*(int*)ptr));*/      break;   case SPEEX_SET_SAMPLING_RATE:      {         int tmp=(*(int*)ptr);         st->sampling_rate = tmp;         tmp>>=1;         speex_encoder_ctl(st->st_low, SPEEX_SET_SAMPLING_RATE, &tmp);      }      break;   case SPEEX_GET_SAMPLING_RATE:      (*(int*)ptr)=st->sampling_rate;      break;   case SPEEX_RESET_STATE:      {         int i;         st->first = 1;         for (i=0;i<st->lpcSize;i++)            st->lsp[i]=(M_PI*((float)(i+1)))/(st->lpcSize+1);         for (i=0;i<st->lpcSize;i++)            st->mem_sw[i]=st->mem_sp[i]=st->mem_sp2[i]=0;         for (i=0;i<st->bufSize;i++)            st->excBuf[i]=0;         for (i=0;i<QMF_ORDER;i++)            st->h0_mem[i]=st->h1_mem[i]=st->g0_mem[i]=st->g1_mem[i]=0;      }      break;   case SPEEX_SET_SUBMODE_ENCODING:      st->encode_submode = (*(int*)ptr);      speex_encoder_ctl(st->st_low, SPEEX_SET_SUBMODE_ENCODING, &ptr);      break;   case SPEEX_GET_SUBMODE_ENCODING:      (*(int*)ptr) = st->encode_submode;      break;   case SPEEX_GET_PI_GAIN:      {         int i;         spx_word32_t *g = (spx_word32_t*)ptr;         for (i=0;i<st->nbSubframes;i++)            g[i]=st->pi_gain[i];      }      break;   case SPEEX_GET_EXC:      {         int i;         spx_sig_t *e = (spx_sig_t*)ptr;         for (i=0;i<st->full_frame_size;i++)            e[i]=0;         for (i=0;i<st->frame_size;i++)            e[2*i]=2*st->exc[i];      }      break;   case SPEEX_GET_INNOV:      {         int i;         spx_sig_t *e = (spx_sig_t*)ptr;         for (i=0;i<st->full_frame_size;i++)            e[i]=0;         for (i=0;i<st->frame_size;i++)            e[2*i]=2*st->exc[i];      }      break;   case SPEEX_GET_RELATIVE_QUALITY:      (*(float*)ptr)=st->relative_quality;      break;   default:      speex_warning_int("Unknown nb_ctl request: ", request);      return -1;   }   return 0;}