Lines Matching refs:st

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