Lines Matching refs:st
113 #define SUBMODE(x) st->submodes[st->submodeID]->x
194 SBEncState *st;
197 st = (SBEncState*)speex_alloc(sizeof(SBEncState));
198 if (!st)
200 st->mode = m;
204 st->st_low = speex_encoder_init(mode->nb_mode);
206 st->stack = NULL;
208 /*st->stack = (char*)speex_alloc_scratch(SB_ENC_STACK);*/
209 speex_encoder_ctl(st->st_low, SPEEX_GET_STACK, &st->stack);
212 st->full_frame_size = 2*mode->frameSize;
213 st->frame_size = mode->frameSize;
214 st->subframeSize = mode->subframeSize;
215 st->nbSubframes = mode->frameSize/mode->subframeSize;
216 st->windowSize = st->frame_size+st->subframeSize;
217 st->lpcSize=mode->lpcSize;
219 st->encode_submode = 1;
220 st->submodes=mode->submodes;
221 st->submodeSelect = st->submodeID=mode->defaultSubmode;
224 speex_encoder_ctl(st->st_low, SPEEX_SET_QUALITY, &tmp);
226 speex_encoder_ctl(st->st_low, SPEEX_SET_WIDEBAND, &tmp);
228 st->lpc_floor = mode->lpc_floor;
229 st->gamma1=mode->gamma1;
230 st->gamma2=mode->gamma2;
231 st->first=1;
233 st->high=(spx_word16_t*)speex_alloc((st->windowSize-st->frame_size)*sizeof(spx_word16_t));
235 st->h0_mem=(spx_word16_t*)speex_alloc((QMF_ORDER)*sizeof(spx_word16_t));
236 st->h1_mem=(spx_word16_t*)speex_alloc((QMF_ORDER)*sizeof(spx_word16_t));
238 st->window= lpc_window;
240 st->lagWindow = lag_window;
242 st->old_lsp = (spx_lsp_t*)speex_alloc(st->lpcSize*sizeof(spx_lsp_t));
243 st->old_qlsp = (spx_lsp_t*)speex_alloc(st->lpcSize*sizeof(spx_lsp_t));
244 st->interp_qlpc = (spx_coef_t*)speex_alloc(st->lpcSize*sizeof(spx_coef_t));
245 st->pi_gain = (spx_word32_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word32_t));
246 st->exc_rms = (spx_word16_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word16_t));
247 st->innov_rms_save = NULL;
249 st->mem_sp = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t));
250 st->mem_sp2 = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t));
251 st->mem_sw = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t));
253 for (i=0;i<st->lpcSize;i++)
254 st->old_lsp[i]= DIV32(MULT16_16(QCONST16(3.1415927f, LSP_SHIFT), i+1), st->lpcSize+1);
257 st->vbr_quality = 8;
258 st->vbr_enabled = 0;
259 st->vbr_max = 0;
260 st->vbr_max_high = 20000; /* We just need a big value here */
261 st->vad_enabled = 0;
262 st->abr_enabled = 0;
263 st->relative_quality=0;
266 st->complexity=2;
267 speex_encoder_ctl(st->st_low, SPEEX_GET_SAMPLING_RATE, &st->sampling_rate);
268 st->sampling_rate*=2;
270 VALGRIND_MAKE_READABLE(st, (st->stack-(char*)st));
272 return st;
277 SBEncState *st=(SBEncState*)state;
279 speex_encoder_destroy(st->st_low);
281 /*speex_free_scratch(st->stack);*/
284 speex_free(st->high);
286 speex_free(st->h0_mem);
287 speex_free(st->h1_mem);
289 speex_free(st->old_lsp);
290 speex_free(st->old_qlsp);
291 speex_free(st->interp_qlpc);
292 speex_free(st->pi_gain);
293 speex_free(st->exc_rms);
295 speex_free(st->mem_sp);
296 speex_free(st->mem_sp2);
297 speex_free(st->mem_sw);
300 speex_free(st);
306 SBEncState *st;
331 st = (SBEncState*)state;
332 stack=st->stack;
333 mode = (const SpeexSBMode*)(st->mode->mode);
335 high = in+st->frame_size;
339 qmf_decomp(in, h0, low, high, st->full_frame_size, QMF_ORDER, st->h0_mem, stack);
342 if (st->vbr_enabled || st->vad_enabled)
346 e_low = compute_rms16(low, st->frame_size);
347 e_high = compute_rms16(high, st->frame_size);
351 ALLOC(low_innov_rms, st->nbSubframes, spx_word16_t);
352 speex_encoder_ctl(st->st_low, SPEEX_SET_INNOVATION_SAVE, low_innov_rms);
354 speex_encode_native(st->st_low, low, bits);
356 high = high - (st->windowSize-st->frame_size);
357 SPEEX_COPY(high, st->high, st->windowSize-st->frame_size);
358 SPEEX_COPY(st->high, &high[st->frame_size], st->windowSize-st->frame_size);
361 ALLOC(low_pi_gain, st->nbSubframes, spx_word32_t);
362 ALLOC(low_exc_rms, st->nbSubframes, spx_word16_t);
363 speex_encoder_ctl(st->st_low, SPEEX_GET_PI_GAIN, low_pi_gain);
364 speex_encoder_ctl(st->st_low, SPEEX_GET_EXC, low_exc_rms);
366 speex_encoder_ctl(st->st_low, SPEEX_GET_LOW_MODE, &dtx);
373 ALLOC(lpc, st->lpcSize, spx_coef_t);
374 ALLOC(interp_lpc, st->lpcSize, spx_coef_t);
375 ALLOC(bw_lpc1, st->lpcSize, spx_coef_t);
376 ALLOC(bw_lpc2, st->lpcSize, spx_coef_t);
378 ALLOC(lsp, st->lpcSize, spx_lsp_t);
379 ALLOC(qlsp, st->lpcSize, spx_lsp_t);
380 ALLOC(interp_lsp, st->lpcSize, spx_lsp_t);
381 ALLOC(interp_qlsp, st->lpcSize, spx_lsp_t);
386 ALLOC(autocorr, st->lpcSize+1, spx_word16_t);
387 ALLOC(w_sig, st->windowSize, spx_word16_t);
390 if (st->subframeSize==80)
392 for (i=0;i<st->windowSize;i++)
393 w_sig[i] = EXTRACT16(SHR32(MULT16_16(high[i],st->window[i>>1]),SIG_SHIFT));
395 for (i=0;i<st->windowSize;i++)
396 w_sig[i] = EXTRACT16(SHR32(MULT16_16(high[i],st->window[i]),SIG_SHIFT));
399 _spx_autocorr(w_sig, autocorr, st->lpcSize+1, st->windowSize);
400 autocorr[0] = ADD16(autocorr[0],MULT16_16_Q15(autocorr[0],st->lpc_floor)); /* Noise floor in auto-correlation domain */
403 for (i=0;i<st->lpcSize+1;i++)
404 autocorr[i] = MULT16_16_Q14(autocorr[i],st->lagWindow[i]);
407 _spx_lpc(lpc, autocorr, st->lpcSize);
411 roots=lpc_to_lsp (lpc, st->lpcSize, lsp, 10, LSP_DELTA1, stack);
412 if (roots!=st->lpcSize)
414 roots = lpc_to_lsp (lpc, st->lpcSize, lsp, 10, LSP_DELTA2, stack);
415 if (roots!=st->lpcSize) {
417 for (i=0;i<st->lpcSize;i++)
419 lsp[i]=st->old_lsp[i];
426 if ((st->vbr_enabled || st->vad_enabled) && !dtx)
429 if (st->abr_enabled)
432 if (st->abr_drift2 * st->abr_drift > 0)
435 qual_change = -.00001*st->abr_drift/(1+st->abr_count);
441 st->vbr_quality += qual_change;
442 if (st->vbr_quality>10)
443 st->vbr_quality=10;
444 if (st->vbr_quality<0)
445 st->vbr_quality=0;
451 speex_encoder_ctl(st->st_low, SPEEX_GET_RELATIVE_QUALITY, &st->relative_quality);
457 if (st->vbr_enabled)
461 st->relative_quality+=1.0*(ratio+2);
462 if (st->relative_quality<-1)
463 st->relative_quality=-1;
468 v1=(int)floor(st->vbr_quality);
472 thresh = (st->vbr_quality-v1) * mode->vbr_thresh[modeid][v1+1] +
473 (1+v1-st->vbr_quality) * mode->vbr_thresh[modeid][v1];
474 if (st->relative_quality >= thresh && st->sampling_rate*st->submodes[modeid]->bits_per_frame/st->full_frame_size <= st->vbr_max_high)
479 if (st->abr_enabled)
483 st->abr_drift+=(bitrate-st->abr_enabled);
484 st->abr_drift2 = .95*st->abr_drift2 + .05*(bitrate-st->abr_enabled);
485 st->abr_count += 1.0;
491 if (st->relative_quality<2.0)
494 modeid=st->submodeSelect;
496 st->submodeID=modeid;
503 if (st->encode_submode)
509 speex_bits_pack(bits, st->submodeID, SB_SUBMODE_BITS);
513 if (dtx || st->submodes[st->submodeID] == NULL)
515 for (i=0;i<st->frame_size;i++)
518 for (i=0;i<st->lpcSize;i++)
519 st->mem_sw[i]=0;
520 st->first=1;
523 iir_mem16(high, st->interp_qlpc, high, st->frame_size, st->lpcSize, st->mem_sp, stack);
533 SUBMODE(lsp_quant)(lsp, qlsp, st->lpcSize, bits);
535 if (st->first)
537 for (i=0;i<st->lpcSize;i++)
538 st->old_lsp[i] = lsp[i];
539 for (i=0;i<st->lpcSize;i++)
540 st->old_qlsp[i] = qlsp[i];
543 ALLOC(mem, st->lpcSize, spx_mem_t);
544 ALLOC(syn_resp, st->subframeSize, spx_word16_t);
545 ALLOC(innov, st->subframeSize, spx_sig_t);
546 ALLOC(target, st->subframeSize, spx_word16_t);
548 for (sub=0;sub<st->nbSubframes;sub++)
559 offset = st->subframeSize*sub;
561 ALLOC(exc, st->subframeSize, spx_word16_t);
562 ALLOC(res, st->subframeSize, spx_word16_t);
563 ALLOC(sw, st->subframeSize, spx_word16_t);
566 lsp_interpolate(st->old_lsp, lsp, interp_lsp, st->lpcSize, sub, st->nbSubframes);
567 lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpcSize, sub, st->nbSubframes);
569 lsp_enforce_margin(interp_lsp, st->lpcSize, LSP_MARGIN);
570 lsp_enforce_margin(interp_qlsp, st->lpcSize, LSP_MARGIN);
572 lsp_to_lpc(interp_lsp, interp_lpc, st->lpcSize,stack);
573 lsp_to_lpc(interp_qlsp, st->interp_qlpc, st->lpcSize, stack);
575 bw_lpc(st->gamma1, interp_lpc, bw_lpc1, st->lpcSize);
576 bw_lpc(st->gamma2, interp_lpc, bw_lpc2, st->lpcSize);
580 st->pi_gain[sub]=LPC_SCALING;
582 for (i=0;i<st->lpcSize;i+=2)
584 rh += st->interp_qlpc[i+1] - st->interp_qlpc[i];
585 st->pi_gain[sub] += st->interp_qlpc[i] + st->interp_qlpc[i+1];
596 fir_mem16(sp, st->interp_qlpc, exc, st->subframeSize, st->lpcSize, st->mem_sp2, stack);
599 eh = compute_rms16(exc, st->subframeSize);
614 ALLOC(tmp_sig, st->subframeSize, spx_sig_t);
615 for (i=0;i<st->lpcSize;i++)
616 mem[i]=st->mem_sp[i];
617 iir_mem2(st->low_innov+offset, st->interp_qlpc, tmp_sig, st->subframeSize, st->lpcSize, mem);
618 g2 = compute_rms(sp, st->subframeSize)/(.01+compute_rms(tmp_sig, st->subframeSize));
636 if (st->innov_rms_save)
638 st->innov_rms_save[sub] = eh;
640 st->exc_rms[sub] = eh;
650 if (st->subframeSize==80)
658 if (st->subframeSize==80)
663 compute_impulse_response(st->interp_qlpc, bw_lpc1, bw_lpc2, syn_resp, st->subframeSize, st->lpcSize, stack);
667 for (i=0;i<st->subframeSize;i++)
671 for (i=0;i<st->lpcSize;i++)
672 mem[i]=st->mem_sp[i];
673 iir_mem16(res, st->interp_qlpc, res, st->subframeSize, st->lpcSize, mem, stack);
675 for (i=0;i<st->lpcSize;i++)
676 mem[i]=st->mem_sw[i];
677 filter_mem16(res, bw_lpc1, bw_lpc2, res, st->subframeSize, st->lpcSize, mem, stack);
680 for (i=0;i<st->lpcSize;i++)
681 mem[i]=st->mem_sw[i];
682 filter_mem16(sp, bw_lpc1, bw_lpc2, sw, st->subframeSize, st->lpcSize, mem, stack);
685 for (i=0;i<st->subframeSize;i++)
688 signal_div(target, target, scale, st->subframeSize);
691 SPEEX_MEMSET(innov, 0, st->subframeSize);
693 /*print_vec(target, st->subframeSize, "\ntarget");*/
694 SUBMODE(innovation_quant)(target, st->interp_qlpc, bw_lpc1, bw_lpc2,
695 SUBMODE(innovation_params), st->lpcSize, st->subframeSize,
696 innov, syn_resp, bits, stack, st->complexity, SUBMODE(double_codebook));
697 /*print_vec(target, st->subframeSize, "after");*/
699 signal_mul(innov, innov, scale, st->subframeSize);
704 ALLOC(innov2, st->subframeSize, spx_sig_t);
705 SPEEX_MEMSET(innov2, 0, st->subframeSize);
706 for (i=0;i<st->subframeSize;i++)
709 SUBMODE(innovation_quant)(target, st->interp_qlpc, bw_lpc1, bw_lpc2,
710 SUBMODE(innovation_params), st->lpcSize, st->subframeSize,
711 innov2, syn_resp, bits, stack, st->complexity, 0);
712 signal_mul(innov2, innov2, MULT16_32_P15(QCONST16(0.4f,15),scale), st->subframeSize);
714 for (i=0;i<st->subframeSize;i++)
718 for (i=0;i<st->subframeSize;i++)
721 if (st->innov_rms_save)
723 st->innov_rms_save[sub] = MULT16_16_Q15(QCONST16(.70711f, 15), compute_rms(innov, st->subframeSize));
725 st->exc_rms[sub] = compute_rms16(exc, st->subframeSize);
732 for (i=0;i<st->lpcSize;i++)
733 mem[i]=st->mem_sp[i];
735 iir_mem16(exc, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, st->mem_sp, stack);
738 filter_mem16(sp, bw_lpc1, bw_lpc2, sw, st->subframeSize, st->lpcSize, st->mem_sw, stack);
741 for (i=0;i<st->lpcSize;i++)
742 st->old_lsp[i] = lsp[i];
743 for (i=0;i<st->lpcSize;i++)
744 st->old_qlsp[i] = qlsp[i];
746 st->first=0;
758 SBDecState *st;
760 st = (SBDecState*)speex_alloc(sizeof(SBDecState));
761 if (!st)
763 st->mode = m;
765 st->encode_submode = 1;
767 st->st_low = speex_decoder_init(mode->nb_mode);
769 st->stack = NULL;
771 /*st->stack = (char*)speex_alloc_scratch(SB_DEC_STACK);*/
772 speex_decoder_ctl(st->st_low, SPEEX_GET_STACK, &st->stack);
775 st->full_frame_size = 2*mode->frameSize;
776 st->frame_size = mode->frameSize;
777 st->subframeSize = mode->subframeSize;
778 st->nbSubframes = mode->frameSize/mode->subframeSize;
779 st->lpcSize=mode->lpcSize;
780 speex_decoder_ctl(st->st_low, SPEEX_GET_SAMPLING_RATE, &st->sampling_rate);
781 st->sampling_rate*=2;
783 speex_decoder_ctl(st->st_low, SPEEX_SET_WIDEBAND, &tmp);
785 st->submodes=mode->submodes;
786 st->submodeID=mode->defaultSubmode;
788 st->first=1;
790 st->g0_mem = (spx_word16_t*)speex_alloc((QMF_ORDER)*sizeof(spx_word16_t));
791 st->g1_mem = (spx_word16_t*)speex_alloc((QMF_ORDER)*sizeof(spx_word16_t));
793 st->excBuf = (spx_word16_t*)speex_alloc((st->subframeSize)*sizeof(spx_word16_t));
795 st->old_qlsp = (spx_lsp_t*)speex_alloc((st->lpcSize)*sizeof(spx_lsp_t));
796 st->interp_qlpc = (spx_coef_t*)speex_alloc(st->lpcSize*sizeof(spx_coef_t));
798 st->pi_gain = (spx_word32_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word32_t));
799 st->exc_rms = (spx_word16_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word16_t));
800 st->mem_sp = (spx_mem_t*)speex_alloc((2*st->lpcSize)*sizeof(spx_mem_t));
802 st->innov_save = NULL;
805 st->lpc_enh_enabled=0;
806 st->seed = 1000;
809 VALGRIND_MAKE_READABLE(st, (st->stack-(char*)st));
811 return st;
816 SBDecState *st;
817 st = (SBDecState*)state;
818 speex_decoder_destroy(st->st_low);
820 /*speex_free_scratch(st->stack);*/
823 speex_free(st->g0_mem);
824 speex_free(st->g1_mem);
825 speex_free(st->excBuf);
826 speex_free(st->old_qlsp);
827 speex_free(st->interp_qlpc);
828 speex_free(st->pi_gain);
829 speex_free(st->exc_rms);
830 speex_free(st->mem_sp);
835 static void sb_decode_lost(SBDecState *st, spx_word16_t *out, int dtx, char *stack)
842 saved_modeid=st->submodeID;
843 st->submodeID=1;
845 bw_lpc(QCONST16(0.99f,15), st->interp_qlpc, st->interp_qlpc, st->lpcSize);
848 st->first=1;
854 st->last_ener = MULT16_16_Q15(QCONST16(.9f,15),st->last_ener);
856 for (i=0;i<st->frame_size;i++)
857 out[i+st->frame_size] = speex_rand(st->last_ener, &st->seed);
859 iir_mem16(out+st->frame_size, st->interp_qlpc, out+st->frame_size, st->frame_size, st->lpcSize,
860 st->mem_sp, stack);
864 qmf_synth(out, out+st->frame_size, h0, out, st->full_frame_size, QMF_ORDER, st->g0_mem, st->g1_mem, stack);
867 st->submodeID=saved_modeid;
876 SBDecState *st;
891 st = (SBDecState*)state;
892 stack=st->stack;
893 mode = (const SpeexSBMode*)(st->mode->mode);
895 low_innov_alias = out+st->frame_size;
896 speex_decoder_ctl(st->st_low, SPEEX_SET_INNOVATION_SAVE, low_innov_alias);
898 ret = speex_decode_native(st->st_low, bits, out);
900 speex_decoder_ctl(st->st_low, SPEEX_GET_DTX_STATUS, &dtx);
910 sb_decode_lost(st, out, dtx, stack);
914 if (st->encode_submode)
926 st->submodeID = speex_bits_unpack_unsigned(bits, SB_SUBMODE_BITS);
930 st->submodeID = 0;
932 if (st->submodeID != 0 && st->submodes[st->submodeID] == NULL)
940 if (st->submodes[st->submodeID] == NULL)
944 sb_decode_lost(st, out, 1, stack);
948 for (i=0;i<st->frame_size;i++)
949 out[st->frame_size+i]=VERY_SMALL;
951 st->first=1;
954 iir_mem16(out+st->frame_size, st->interp_qlpc, out+st->frame_size, st->frame_size, st->lpcSize, st->mem_sp, stack);
956 qmf_synth(out, out+st->frame_size, h0, out, st->full_frame_size, QMF_ORDER, st->g0_mem, st->g1_mem, stack);
962 ALLOC(low_pi_gain, st->nbSubframes, spx_word32_t);
963 ALLOC(low_exc_rms, st->nbSubframes, spx_word16_t);
964 speex_decoder_ctl(st->st_low, SPEEX_GET_PI_GAIN, low_pi_gain);
965 speex_decoder_ctl(st->st_low, SPEEX_GET_EXC, low_exc_rms);
967 ALLOC(qlsp, st->lpcSize, spx_lsp_t);
968 ALLOC(interp_qlsp, st->lpcSize, spx_lsp_t);
969 SUBMODE(lsp_unquant)(qlsp, st->lpcSize, bits);
971 if (st->first)
973 for (i=0;i<st->lpcSize;i++)
974 st->old_qlsp[i] = qlsp[i];
977 ALLOC(ak, st->lpcSize, spx_coef_t);
979 for (sub=0;sub<st->nbSubframes;sub++)
989 offset = st->subframeSize*sub;
990 sp=out+st->frame_size+offset;
991 ALLOC(exc, st->subframeSize, spx_word32_t);
993 if (st->innov_save)
995 innov_save = st->innov_save+2*offset;
996 SPEEX_MEMSET(innov_save, 0, 2*st->subframeSize);
1000 lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpcSize, sub, st->nbSubframes);
1002 lsp_enforce_margin(interp_qlsp, st->lpcSize, LSP_MARGIN);
1005 lsp_to_lpc(interp_qlsp, ak, st->lpcSize, stack);
1010 st->pi_gain[sub]=LPC_SCALING;
1012 for (i=0;i<st->lpcSize;i+=2)
1015 st->pi_gain[sub] += ak[i] + ak[i+1];
1025 SPEEX_MEMSET(exc, 0, st->subframeSize);
1036 for (i=0;i<st->subframeSize;i+=2)
1050 if (st->subframeSize==80)
1054 SUBMODE(innovation_unquant)(exc, SUBMODE(innovation_params), st->subframeSize,
1055 bits, stack, &st->seed);
1057 signal_mul(exc,exc,scale,st->subframeSize);
1062 ALLOC(innov2, st->subframeSize, spx_sig_t);
1063 SPEEX_MEMSET(innov2, 0, st->subframeSize);
1064 SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize,
1065 bits, stack, &st->seed);
1066 signal_mul(innov2, innov2, MULT16_32_P15(QCONST16(0.4f,15),scale), st->subframeSize);
1067 for (i=0;i<st->subframeSize;i++)
1074 if (st->innov_save)
1076 for (i=0;i<st->subframeSize;i++)
1080 iir_mem16(st->excBuf, st->interp_qlpc, sp, st->subframeSize, st->lpcSize,
1081 st->mem_sp, stack);
1082 for (i=0;i<st->subframeSize;i++)
1083 st->excBuf[i]=EXTRACT16(PSHR32(exc[i],SIG_SHIFT));
1084 for (i=0;i<st->lpcSize;i++)
1085 st->interp_qlpc[i] = ak[i];
1086 st->exc_rms[sub] = compute_rms16(st->excBuf, st->subframeSize);
1087 exc_ener_sum = ADD32(exc_ener_sum, DIV32(MULT16_16(st->exc_rms[sub],st->exc_rms[sub]), st->nbSubframes));
1089 st->last_ener = spx_sqrt(exc_ener_sum);
1091 qmf_synth(out, out+st->frame_size, h0, out, st->full_frame_size, QMF_ORDER, st->g0_mem, st->g1_mem, stack);
1092 for (i=0;i<st->lpcSize;i++)
1093 st->old_qlsp[i] = qlsp[i];
1095 st->first=0;
1103 SBEncState *st;
1104 st=(SBEncState*)state;
1108 (*(spx_int32_t*)ptr) = st->full_frame_size;
1111 st->submodeSelect = st->submodeID = (*(spx_int32_t*)ptr);
1114 speex_encoder_ctl(st->st_low, SPEEX_SET_LOW_MODE, ptr);
1117 speex_encoder_ctl(st->st_low, SPEEX_SET_DTX, ptr);
1120 speex_encoder_ctl(st->st_low, SPEEX_GET_DTX, ptr);
1123 speex_encoder_ctl(st->st_low, SPEEX_GET_LOW_MODE, ptr);
1126 speex_encoder_ctl(st, SPEEX_SET_QUALITY, ptr);
1130 st->vbr_enabled = (*(spx_int32_t*)ptr);
1131 speex_encoder_ctl(st->st_low, SPEEX_SET_VBR, ptr);
1134 (*(spx_int32_t*)ptr) = st->vbr_enabled;
1137 st->vad_enabled = (*(spx_int32_t*)ptr);
1138 speex_encoder_ctl(st->st_low, SPEEX_SET_VAD, ptr);
1141 (*(spx_int32_t*)ptr) = st->vad_enabled;
1149 st->vbr_quality = (*(float*)ptr);
1155 speex_encoder_ctl(st->st_low, SPEEX_SET_VBR_QUALITY, &qual);
1160 (*(float*)ptr) = st->vbr_quality;
1165 st->abr_enabled = (*(spx_int32_t*)ptr);
1166 st->vbr_enabled = st->abr_enabled!=0;
1167 speex_encoder_ctl(st->st_low, SPEEX_SET_VBR, &st->vbr_enabled);
1168 if (st->vbr_enabled)
1175 speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i);
1176 speex_encoder_ctl(st, SPEEX_GET_BITRATE, &rate);
1184 speex_encoder_ctl(st, SPEEX_SET_VBR_QUALITY, &vbr_qual);
1185 st->abr_count=0;
1186 st->abr_drift=0;
1187 st->abr_drift2=0;
1192 (*(spx_int32_t*)ptr) = st->abr_enabled;
1204 st->submodeSelect = st->submodeID = ((const SpeexSBMode*)(st->mode->mode))->quality_map[quality];
1205 nb_qual = ((const SpeexSBMode*)(st->mode->mode))->low_quality_map[quality];
1206 speex_encoder_ctl(st->st_low, SPEEX_SET_MODE, &nb_qual);
1210 speex_encoder_ctl(st->st_low, SPEEX_SET_COMPLEXITY, ptr);
1211 st->complexity = (*(spx_int32_t*)ptr);
1212 if (st->complexity<1)
1213 st->complexity=1;
1216 (*(spx_int32_t*)ptr) = st->complexity;
1225 speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i);
1226 speex_encoder_ctl(st, SPEEX_GET_BITRATE, &rate);
1234 speex_encoder_ctl(st->st_low, request, ptr);
1236 if (st->submodes[st->submodeID])
1237 (*(spx_int32_t*)ptr) += st->sampling_rate*SUBMODE(bits_per_frame)/st->full_frame_size;
1239 (*(spx_int32_t*)ptr) += st->sampling_rate*(SB_SUBMODE_BITS+1)/st->full_frame_size;
1245 st->sampling_rate = tmp;
1247 speex_encoder_ctl(st->st_low, SPEEX_SET_SAMPLING_RATE, &tmp);
1251 (*(spx_int32_t*)ptr)=st->sampling_rate;
1256 st->first = 1;
1257 for (i=0;i<st->lpcSize;i++)
1258 st->old_lsp[i]= DIV32(MULT16_16(QCONST16(3.1415927f, LSP_SHIFT), i+1), st->lpcSize+1);
1259 for (i=0;i<st->lpcSize;i++)
1260 st->mem_sw[i]=st->mem_sp[i]=st->mem_sp2[i]=0;
1262 st->h0_mem[i]=st->h1_mem[i]=0;
1266 st->encode_submode = (*(spx_int32_t*)ptr);
1267 speex_encoder_ctl(st->st_low, SPEEX_SET_SUBMODE_ENCODING, ptr);
1270 (*(spx_int32_t*)ptr) = st->encode_submode;
1273 speex_encoder_ctl(st->st_low, SPEEX_GET_LOOKAHEAD, ptr);
1277 speex_encoder_ctl(st->st_low, SPEEX_SET_PLC_TUNING, ptr);
1280 speex_encoder_ctl(st->st_low, SPEEX_GET_PLC_TUNING, ptr);
1285 st->vbr_max = (*(spx_int32_t*)ptr);
1288 speex_encoder_ctl(st->st_low, SPEEX_SET_VBR_MAX_BITRATE, &st->vbr_max);
1289 st->vbr_max_high = 17600;
1292 if (st->vbr_max >= 42200)
1294 st->vbr_max_high = 17600;
1295 } else if (st->vbr_max >= 27800)
1297 st->vbr_max_high = 9600;
1298 } else if (st->vbr_max > 20600)
1300 st->vbr_max_high = 5600;
1302 st->vbr_max_high = 1800;
1304 if (st->subframeSize==80)
1305 st->vbr_max_high = 1800;
1306 low_rate = st->vbr_max - st->vbr_max_high;
1307 speex_encoder_ctl(st->st_low, SPEEX_SET_VBR_MAX_BITRATE, &low_rate);
1312 (*(spx_int32_t*)ptr) = st->vbr_max;
1316 speex_encoder_ctl(st->st_low, SPEEX_SET_HIGHPASS, ptr);
1319 speex_encoder_ctl(st->st_low, SPEEX_GET_HIGHPASS, ptr);
1328 for (i=0;i<st->nbSubframes;i++)
1329 g[i]=st->pi_gain[i];
1335 for (i=0;i<st->nbSubframes;i++)
1336 ((spx_word16_t*)ptr)[i] = st->exc_rms[i];
1341 (*(float*)ptr)=st->relative_quality;
1345 st->innov_rms_save = (spx_word16_t*)ptr;
1348 speex_encoder_ctl(st->st_low, SPEEX_SET_WIDEBAND, ptr);
1351 *((char**)ptr) = st->stack;
1362 SBDecState *st;
1363 st=(SBDecState*)state;
1367 st->submodeID = (*(spx_int32_t*)ptr);
1370 speex_decoder_ctl(st->st_low, SPEEX_SET_LOW_MODE, ptr);
1373 speex_decoder_ctl(st->st_low, SPEEX_GET_LOW_MODE, ptr);
1376 (*(spx_int32_t*)ptr) = st->full_frame_size;
1379 speex_decoder_ctl(st->st_low, request, ptr);
1380 st->lpc_enh_enabled = *((spx_int32_t*)ptr);
1383 *((spx_int32_t*)ptr) = st->lpc_enh_enabled;
1394 st->submodeID = ((const SpeexSBMode*)(st->mode->mode))->quality_map[quality];
1395 nb_qual = ((const SpeexSBMode*)(st->mode->mode))->low_quality_map[quality];
1396 speex_decoder_ctl(st->st_low, SPEEX_SET_MODE, &nb_qual);
1400 speex_decoder_ctl(st->st_low, request, ptr);
1401 if (st->submodes[st->submodeID])
1402 (*(spx_int32_t*)ptr) += st->sampling_rate*SUBMODE(bits_per_frame)/st->full_frame_size;
1404 (*(spx_int32_t*)ptr) += st->sampling_rate*(SB_SUBMODE_BITS+1)/st->full_frame_size;
1409 st->sampling_rate = tmp;
1411 speex_decoder_ctl(st->st_low, SPEEX_SET_SAMPLING_RATE, &tmp);
1415 (*(spx_int32_t*)ptr)=st->sampling_rate;
1418 speex_decoder_ctl(st->st_low, SPEEX_SET_HANDLER, ptr);
1421 speex_decoder_ctl(st->st_low, SPEEX_SET_USER_HANDLER, ptr);
1426 for (i=0;i<2*st->lpcSize;i++)
1427 st->mem_sp[i]=0;
1429 st->g0_mem[i]=st->g1_mem[i]=0;
1430 st->last_ener=0;
1434 st->encode_submode = (*(spx_int32_t*)ptr);
1435 speex_decoder_ctl(st->st_low, SPEEX_SET_SUBMODE_ENCODING, ptr);
1438 (*(spx_int32_t*)ptr) = st->encode_submode;
1441 speex_decoder_ctl(st->st_low, SPEEX_GET_LOOKAHEAD, ptr);
1445 speex_decoder_ctl(st->st_low, SPEEX_SET_HIGHPASS, ptr);
1448 speex_decoder_ctl(st->st_low, SPEEX_GET_HIGHPASS, ptr);
1451 speex_decoder_ctl(st->st_low, SPEEX_GET_ACTIVITY, ptr);
1457 for (i=0;i<st->nbSubframes;i++)
1458 g[i]=st->pi_gain[i];
1464 for (i=0;i<st->nbSubframes;i++)
1465 ((spx_word16_t*)ptr)[i] = st->exc_rms[i];
1469 speex_decoder_ctl(st->st_low, SPEEX_GET_DTX_STATUS, ptr);
1472 st->innov_save = (spx_word16_t*)ptr;
1475 speex_decoder_ctl(st->st_low, SPEEX_SET_WIDEBAND, ptr);
1478 *((char**)ptr) = st->stack;